diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-12-05 15:37:27 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-01-08 04:48:26 +0000 |
commit | 3c372c7bac98d34d0342837007f3b86c3cba8ff8 (patch) | |
tree | b444b502d5f7ae5f2ed75657d764b141fb9314e2 /ui/qt/widgets/syntax_line_edit.cpp | |
parent | 5d30fb5d1a05917648667c368be9f9dbd295b9b1 (diff) |
Qt: Add syntax line edit feedback symbols.
Draw a circle+backslash or a warning triangle in the far right of the
line edit entry for invalid and deprecated filters respectively. This
should provide an additional clue for color blind users.
Bug: 15326
Change-Id: I55a1e214834a340ccda3bfe8880bba12c5e274e9
Reviewed-on: https://code.wireshark.org/review/30936
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/widgets/syntax_line_edit.cpp')
-rw-r--r-- | ui/qt/widgets/syntax_line_edit.cpp | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/ui/qt/widgets/syntax_line_edit.cpp b/ui/qt/widgets/syntax_line_edit.cpp index ae4e082548..feee60a8fe 100644 --- a/ui/qt/widgets/syntax_line_edit.cpp +++ b/ui/qt/widgets/syntax_line_edit.cpp @@ -16,21 +16,22 @@ #include <epan/dfilter/dfilter.h> #include <epan/column-info.h> +#include <wsutil/utf8_entities.h> + #include <ui/qt/widgets/syntax_line_edit.h> #include <ui/qt/utils/color_utils.h> +#include <ui/qt/utils/stock_icon.h> #include <QAbstractItemView> #include <QCompleter> #include <QKeyEvent> +#include <QPainter> #include <QScrollBar> #include <QStringListModel> +#include <QStyleOptionFrame> #include <limits> -// To do: -// - Add indicator icons for syntax states to make things more clear for -// color blind people? - const int max_completion_items_ = 20; SyntaxLineEdit::SyntaxLineEdit(QWidget *parent) : @@ -350,6 +351,48 @@ void SyntaxLineEdit::focusOutEvent(QFocusEvent *event) QLineEdit::focusOutEvent(event); } +// Add indicator icons for syntax states in order to make things more clear for +// color blind people. +void SyntaxLineEdit::paintEvent(QPaintEvent *event) +{ + QLineEdit::paintEvent(event); + + QString si_name; + + switch (syntax_state_) { + case Invalid: + si_name = "x-filter-invalid"; + break; + case Deprecated: + si_name = "x-filter-deprecated"; + break; + default: + return; + } + + QStyleOptionFrame opt; + initStyleOption(&opt); + QRect cr = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this); + QRect sir = QRect(0, 0, 14, 14); // QIcon::paint scales, which is not what we want. + + if (fontMetrics().width(text()) + cr.height() > cr.width() || cr.height() < sir.height()) { + // No space to draw + return; + } + + QIcon state_icon = StockIcon(si_name); + if (state_icon.isNull()) { + return; + } + + int si_off = (cr.height() - sir.height()) / 2; + sir.moveTop(si_off); + sir.moveRight(cr.right() - si_off); + QPainter painter(this); + painter.setOpacity(0.25); + state_icon.paint(&painter, sir); +} + void SyntaxLineEdit::insertFieldCompletion(const QString &completion_text) { if (!completer_) return; |