aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-07-27 13:42:59 -0700
committerGerald Combs <gerald@wireshark.org>2018-07-27 21:54:15 +0000
commitce2d45dfc1f956bdcffc641947787fd0cc07866f (patch)
tree3ce6973ae12c0c5c3641862f96cbc3c63c5dd535 /ui/qt/models
parentda774fbc61a029e31481b0cc2bd10ce428e70446 (diff)
Qt: Comment some of the sparkline code.
Explain some of the magic numbers and other parts of the sparkline code. Change-Id: Idfad30e773bd852ac021326467cf03ada91f6efc Reviewed-on: https://code.wireshark.org/review/28874 Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/models')
-rw-r--r--ui/qt/models/sparkline_delegate.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/ui/qt/models/sparkline_delegate.cpp b/ui/qt/models/sparkline_delegate.cpp
index 33369bc9de..e142556de1 100644
--- a/ui/qt/models/sparkline_delegate.cpp
+++ b/ui/qt/models/sparkline_delegate.cpp
@@ -19,6 +19,9 @@ void SparkLineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
{
QList<int> points = qvariant_cast<QList<int> >(index.data(Qt::UserRole));
int max = 1;
+ // We typically draw a sparkline alongside some text. Size our
+ // drawing area based on an Em width. and a bit of eyballing on
+ // Linux, macOS, and Windows.
int em_w = option.fontMetrics.height();
int content_w = option.rect.width() - (em_w / 4);
int content_h = option.fontMetrics.ascent() - 1;
@@ -72,12 +75,19 @@ void SparkLineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
painter->setPen(option_vi.palette.color(cg, QPalette::Text));
}
+ // As a general rule, aliased painting renders to pixels and
+ // antialiased painting renders to mathematical coordinates:
+ // http://doc.qt.io/qt-5/coordsys.html
+ // Shift our coordinates by 0.5 pixels, otherwise our lines end
+ // up blurry.
painter->setRenderHint(QPainter::Antialiasing, true);
painter->translate(
option.rect.x() + (em_w / 8) + 0.5,
option.rect.y() + ((option.rect.height() - option.fontMetrics.height()) / 2) + 1 + 0.5);
painter->drawPolyline(QPolygonF(fpoints));
+ // Some sparklines are decorated with dots at the beginning and end.
+ // Ours look better without in my (gcc) opinion.
// painter->setPen(Qt::NoPen);
// painter->setBrush(option.palette.foreground());
// painter->drawEllipse(fpoints.first(), 2, 2);