statistics: improve placement of info-box

The info box was placed either above or below the mouse-pointer.
If the pointer is at the center and the infobox higher than
half the chart, it would cross the border. Detect this case
and place the info box at the center.

Same logic for right/left, though that should typically not
happen.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-06 14:33:06 +01:00 committed by Dirk Hohndel
parent 405e6b6b69
commit cad00032fc

View file

@ -40,11 +40,19 @@ void InformationBox::setPos(QPointF pos)
QRectF plotArea = chart->plotArea();
double x = pos.x() + distanceFromPointer;
if (x + width >= plotArea.right() && pos.x() - width >= plotArea.x())
x = pos.x() - width;
if (x + width >= plotArea.right()) {
if (pos.x() - width >= plotArea.x())
x = pos.x() - width;
else
x = pos.x() - width / 2.0;
}
double y = pos.y() + distanceFromPointer;
if (y + height >= plotArea.bottom() && pos.y() - height >= plotArea.y())
y = pos.y() - height;
if (y + height >= plotArea.bottom()) {
if (pos.y() - height >= plotArea.y())
y = pos.y() - height;
else
y = pos.y() - height / 2.0;
}
setRect(x, y, width, height);
double actY = y + 2.0 * informationBorder;