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 <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
5631bdbac6
commit
46a35e5004
|
@ -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_);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
static const QList<QRgb> 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<QRgb> graph_colors_;
|
||||
static QList<QRgb> 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);
|
||||
|
|
|
@ -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<QTextLayout::FormatRange> &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;
|
||||
|
|
|
@ -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_;
|
||||
|
|
Loading…
Reference in New Issue