diff options
author | Roland Knall <rknall@gmail.com> | 2019-01-09 14:57:17 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2019-01-16 18:40:10 +0000 |
commit | 5b7ea06e0a79c8adfbc94357d4c9627a71612169 (patch) | |
tree | 72128aadf2079853e49cb3aeb8822666baa1389d | |
parent | 179cb6dfa14441d14c48f4b19baa02fda2160a2d (diff) |
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>
-rw-r--r-- | ui/qt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | ui/qt/models/uat_delegate.cpp | 32 | ||||
-rw-r--r-- | ui/qt/models/uat_delegate.h | 1 | ||||
-rw-r--r-- | ui/qt/widgets/editor_color_dialog.cpp | 88 | ||||
-rw-r--r-- | ui/qt/widgets/editor_color_dialog.h | 57 |
5 files changed, 16 insertions, 164 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 5c8106ea0f..bdbd099d56 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -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 diff --git a/ui/qt/models/uat_delegate.cpp b/ui/qt/models/uat_delegate.cpp index b218edb672..d992d9235d 100644 --- a/ui/qt/models/uat_delegate.cpp +++ b/ui/qt/models/uat_delegate.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: diff --git a/ui/qt/models/uat_delegate.h b/ui/qt/models/uat_delegate.h index ced3c0343d..a2bc341897 100644 --- a/ui/qt/models/uat_delegate.h +++ b/ui/qt/models/uat_delegate.h @@ -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; diff --git a/ui/qt/widgets/editor_color_dialog.cpp b/ui/qt/widgets/editor_color_dialog.cpp deleted file mode 100644 index 2749ad7dd8..0000000000 --- a/ui/qt/widgets/editor_color_dialog.cpp +++ /dev/null @@ -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: - */ diff --git a/ui/qt/widgets/editor_color_dialog.h b/ui/qt/widgets/editor_color_dialog.h deleted file mode 100644 index 753d49c311..0000000000 --- a/ui/qt/widgets/editor_color_dialog.h +++ /dev/null @@ -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: - */ |