diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-13 21:15:11 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-20 08:47:18 +0100 |
commit | b1c0d424081530161c1637a1a24ff07a4b021097 (patch) | |
tree | 6db7322173e4ffd183534cc409e61ee6ed0ea3c8 /stats/statsview.cpp | |
parent | e1c0cace95d6ed19dff37a524c7f4b2288d258d7 (diff) | |
download | subsurface-b1c0d424081530161c1637a1a24ff07a4b021097.tar.gz |
statistics: remember position of legend when resizing
The position of the legend was reset when resizing. This was
OK as long as the legend wasn't movable.
To avoid resetting the position, store the center position
of the legend relatively to the size of the canvas. On
resize restore the center to the same relative size.
To avoid code duplication, move the sanitizing of the
coordinates from the StatsView to the Legend.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsview.cpp')
-rw-r--r-- | stats/statsview.cpp | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp index 983b128fe..f07b00896 100644 --- a/stats/statsview.cpp +++ b/stats/statsview.cpp @@ -236,14 +236,7 @@ void StatsView::mouseMoveEvent(QMouseEvent *event) QSizeF sceneSize = size(); if (sceneSize.width() <= 1.0 || sceneSize.height() <= 1.0) return; - QPointF pos = event->pos() - dragStartMouse + dragStartItem;; - QSizeF itemSize = draggedItem->getRect().size(); - double widthHalf = floor(itemSize.width() / 2); - double heightHalf = floor(itemSize.height() / 2); - QSizeF itemSizeHalf(floor(itemSize.width() / 2), floor(itemSize.height() / 2)); - QPointF sanitizedPos(std::clamp(pos.x(), -widthHalf, sceneSize.width() - widthHalf - 1.0), - std::clamp(pos.y(), -heightHalf, sceneSize.height() - heightHalf - 1.0)); - draggedItem->setPos(sanitizedPos); + draggedItem->setPos(event->pos() - dragStartMouse + dragStartItem); update(); } |