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>
46 lines
1.8 KiB
C++
46 lines
1.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <QColor>
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
class QChart;
|
|
class QWidget;
|
|
|
|
// The viewer's colour scheme: the light salmon one, or a dark indigo one. The View menu offers
|
|
// System, Light and Dark; System follows the desktop where Qt can read it (Qt 6.5+) and is light
|
|
// otherwise. A change applies at once: widgets that follow the palette repaint by themselves, and
|
|
// the ones that put colours into stylesheets, icons or charts listen to ThemeNotifier.
|
|
enum class ThemeChoice { System, Light, Dark };
|
|
ThemeChoice LoadThemeChoice();
|
|
void SetThemeChoice(ThemeChoice choice); // stores the choice and applies it
|
|
|
|
// Sets the palette and starts following the desktop's scheme. Call once, after the Fusion style is
|
|
// set and before any window is made.
|
|
void InitTheme();
|
|
bool DarkTheme();
|
|
|
|
class ThemeNotifier : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static ThemeNotifier *Instance();
|
|
signals:
|
|
void changed();
|
|
};
|
|
|
|
// Sets the widget's stylesheet from `style`, now and again after every theme change.
|
|
void SetThemedStyleSheet(QWidget *widget, const std::function<QString()> &style);
|
|
|
|
// Colours that widgets put into their own stylesheets and drawings.
|
|
QColor AccentTextColor(); // headings and headline values: navy on light, light blue on dark
|
|
QColor IconInkColor(); // toolbar glyphs and flat toolbar-button text
|
|
QString SliderStyle(); // the coral/navy sliders of the toolbars
|
|
|
|
// Qt Charts do not follow the widget palette; this gives a chart the current scheme's colours. It
|
|
// recolours the series too, so call it before adding series that carry colours of their own.
|
|
void StyleChart(QChart *chart);
|