diff --git a/viewer/windows/JFJochMagnifierWindow.cpp b/viewer/windows/JFJochMagnifierWindow.cpp index 11c779eb..7ba758ac 100644 --- a/viewer/windows/JFJochMagnifierWindow.cpp +++ b/viewer/windows/JFJochMagnifierWindow.cpp @@ -4,6 +4,8 @@ #include "JFJochMagnifierWindow.h" #include "../image_viewer/JFJochFollowerImage.h" +#include + JFJochMagnifierWindow::JFJochMagnifierWindow(QWidget *parent) : JFJochHelperWindow(parent) { setWindowTitle("Magnifier"); @@ -23,7 +25,16 @@ void JFJochMagnifierWindow::imageLoaded(std::shared_ptr } void JFJochMagnifierWindow::centerAt(QPointF scenePos) { + m_last_scene_pos = scenePos; if (!isVisible()) return; m_image->CenterAt(scenePos); } + +void JFJochMagnifierWindow::showEvent(QShowEvent *event) { + JFJochHelperWindow::showEvent(event); + // setFrame keeps the pixels current while hidden, but the centre does not move, so without this + // the window re-opens showing wherever the cursor happened to be when it was closed. + if (m_last_scene_pos) + m_image->CenterAt(*m_last_scene_pos); +} diff --git a/viewer/windows/JFJochMagnifierWindow.h b/viewer/windows/JFJochMagnifierWindow.h index de01c7d6..78d34927 100644 --- a/viewer/windows/JFJochMagnifierWindow.h +++ b/viewer/windows/JFJochMagnifierWindow.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "JFJochHelperWindow.h" #include @@ -19,6 +20,10 @@ class JFJochMagnifierWindow : public JFJochHelperWindow { Q_OBJECT JFJochFollowerImage *m_image; + // Where the cursor last was. Hover positions arriving while the window is hidden are remembered + // rather than dropped, so re-opening shows the region the cursor is over now and not the one it + // was over when the window was closed. + std::optional m_last_scene_pos; public: explicit JFJochMagnifierWindow(QWidget *parent = nullptr); @@ -27,6 +32,9 @@ public: // displayed from the frame the main view rendered, nothing is converted here. void imageLoaded(std::shared_ptr image) override; +protected: + void showEvent(QShowEvent *event) override; + public slots: void setFrame(std::shared_ptr frame); void centerAt(QPointF scenePos);