Qt: IO Graph correct color selection
The correct method of selection of colors is just using the QColorDialog not a specialized object. Implementing it just that way, to correct bug on Linux Bug: 15399 Change-Id: I3c4785d352888ec34c34534667c3f7df182f9fd7 Reviewed-on: https://code.wireshark.org/review/31465 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
179cb6dfa1
commit
5b7ea06e0a
|
@ -22,7 +22,6 @@ set(WIRESHARK_WIDGET_HEADERS
|
|||
widgets/dissector_tables_view.h
|
||||
widgets/drag_drop_toolbar.h
|
||||
widgets/drag_label.h
|
||||
widgets/editor_color_dialog.h
|
||||
widgets/editor_file_dialog.h
|
||||
widgets/expert_info_view.h
|
||||
widgets/export_objects_view.h
|
||||
|
@ -245,7 +244,6 @@ set(WIRESHARK_WIDGET_SRCS
|
|||
widgets/dissector_tables_view.cpp
|
||||
widgets/drag_drop_toolbar.cpp
|
||||
widgets/drag_label.cpp
|
||||
widgets/editor_color_dialog.cpp
|
||||
widgets/editor_file_dialog.cpp
|
||||
widgets/elided_label.cpp
|
||||
widgets/expert_info_view.cpp
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <ui/qt/widgets/display_filter_edit.h>
|
||||
#include <ui/qt/widgets/field_filter_edit.h>
|
||||
#include <ui/qt/widgets/editor_file_dialog.h>
|
||||
#include <ui/qt/widgets/editor_color_dialog.h>
|
||||
|
||||
// The Qt docs suggest overriding updateEditorGeometry, but the
|
||||
// defaults seem sane.
|
||||
|
@ -74,11 +73,8 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &
|
|||
case PT_TXTMOD_COLOR:
|
||||
if (index.isValid()) {
|
||||
QColor color(index.model()->data(index, Qt::DecorationRole).toString());
|
||||
EditorColorDialog *colorDialog = new EditorColorDialog(index, color, parent);
|
||||
|
||||
//Use signals to accept data from cell
|
||||
connect(colorDialog, &EditorColorDialog::acceptEdit, this, &UatDelegate::applyColor);
|
||||
return colorDialog;
|
||||
QColorDialog * dialog = new QColorDialog(color, parent);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
//shouldn't happen
|
||||
|
@ -152,6 +148,15 @@ void UatDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|||
|
||||
break;
|
||||
}
|
||||
case PT_TXTMOD_COLOR:
|
||||
{
|
||||
if ( qobject_cast<QColorDialog *>(editor) )
|
||||
{
|
||||
QColor color(index.model()->data(index, Qt::DecorationRole).toString());
|
||||
qobject_cast<QColorDialog *>(editor)->setCurrentColor(color);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
|
@ -173,6 +178,11 @@ void UatDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|||
}
|
||||
case PT_TXTMOD_COLOR:
|
||||
//do nothing, dialog signals will update table
|
||||
if ( qobject_cast<QColorDialog *>(editor) )
|
||||
{
|
||||
QColor newColor = qobject_cast<QColorDialog *>(editor)->currentColor();
|
||||
((QAbstractItemModel *)index.model())->setData(index, newColor.name(), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -188,16 +198,6 @@ void UatDelegate::applyFilename(const QModelIndex& index)
|
|||
}
|
||||
}
|
||||
|
||||
void UatDelegate::applyColor(const QModelIndex& index)
|
||||
{
|
||||
if (index.isValid()) {
|
||||
EditorColorDialog *colorDialog = static_cast<EditorColorDialog*>(sender());
|
||||
QColor newColor = colorDialog->currentColor();
|
||||
((QAbstractItemModel *)index.model())->setData(index, newColor.name(), Qt::EditRole);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* * Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
|
|
|
@ -35,7 +35,6 @@ public:
|
|||
|
||||
private slots:
|
||||
void applyFilename(const QModelIndex& index);
|
||||
void applyColor(const QModelIndex& index);
|
||||
|
||||
private:
|
||||
uat_field_t *indexToField(const QModelIndex &index) const;
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
/* editor_color_dialog.cpp
|
||||
*
|
||||
* Color dialog that can be used as an "inline editor" in a table
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <ui/qt/widgets/editor_color_dialog.h>
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QStyle>
|
||||
|
||||
EditorColorDialog::EditorColorDialog(const QModelIndex& index, const QColor& initial, QWidget* parent)
|
||||
: QLineEdit(parent)
|
||||
, color_button_(new QPushButton(this))
|
||||
, index_(index)
|
||||
, current_(initial)
|
||||
{
|
||||
connect(color_button_, &QPushButton::clicked, this, &EditorColorDialog::applyColor);
|
||||
}
|
||||
|
||||
// QAbstractItemView installs QAbstractItemDelegate's event filter after
|
||||
// we've been created. We need to install our own event filter after that
|
||||
// happens so that we can steal tab keypresses.
|
||||
void EditorColorDialog::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
installEventFilter(this);
|
||||
QLineEdit::focusInEvent(event);
|
||||
}
|
||||
|
||||
void EditorColorDialog::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
removeEventFilter(this);
|
||||
QLineEdit::focusOutEvent(event);
|
||||
}
|
||||
|
||||
bool EditorColorDialog::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent* key = static_cast<QKeyEvent*>(event);
|
||||
if ( (key->key() == Qt::Key_Tab) && !color_button_->hasFocus()) {
|
||||
color_button_->setFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QLineEdit::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void EditorColorDialog::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
// Move the button to the end of the line edit and set its height.
|
||||
QSize sz = color_button_->sizeHint();
|
||||
int frame_width = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||
color_button_->move(rect().right() - frame_width - sz.width(),
|
||||
contentsRect().top());
|
||||
color_button_->setMinimumHeight(contentsRect().height());
|
||||
color_button_->setMaximumHeight(contentsRect().height());
|
||||
}
|
||||
|
||||
void EditorColorDialog::applyColor()
|
||||
{
|
||||
QColorDialog color_dlg;
|
||||
|
||||
color_dlg.setCurrentColor(current_);
|
||||
if (color_dlg.exec() == QDialog::Accepted) {
|
||||
current_ = color_dlg.currentColor();
|
||||
emit acceptEdit(index_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
|
@ -1,57 +0,0 @@
|
|||
/* editor_color_dialog.h
|
||||
*
|
||||
* Color dialog that can be used as an "inline editor" in a table
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef EDITOR_COLOR_DIALOG_H_
|
||||
#define EDITOR_COLOR_DIALOG_H_
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QModelIndex>
|
||||
|
||||
class EditorColorDialog : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EditorColorDialog(const QModelIndex& index, const QColor& initial, QWidget* parent = 0);
|
||||
|
||||
QColor currentColor() { return current_; }
|
||||
virtual void focusInEvent(QFocusEvent *event);
|
||||
virtual void focusOutEvent(QFocusEvent *event);
|
||||
virtual bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
signals:
|
||||
void acceptEdit(const QModelIndex& index);
|
||||
|
||||
private slots:
|
||||
void applyColor();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
QPushButton* color_button_;
|
||||
const QModelIndex index_; //saved index of table cell
|
||||
QColor current_; //initial color in edit
|
||||
};
|
||||
|
||||
#endif /* EDITOR_COLOR_DIALOG_H_ */
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
Loading…
Reference in New Issue