diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-06 12:26:54 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-06 10:05:41 -0800 |
commit | 5b6f4685475be7f7b68375fcab465c1626950296 (patch) | |
tree | 5321de5a6baff8d6e41e6919a52bae724c300518 /stats/barseries.cpp | |
parent | f1203d365a4a890410038943cdd4aaaaf6ab558c (diff) | |
download | subsurface-5b6f4685475be7f7b68375fcab465c1626950296.tar.gz |
statistics: don't place labels at half-integer values
Placing labels at half-integer values gives horrible
rendering artifacts. Therefore, always round to integer
values. The easiest way to do this is right before setting
the position. Introduce a helper function to round QPointF
in such scenarios.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/barseries.cpp')
-rw-r--r-- | stats/barseries.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/stats/barseries.cpp b/stats/barseries.cpp index 766843703..252f05af6 100644 --- a/stats/barseries.cpp +++ b/stats/barseries.cpp @@ -118,7 +118,7 @@ void BarSeries::BarLabel::updatePosition(bool horizontal, bool center, const QRe return; } QPointF pos = rect.center(); - pos.rx() -= round(itemSize.width() / 2.0); + pos.rx() -= itemSize.width() / 2.0; // Heuristics: if the label fits nicely into the bar (bar height is at least twice the label height), // then put the label in the middle of the bar. Otherwise, put it at the top of the bar. @@ -130,29 +130,29 @@ void BarSeries::BarLabel::updatePosition(bool horizontal, bool center, const QRe setVisible(false); return; } - pos.ry() -= round(itemSize.height() / 2.0); + pos.ry() -= itemSize.height() / 2.0; } - item->setPos(pos); + item->setPos(roundPos(pos)); // Round to integer to avoid ugly artifacts. } else { if (itemSize.height() > rect.height()) { setVisible(false); return; } QPointF pos = rect.center(); - pos.ry() -= round(itemSize.height() / 2.0); + pos.ry() -= itemSize.height() / 2.0; // Heuristics: if the label fits nicely into the bar (bar width is at least twice the label height), // then put the label in the middle of the bar. Otherwise, put it to the right of the bar. isOutside = !center && rect.width() < 2.0 * itemSize.width(); if (isOutside) { - pos.rx() = round(rect.right() + 2.0); // Leave two pixels(?) space + pos.rx() = rect.right() + 2.0; // Leave two pixels(?) space } else { if (itemSize.width() > rect.width()) { setVisible(false); return; } } - item->setPos(pos); + item->setPos(roundPos(pos)); // Round to integer to avoid ugly artifacts. } setVisible(true); // If label changed from inside to outside, or vice-versa, the color might change. |