From 7608b93a0f2fec74a647fb9148e9fcd73e875a7e Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 14 Nov 2025 17:24:47 +0100 Subject: [PATCH] jfjoch_viewer: Handle autocontrast better --- viewer/JFJochViewerWindow.cpp | 3 +++ viewer/toolbar/JFJochViewerToolbarDisplay.cpp | 18 ++++++++---------- viewer/toolbar/JFJochViewerToolbarDisplay.h | 1 + viewer/widgets/JFJochDiffractionImage.cpp | 9 ++++++++- viewer/widgets/JFJochDiffractionImage.h | 5 +++++ viewer/widgets/JFJochImage.h | 2 +- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/viewer/JFJochViewerWindow.cpp b/viewer/JFJochViewerWindow.cpp index 603ca3ba..d128c6bd 100644 --- a/viewer/JFJochViewerWindow.cpp +++ b/viewer/JFJochViewerWindow.cpp @@ -153,6 +153,9 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString connect(toolBarDisplay, &JFJochViewerToolbarDisplay::setForeground, viewer, &JFJochDiffractionImage::changeForeground); + connect(viewer, &JFJochDiffractionImage::autoForegroundChanged, + toolBarDisplay, &JFJochViewerToolbarDisplay::updateAutoForeground); + connect(toolBarDisplay, &JFJochViewerToolbarDisplay::setAutoForeground, viewer, &JFJochDiffractionImage::setAutoForeground); diff --git a/viewer/toolbar/JFJochViewerToolbarDisplay.cpp b/viewer/toolbar/JFJochViewerToolbarDisplay.cpp index a0e03d52..fd8dd1b7 100644 --- a/viewer/toolbar/JFJochViewerToolbarDisplay.cpp +++ b/viewer/toolbar/JFJochViewerToolbarDisplay.cpp @@ -15,7 +15,7 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) addWidget(foreground_slider); auto_foreground_button = new QPushButton("Auto"); auto_foreground_button->setCheckable(true); - auto_foreground_button->setChecked(auto_foreground); + auto_foreground_button->setChecked(false); addWidget(auto_foreground_button); addWidget(new QLabel("  Color map  ")); @@ -40,11 +40,6 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) } void JFJochViewerToolbarDisplay::foregroundSet(double val) { - if (auto_foreground) { - auto_foreground = false; - auto_foreground_button->setChecked(false); - emit setAutoForeground(false); - } emit setForeground(static_cast(val)); } @@ -59,7 +54,10 @@ void JFJochViewerToolbarDisplay::colorComboBoxSet(int val) { void JFJochViewerToolbarDisplay::autoForegroundButtonPressed() { - auto_foreground = !auto_foreground; - auto_foreground_button->setChecked(auto_foreground); - emit setAutoForeground(auto_foreground); -} \ No newline at end of file + emit setAutoForeground(auto_foreground_button->isChecked()); +} + +void JFJochViewerToolbarDisplay::updateAutoForeground(bool val) { + QSignalBlocker blocker(auto_foreground_button); + auto_foreground_button->setChecked(val); +} diff --git a/viewer/toolbar/JFJochViewerToolbarDisplay.h b/viewer/toolbar/JFJochViewerToolbarDisplay.h index 782ec051..feaff257 100644 --- a/viewer/toolbar/JFJochViewerToolbarDisplay.h +++ b/viewer/toolbar/JFJochViewerToolbarDisplay.h @@ -28,6 +28,7 @@ signals: public slots: void updateForeground(float val); + void updateAutoForeground(bool val); private slots: void foregroundSet(double val); diff --git a/viewer/widgets/JFJochDiffractionImage.cpp b/viewer/widgets/JFJochDiffractionImage.cpp index 3b769e11..f8182c80 100644 --- a/viewer/widgets/JFJochDiffractionImage.cpp +++ b/viewer/widgets/JFJochDiffractionImage.cpp @@ -304,11 +304,12 @@ void JFJochDiffractionImage::loadImage(std::shared_ptr void JFJochDiffractionImage::setAutoForeground(bool input) { auto_fg = input; if (image && auto_fg) { - // If auto_foreground is not set, then view stays with the current settings till these are explicitely changed + // If auto_foreground is not set, then view stays with the current settings till these are explicitly changed foreground = image->GetAutoContrastValue(); emit foregroundChanged(foreground); Redraw(); } + emit autoForegroundChanged(auto_fg); } void JFJochDiffractionImage::setResolutionRing(QVector v) { @@ -376,3 +377,9 @@ void JFJochDiffractionImage::highlightIceRings(bool input) { highlight_ice_rings = input; updateOverlay(); } + +void JFJochDiffractionImage::changeForeground(float val) { + auto_fg = false; + emit autoForegroundChanged(false); + JFJochImage::changeForeground(val); +} diff --git a/viewer/widgets/JFJochDiffractionImage.h b/viewer/widgets/JFJochDiffractionImage.h index 919deb2f..b51e429b 100644 --- a/viewer/widgets/JFJochDiffractionImage.h +++ b/viewer/widgets/JFJochDiffractionImage.h @@ -43,6 +43,10 @@ private: float ice_ring_width_Q_recipA = 0.01; void mouseHover(QMouseEvent* event) override; + +signals: + void autoForegroundChanged(bool input); + public slots: void loadImage(std::shared_ptr image); void setAutoForeground(bool input); @@ -59,5 +63,6 @@ public slots: void showSaturation(bool input); void highlightIceRings(bool input); + void changeForeground(float val) override; }; diff --git a/viewer/widgets/JFJochImage.h b/viewer/widgets/JFJochImage.h index 7e7e9539..57340932 100644 --- a/viewer/widgets/JFJochImage.h +++ b/viewer/widgets/JFJochImage.h @@ -73,7 +73,7 @@ private slots: public slots: void setFeatureColor(QColor input); void setColorMap(int color_map); - void changeForeground(float val); + virtual void changeForeground(float val); void changeBackground(float val); void SetROIBox(QRect box);