aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-01-18 14:07:57 -0800
committerGerald Combs <gerald@wireshark.org>2018-01-19 19:22:12 +0000
commit655892c0a673bb3893b502c2bdab63dcb663fc08 (patch)
tree91785e1e23925685d249d1d708cd770327ca646d
parent8d06115dbf72f652d464ea80ffdabe2b1a0cb67e (diff)
Qt: Force integer font metrics in the byte view.
Force the layout engine to use integer arithmetic so that we don't run into wierd rounding artifacts. Include the leading when applying formats. Restrict the hover line width to either 0.5 or 1 logical pixels. Change-Id: Icc992e085e96e328ed4ed247271f75ddd69637bc Reviewed-on: https://code.wireshark.org/review/25381 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r--ui/qt/widgets/byte_view_text.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/ui/qt/widgets/byte_view_text.cpp b/ui/qt/widgets/byte_view_text.cpp
index 58a0a6f75b..988f64c578 100644
--- a/ui/qt/widgets/byte_view_text.cpp
+++ b/ui/qt/widgets/byte_view_text.cpp
@@ -162,13 +162,15 @@ void ByteViewText::markAppendix(int start, int length)
void ByteViewText::setMonospaceFont(const QFont &mono_font)
{
- mono_font_ = mono_font;
+ mono_font_ = QFont(mono_font);
+ mono_font_.setStyleStrategy(QFont::ForceIntegerMetrics);
- const QFontMetricsF fm(mono_font);
+ const QFontMetricsF fm(mono_font_);
font_width_ = fm.width('M');
- setFont(mono_font);
- layout_->setFont(mono_font);
+ setFont(mono_font_);
+ viewport()->setFont(mono_font_);
+ layout_->setFont(mono_font_);
// We should probably use ProtoTree::rowHeight.
line_height_ = fontMetrics().height();
@@ -181,7 +183,6 @@ void ByteViewText::paintEvent(QPaintEvent *)
{
QPainter painter(viewport());
painter.translate(-horizontalScrollBar()->value() * font_width_, 0);
- painter.setFont(mono_font_);
// Pixel offset of this row
int row_y = 0;
@@ -205,13 +206,14 @@ void ByteViewText::paintEvent(QPaintEvent *)
// Data rows
int widget_height = height();
+ int leading = fontMetrics().leading();
painter.save();
x_pos_to_column_.clear();
while( (int) (row_y + line_height_) < widget_height && offset < (int) data_.count()) {
drawLine(&painter, offset, row_y);
offset += row_width_;
- row_y += line_height_;
+ row_y += line_height_ + leading;
}
painter.restore();
@@ -219,14 +221,16 @@ void ByteViewText::paintEvent(QPaintEvent *)
// We can't do this in drawLine since the next line might draw over our rect.
if (!hover_outlines_.isEmpty()) {
qreal pen_width = 1.0;
- #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
- pen_width = 1.0 / devicePixelRatio();
- #endif
QPen ho_pen;
QColor ho_color = palette().text().color();
ho_color.setAlphaF(0.5);
ho_pen.setColor(ho_color);
ho_pen.setWidthF(pen_width);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+ if (devicePixelRatio() > 1) {
+ pen_width = 0.5;
+ }
+#endif
painter.save();
painter.setPen(ho_pen);
@@ -451,7 +455,7 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
layout_->beginLayout();
QTextLine tl = layout_->createLine();
tl.setLineWidth(totalPixels());
- tl.setPosition(QPointF(0.0, 0.0));
+ tl.setLeadingIncluded(true);
layout_->endLayout();
layout_->draw(painter, QPointF(0.0, row_y));
}
@@ -464,7 +468,6 @@ bool ByteViewText::addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int
QTextLayout::FormatRange format_range;
format_range.start = start;
format_range.length = length;
- format_range.format.setProperty(QTextFormat::LineHeight, line_height_);
switch (mode) {
case ModeNormal:
return false;
@@ -482,7 +485,7 @@ bool ByteViewText::addFormatRange(QList<QTextLayout::FormatRange> &fmt_list, int
break;
case ModeMarked:
// XXX Should we get rid of byteViewMarkColor and just draw an
- // overline + underline instead?
+ // outline instead?
format_range.format.setForeground(ColorUtils::byteViewMarkColor(false));
format_range.format.setBackground(ColorUtils::byteViewMarkColor(true));
break;