From cad00032fc040973cd348bcc3708e054b6e6ffba Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 6 Jan 2021 14:33:06 +0100 Subject: 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 --- stats/informationbox.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'stats') diff --git a/stats/informationbox.cpp b/stats/informationbox.cpp index 706035f93..727b6fe83 100644 --- a/stats/informationbox.cpp +++ b/stats/informationbox.cpp @@ -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; -- cgit v1.2.3-70-g09d2