Files
Jungfraujoch/viewer/windows/JFJochMagnifierWindow.cpp
leonarski_fandClaude Opus 5 30252722e4 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>
2026-07-30 11:22:27 +02:00

41 lines
1.4 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochMagnifierWindow.h"
#include "../image_viewer/JFJochFollowerImage.h"
#include <QShowEvent>
JFJochMagnifierWindow::JFJochMagnifierWindow(QWidget *parent)
: JFJochHelperWindow(parent) {
setWindowTitle("Magnifier");
m_image = new JFJochFollowerImage(this);
setCentralWidget(m_image);
resize(320, 320);
}
void JFJochMagnifierWindow::setFrame(std::shared_ptr<const QImage> frame) {
// Just a pointer assignment plus an update() that a hidden window never acts on, so this
// needs no visibility guard: there is nothing expensive left to skip.
m_image->SetFrame(std::move(frame));
}
void JFJochMagnifierWindow::imageLoaded(std::shared_ptr<const JFJochReaderImage> image) {
m_image->SetPixelValues(std::move(image));
}
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);
}