Viewer: the magnifier re-opens on the current cursor position
centerAt returns early while the window is hidden, and nothing replays the last position when it comes back, so re-opening the magnifier showed whatever region the cursor was over when it was closed - with current pixels, which makes it look like a live view of the wrong place. Remember the position while hidden and apply it on show. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include "JFJochMagnifierWindow.h"
|
||||
#include "../image_viewer/JFJochFollowerImage.h"
|
||||
|
||||
#include <QShowEvent>
|
||||
|
||||
JFJochMagnifierWindow::JFJochMagnifierWindow(QWidget *parent)
|
||||
: JFJochHelperWindow(parent) {
|
||||
setWindowTitle("Magnifier");
|
||||
@@ -23,7 +25,16 @@ void JFJochMagnifierWindow::imageLoaded(std::shared_ptr<const JFJochReaderImage>
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "JFJochHelperWindow.h"
|
||||
#include <QPointF>
|
||||
@@ -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<QPointF> 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<const JFJochReaderImage> image) override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
public slots:
|
||||
void setFrame(std::shared_ptr<const QImage> frame);
|
||||
void centerAt(QPointF scenePos);
|
||||
|
||||
Reference in New Issue
Block a user