From 46a35e50044b7caf35bc0eaead3d70e39f8427ed Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Thu, 21 Dec 2017 09:02:06 -0800 Subject: [PATCH] Qt: Add back byte view hover. Add back the byte view hover behavior. Draw an overline+underline when hovering to make it a bit less distracting and to make hovered vs marked modes more obvious. Update names to match. Change-Id: I554d1cad98199f08f1c19796b14d158ad41706b4 Reviewed-on: https://code.wireshark.org/review/24932 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- ui/qt/utils/color_utils.cpp | 8 +++---- ui/qt/utils/color_utils.h | 6 ++--- ui/qt/widgets/byte_view_text.cpp | 41 ++++++++++++++++++++++++-------- ui/qt/widgets/byte_view_text.h | 5 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/ui/qt/utils/color_utils.cpp b/ui/qt/utils/color_utils.cpp index 907adc8afe..79dcd576ee 100644 --- a/ui/qt/utils/color_utils.cpp +++ b/ui/qt/utils/color_utils.cpp @@ -38,17 +38,17 @@ const QColor ColorUtils::expert_color_error = QColor ( 0xff, 0x5c, 0x5c ); const QColor ColorUtils::expert_color_foreground = QColor ( 0x00, 0x00, 0x00 ); /* Black */ const QColor ColorUtils::hidden_proto_item = QColor ( 0x44, 0x44, 0x44 ); /* Gray */ -const QRgb ColorUtils::byte_view_hover_bg_ = tango_butter_2; -const QRgb ColorUtils::byte_view_hover_fg_ = tango_sky_blue_5; +const QRgb ColorUtils::byte_view_mark_bg_ = tango_butter_2; +const QRgb ColorUtils::byte_view_mark_fg_ = tango_sky_blue_5; ColorUtils::ColorUtils(QObject *parent) : QObject(parent) { } -QColor ColorUtils::byteViewHoverColor(bool background) +QColor ColorUtils::byteViewMarkColor(bool background) { - return QColor(background ? byte_view_hover_bg_ : byte_view_hover_fg_); + return QColor(background ? byte_view_mark_bg_ : byte_view_mark_fg_); } // diff --git a/ui/qt/utils/color_utils.h b/ui/qt/utils/color_utils.h index 356c963539..f5ecf832a3 100644 --- a/ui/qt/utils/color_utils.h +++ b/ui/qt/utils/color_utils.h @@ -56,7 +56,7 @@ public: static const QList graphColors(); static QRgb graphColor(int item); static QRgb sequenceColor(int item); - static QColor byteViewHoverColor(bool background); + static QColor byteViewMarkColor(bool background); signals: @@ -65,8 +65,8 @@ public slots: private: static QList graph_colors_; static QList sequence_colors_; - static const QRgb byte_view_hover_bg_; - static const QRgb byte_view_hover_fg_; + static const QRgb byte_view_mark_bg_; + static const QRgb byte_view_mark_fg_; }; void color_filter_qt_add_cb(color_filter_t *colorf, gpointer user_data); diff --git a/ui/qt/widgets/byte_view_text.cpp b/ui/qt/widgets/byte_view_text.cpp index e1aeb2f95e..f6eddd4397 100644 --- a/ui/qt/widgets/byte_view_text.cpp +++ b/ui/qt/widgets/byte_view_text.cpp @@ -33,7 +33,6 @@ // and ASCII/EBCDIC. // - Add a UTF-8 and possibly UTF-xx option to the ASCII display. // - Add "copy bytes as" context menu items. -// - Add back hover. // - Move more common metrics to DataPrinter. Q_DECLARE_METATYPE(bytes_view_type) @@ -44,7 +43,7 @@ ByteViewText::ByteViewText(QByteArray data, packet_char_enc encoding, QWidget *p layout_(new QTextLayout()), encoding_(encoding), hovered_byte_offset_(-1), - hovered_byte_lock_(false), + marked_byte_offset_(-1), proto_start_(0), proto_len_(0), field_start_(0), @@ -241,17 +240,24 @@ void ByteViewText::mousePressEvent (QMouseEvent *event) { return; } - hovered_byte_lock_ = !hovered_byte_lock_; - emit byteSelected(byteOffsetAtPixel(event->pos())); + if (marked_byte_offset_ < 0) { + marked_byte_offset_ = byteOffsetAtPixel(event->pos()); + hovered_byte_offset_ = -1; + } else { + marked_byte_offset_ = -1; + mouseMoveEvent(event); + } + emit byteSelected(marked_byte_offset_); } void ByteViewText::mouseMoveEvent(QMouseEvent *event) { - if (hovered_byte_lock_) { + if (marked_byte_offset_ >= 0) { return; } - emit byteHovered(byteOffsetAtPixel(event->pos())); + hovered_byte_offset_ = byteOffsetAtPixel(event->pos()); + emit byteHovered(hovered_byte_offset_); viewport()->update(); } @@ -347,8 +353,11 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y offset_mode = ModeOffsetField; } addHexFormatRange(fmt_list, field_a_start_, field_a_len_, offset, max_tvb_pos, ModeField); + if (marked_byte_offset_ >= offset && marked_byte_offset_ <= max_tvb_pos) { + addHexFormatRange(fmt_list, marked_byte_offset_, 1, offset, max_tvb_pos, ModeMarked); + } if (hovered_byte_offset_ >= offset && hovered_byte_offset_ <= max_tvb_pos) { - addHexFormatRange(fmt_list, hovered_byte_offset_, hovered_byte_offset_ + 1, offset, max_tvb_pos, ModeField); + addHexFormatRange(fmt_list, hovered_byte_offset_, 1, offset, max_tvb_pos, ModeHover); } } @@ -370,6 +379,7 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y if (g_ascii_isprint(c)) { line += c; } else { + // XXX Should we soften the text color as well? line += UTF8_MIDDLE_DOT; } if (build_x_pos) { @@ -381,8 +391,11 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y offset_mode = ModeOffsetField; } addAsciiFormatRange(fmt_list, field_a_start_, field_a_len_, offset, max_tvb_pos, ModeField); + if (marked_byte_offset_ >= offset && marked_byte_offset_ <= max_tvb_pos) { + addAsciiFormatRange(fmt_list, marked_byte_offset_, 1, offset, max_tvb_pos, ModeMarked); + } if (hovered_byte_offset_ >= offset && hovered_byte_offset_ <= max_tvb_pos) { - addAsciiFormatRange(fmt_list, hovered_byte_offset_, hovered_byte_offset_ + 1, offset, max_tvb_pos, ModeField); + addAsciiFormatRange(fmt_list, hovered_byte_offset_, 1, offset, max_tvb_pos, ModeHover); } } @@ -427,8 +440,16 @@ bool ByteViewText::addFormatRange(QList &fmt_list, int format_range.format.setForeground(offset_field_fg_); break; case ModeHover: - format_range.format.setForeground(ColorUtils::byteViewHoverColor(false)); - format_range.format.setBackground(ColorUtils::byteViewHoverColor(true)); + // QTextCharFormat doesn't appear to let us draw a complete border. + // This is the next best thing. + format_range.format.setFontUnderline(true); + format_range.format.setFontOverline(true); + break; + case ModeMarked: + // XXX Should we get rid of byteViewMarkColor and just draw an + // overline + underline instead? + format_range.format.setForeground(ColorUtils::byteViewMarkColor(false)); + format_range.format.setBackground(ColorUtils::byteViewMarkColor(true)); break; } fmt_list << format_range; diff --git a/ui/qt/widgets/byte_view_text.h b/ui/qt/widgets/byte_view_text.h index 657f4e950a..73f58cb51d 100644 --- a/ui/qt/widgets/byte_view_text.h +++ b/ui/qt/widgets/byte_view_text.h @@ -71,7 +71,8 @@ private: ModeProtocol, ModeOffsetNormal, ModeOffsetField, - ModeHover + ModeHover, + ModeMarked } HighlightMode; QTextLayout *layout_; @@ -106,7 +107,7 @@ private: // Data highlight int hovered_byte_offset_; - bool hovered_byte_lock_; + int marked_byte_offset_; int proto_start_; int proto_len_; int field_start_;