mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
f1203d365a
commit
5b6f468547
7 changed files with 31 additions and 12 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue