Files
Jungfraujoch/viewer/JFJochViewerStatusBar.cpp
T
Filip LeonarskiandClaude Opus 5.5 0be8eb2bca Viewer: dark theme, switchable live from the View menu
View > Theme offers Follow system / Light / Dark, stored in the settings.
Follow system uses the desktop's colour scheme where Qt reports it (6.5+)
and is light otherwise. The dark theme is a deep indigo (#1A1D3A panels,
#12142B entry fields and charts).

The palettes live in the new ViewerTheme module. A switch applies at once:
the application stylesheet is set again after the palette so every widget
is re-polished (with a stylesheet active, polished widgets otherwise keep
their old palette); widgets that bake colours into stylesheets use
SetThemedStyleSheet, which re-applies them on ThemeNotifier::changed;
toolbar icons draw their glyph at paint time through an icon engine, so the
ink follows the theme (and stays sharp at any size); charts re-theme and
rebuild. Hard-coded white backgrounds on entry fields and tables are
removed in favour of the palette's base colour.

The idle detector-status badge in the status bar is now transparent instead
of an empty default-styled progress bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 17:51:50 +02:00

97 lines
3.5 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochViewerStatusBar.h"
#include <algorithm>
JFJochViewerStatusBar::JFJochViewerStatusBar(QWidget *parent) : QStatusBar(parent) {
rate_label = new QLabel(this);
rate_label->setFixedWidth(60);
rate_label->setAlignment(Qt::AlignCenter);
addPermanentWidget(rate_label);
state_box = new QProgressBar(this);
state_box->setFixedWidth(110);
state_box->setRange(0, 1000);
state_box->setValue(0);
state_box->setTextVisible(true);
state_box->setAlignment(Qt::AlignCenter);
state_box->setFormat("");
// No detector session yet: the badge keeps its place but draws nothing (see setHttpConnection).
state_box->setStyleSheet("QProgressBar { border: none; background: transparent; }");
addPermanentWidget(state_box);
}
void JFJochViewerStatusBar::display(QString input) {
showMessage(input, 60000);
}
void JFJochViewerStatusBar::setBrokerStatus(BrokerStatus status) {
QString text;
switch (status.state) {
case JFJochState::Inactive: text = "Inactive"; break;
case JFJochState::Idle: text = "Idle"; break;
case JFJochState::Measuring: text = "Measuring"; break;
case JFJochState::Error: text = "Error"; break;
case JFJochState::Busy: text = "Busy"; break;
case JFJochState::Calibration: text = "Calibration"; break;
}
state_box->setFormat(text);
if (status.progress.has_value())
state_box->setValue(std::clamp(static_cast<int>(status.progress.value() * 1000.0f), 0, 1000));
else
state_box->setValue(1000.0);
const QString chunk = (status.state == JFJochState::Error) ? "#d9534f" : "#5cb85c";
state_box->setStyleSheet(QString(
"QProgressBar { border: 1px solid #aaa; border-radius: 2px; background: transparent; }"
"QProgressBar::chunk { background-color: %1; }").arg(chunk));
if (status.message.has_value() && !status.message.value().empty())
state_box->setToolTip(QString::fromStdString(status.message.value()));
else
state_box->setToolTip(text);
}
void JFJochViewerStatusBar::setHttpConnection(bool connected, QString addr) {
if (addr.isEmpty()) {
// No detector session at all -> blank the whole cluster (but keep the reserved space).
state_box->setFormat("");
state_box->setValue(0);
state_box->setStyleSheet("QProgressBar { border: none; background: transparent; }");
state_box->setToolTip("");
rate_label->setText("");
return;
}
if (!connected) {
// Connection lost: clear live readouts but keep the badge so the user sees why.
state_box->setStyleSheet(QString(
"QProgressBar { border: 1px solid #aaa; border-radius: 2px; background: transparent; }"
"QProgressBar::chunk { background-color: #888888; }"));
state_box->setFormat("Disconnected");
state_box->setValue(0);
state_box->setToolTip("");
rate_label->setText("");
}
}
void JFJochViewerStatusBar::setAutoloadMode(JFJochImageReadingWorker::AutoloadMode mode) {
autoload_mode = mode;
}
void JFJochViewerStatusBar::setImageNumber(int64_t in_total_images, int64_t in_current_image) {
total_images = in_total_images;
current_image = in_current_image;
}
void JFJochViewerStatusBar::setLiveRate(double hz) {
if (hz > 0.0)
rate_label->setText(QString::number(hz, 'f', 1) + " Hz");
else
rate_label->setText("");
}