From 92ce87e599aa969494c3d9a34639152f658de7df Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 8 Dec 2025 10:58:01 +0100 Subject: [PATCH] jfjoch_viewer: Set foreground with holding F --- viewer/JFJochViewerWindow.cpp | 24 ++++++++++++++++++++++++ viewer/JFJochViewerWindow.h | 3 +++ viewer/image_viewer/JFJochImage.cpp | 9 ++++++++- viewer/image_viewer/JFJochImage.h | 4 ++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/viewer/JFJochViewerWindow.cpp b/viewer/JFJochViewerWindow.cpp index 97c0c687..89e23b97 100644 --- a/viewer/JFJochViewerWindow.cpp +++ b/viewer/JFJochViewerWindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "JFJochImageReadingWorker.h" #include "image_viewer/JFJochDiffractionImage.h" @@ -28,6 +29,8 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString menuBar = new JFJochViewerMenu(this); setMenuBar(menuBar); + setFocusPolicy(Qt::StrongFocus); + auto toolBarImage = new JFJochViewerToolbarImage(this); addToolBar(Qt::TopToolBarArea, toolBarImage); addToolBarBreak(Qt::TopToolBarArea); @@ -315,6 +318,9 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString connect(menuBar, &JFJochViewerMenu::openDatasetInfo, this, &JFJochViewerWindow::NewDatasetInfo); NewDatasetInfo(); + connect(this, &JFJochViewerWindow::adjustForegroundButton, + viewer, &JFJochDiffractionImage::adjustForeground); + if (!file.isEmpty()) LoadFile(file, 0, 1); } @@ -360,3 +366,21 @@ void JFJochViewerWindow::NewDatasetInfo() { connect(info, &JFJochViewerDatasetInfo::writeStatusBar, statusbar, &JFJochViewerStatusBar::display); } + +void JFJochViewerWindow::keyPressEvent(QKeyEvent *event) { + if (event->key() == Qt::Key_F) { + emit adjustForegroundButton(true); + event->accept(); + return; + } + QMainWindow::keyPressEvent(event); +} + +void JFJochViewerWindow::keyReleaseEvent(QKeyEvent *event) { + if (event->key() == Qt::Key_F) { + emit adjustForegroundButton(false); + event->accept(); + return; + } + QMainWindow::keyReleaseEvent(event); +} diff --git a/viewer/JFJochViewerWindow.h b/viewer/JFJochViewerWindow.h index 843b891b..31454ca7 100644 --- a/viewer/JFJochViewerWindow.h +++ b/viewer/JFJochViewerWindow.h @@ -32,6 +32,8 @@ private: QThread *reading_thread; + void keyPressEvent(QKeyEvent *event) override; + void keyReleaseEvent(QKeyEvent *event) override; public slots: void LoadFile(const QString &filename, qint64 image_number, qint64 summation); void LoadImage(qint64 image_number, qint64 summation); @@ -40,6 +42,7 @@ public slots: signals: void LoadFileRequest(const QString &filename, qint64 image_number, qint64 summation); void LoadImageRequest(int64_t image_number, int64_t summation); + void adjustForegroundButton(bool input); }; diff --git a/viewer/image_viewer/JFJochImage.cpp b/viewer/image_viewer/JFJochImage.cpp index a69db633..2c9f1246 100644 --- a/viewer/image_viewer/JFJochImage.cpp +++ b/viewer/image_viewer/JFJochImage.cpp @@ -76,7 +76,10 @@ void JFJochImage::wheelEvent(QWheelEvent *event) { // Get the position of the mouse in scene coordinates QPointF targetScenePos = mapToScene(event->position().toPoint()); - if (event->modifiers() == Qt::ShiftModifier) { + const bool adjustForeground = + (event->modifiers() == Qt::ShiftModifier) || m_adjustForegroundWithWheel; + + if (adjustForeground) { float new_foreground = foreground + event->angleDelta().y() / 120.0f; if (new_foreground < 1) new_foreground = 1.0; @@ -821,3 +824,7 @@ void JFJochImage::fitToViewShorterSideOnce() { initial_fit_done_ = true; last_fit_viewport_ = vp; } + +void JFJochImage::adjustForeground(bool input) { + m_adjustForegroundWithWheel = input; +} diff --git a/viewer/image_viewer/JFJochImage.h b/viewer/image_viewer/JFJochImage.h index a6c97d1f..8e3bd522 100644 --- a/viewer/image_viewer/JFJochImage.h +++ b/viewer/image_viewer/JFJochImage.h @@ -13,6 +13,8 @@ class JFJochImage : public QGraphicsView { Q_OBJECT + bool m_adjustForegroundWithWheel = false; + void DrawROI(); virtual void addCustomOverlay(); void updateROI(); @@ -101,6 +103,8 @@ public slots: void centerOnSpot(QPointF point); void fitToView(); + + void adjustForeground(bool input); public: explicit JFJochImage(QWidget *parent = nullptr); };