Qt: Lighten non-printable byte view characters.

Draw non-printable characters using a lighter foreground color in the
byte view.

Change-Id: Ib97a1f9f897fa6f78e33ff80c7efea21f68ef2d5
Reviewed-on: https://code.wireshark.org/review/24935
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Gerald Combs 2017-12-21 14:28:07 -08:00 committed by Roland Knall
parent cf9d7fb8a5
commit 9354901dd1
2 changed files with 22 additions and 2 deletions

View File

@ -363,6 +363,9 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
// ASCII
if (show_ascii_) {
bool in_non_printable = false;
int np_start;
int np_len;
for (int tvb_pos = offset; tvb_pos <= max_tvb_pos; tvb_pos++) {
/* insert a space every separator_interval_ bytes */
if ((tvb_pos != offset) && ((tvb_pos % separator_interval_) == 0)) {
@ -378,14 +381,27 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
if (g_ascii_isprint(c)) {
line += c;
if (in_non_printable) {
in_non_printable = false;
addAsciiFormatRange(fmt_list, np_start, np_len, offset, max_tvb_pos, ModeNonPrintable);
}
} else {
// XXX Should we soften the text color as well?
line += UTF8_MIDDLE_DOT;
if (!in_non_printable) {
in_non_printable = true;
np_start = tvb_pos;
np_len = 1;
} else {
np_len++;
}
}
if (build_x_pos) {
x_pos_to_column_ += QVector<int>().fill(tvb_pos - offset, fontMetrics().width(line) - x_pos_to_column_.size());
}
}
if (in_non_printable) {
addAsciiFormatRange(fmt_list, np_start, np_len, offset, max_tvb_pos, ModeNonPrintable);
}
addAsciiFormatRange(fmt_list, proto_start_, proto_len_, offset, max_tvb_pos, ModeProtocol);
if (addAsciiFormatRange(fmt_list, field_start_, field_len_, offset, max_tvb_pos, ModeField)) {
offset_mode = ModeOffsetField;
@ -451,6 +467,9 @@ bool ByteViewText::addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int
format_range.format.setForeground(ColorUtils::byteViewMarkColor(false));
format_range.format.setBackground(ColorUtils::byteViewMarkColor(true));
break;
case ModeNonPrintable:
format_range.format.setForeground(offset_normal_fg_);
break;
}
fmt_list << format_range;
return true;

View File

@ -72,7 +72,8 @@ private:
ModeOffsetNormal,
ModeOffsetField,
ModeHover,
ModeMarked
ModeMarked,
ModeNonPrintable
} HighlightMode;
QTextLayout *layout_;