Theme¶
class nmeasim::app::theme::Theme · Applications
Applies the looks to the application and tells custom-painted widgets when they change.
Inherits QObject
Declared in src/app/theme/theme.hpp (line 172)
There is one instance, reached through instance. It starts in Mode::Night with the night colours, but nothing is applied to the application until apply is called, which main does at start-up with the mode read from appearance/theme. While the mode is Mode::System, the instance re-applies the look whenever the desktop switches between light and dark.
The instance lives in the GUI thread and is used only there.
Summary¶
Public member functions
| Name | Description |
|---|---|
apply() |
Applies a look to the running application: Fusion style, palette and style sheet. |
mode() |
Returns the mode last passed to apply, which may be Mode::System. |
resolved() |
Returns the look in use after resolving Mode::System. |
colors() |
Returns the colours of the look in use. |
Public static member functions
| Name | Description |
|---|---|
instance() |
Returns the application-wide instance, creating it on the first call. |
readout_font() |
Returns the font for large digital readouts: the bundled Share Tech Mono. |
mono_font() |
Returns the fixed-width font for the console and other text columns. |
resolve() |
Resolves Mode::System from the desktop's colour scheme. |
Signals
| Name | Description |
|---|---|
changed() |
Emitted when the look in use changed: from apply when the operator chose a look that resolves to other colours, on the first apply, and when the desktop switched between light and dark while the mode is Mode::System. |
Private member functions
| Name | Description |
|---|---|
Theme() |
Creates the instance and starts following desktop colour-scheme changes when the application provides style hints. |
Private data members
| Name | Description |
|---|---|
mode_ |
Mode last passed to apply; may be Mode::System. |
resolved_ |
Look in use: Mode::Night or Mode::Day, never Mode::System. |
applied_ |
Whether apply has installed a look; until then the application has neither the palette nor the style sheet of resolved_. |
Public member functions¶
apply()¶
void apply(Mode mode)
Applies a look to the running application: Fusion style, palette and style sheet.
Resolves Mode::System with resolve. On the first call it installs the Fusion style. When the resolved look differs from the one in use, or on the first call, it sets the application palette from the colours of the resolved look (disabled text in Colors::inactive) and, when the application is a QApplication, its style sheet from style_sheet, and emits changed. Setting the application style sheet re-polishes every widget, which is why the look in use is not installed again. Does not store the choice in the preferences; the caller does.
Emits changed synchronously before returning, and only when the look changed: choosing Mode::System while the desktop is dark and the night look is in use changes the mode but not the look.
Parameters
| Name | Type | Description |
|---|---|---|
mode |
Mode |
Mode to apply. |
Postconditions
mode()returnsmodeandresolved()the look now in use.
Declared in src/app/theme/theme.hpp:201 · defined in src/app/theme/theme.cpp:273
mode()¶
Mode mode() const noexcept
Returns the mode last passed to apply, which may be Mode::System.
Returns Mode: The chosen mode; Mode::Night before the first apply.
Declared in src/app/theme/theme.hpp:205
resolved()¶
Mode resolved() const noexcept
Returns the look in use after resolving Mode::System.
Returns Mode: Mode::Night or Mode::Day; Mode::Night before the first apply.
Declared in src/app/theme/theme.hpp:209
colors()¶
const Colors& colors() const
Returns the colours of the look in use.
Returns const Colors&: The table of resolved(), valid for the lifetime of the program. It does not follow later changes: read it again after changed.
Declared in src/app/theme/theme.hpp:214
Public static member functions¶
instance()¶
static Theme& instance()
Returns the application-wide instance, creating it on the first call.
The instance lives until the program exits. The constructor connects to the application's style hints to follow desktop colour-scheme changes, so the first call belongs after the QApplication is created, as in main.
Returns Theme&: The single instance.
Declared in src/app/theme/theme.hpp:183 · defined in src/app/theme/theme.cpp:247
readout_font()¶
static QFont readout_font(double point_size)
Returns the font for large digital readouts: the bundled Share Tech Mono.
The font is registered from the resource :/fonts/ShareTechMono-Regular.ttf on the first call; it is distributed under the SIL Open Font License 1.1. When it cannot be loaded, this and every later call fall back to the system's fixed-width font.
Parameters
| Name | Type | Description |
|---|---|---|
point_size |
double |
Size in points, greater than 0. |
Returns QFont: A new font of that size.
Preconditions
- A
QGuiApplicationexists.
Declared in src/app/theme/theme.hpp:225 · defined in src/app/theme/theme.cpp:322
mono_font()¶
static QFont mono_font()
Returns the fixed-width font for the console and other text columns.
Returns QFont: The system's fixed-width font at its default size, not Share Tech Mono.
Preconditions
- A
QGuiApplicationexists.
Declared in src/app/theme/theme.hpp:230 · defined in src/app/theme/theme.cpp:336
resolve()¶
static Mode resolve(Mode mode)
Resolves Mode::System from the desktop's colour scheme.
Parameters
| Name | Type | Description |
|---|---|---|
mode |
Mode |
Mode to resolve. |
Returns Mode: mode unchanged when it is Mode::Night or Mode::Day. For Mode::System, Mode::Day when the desktop reports a light scheme, otherwise Mode::Night, including when the scheme is unknown or no style hints are available.
Declared in src/app/theme/theme.hpp:238 · defined in src/app/theme/theme.cpp:262
Signals¶
changed()¶
void changed()
Emitted when the look in use changed: from apply when the operator chose a look that resolves to other colours, on the first apply, and when the desktop switched between light and dark while the mode is Mode::System.
Not emitted when the look stays the same.
Emitted synchronously from apply, after the palette and style sheet are installed, so receivers read the new colors. Connected widgets repaint or regenerate their icons.
Declared in src/app/theme/theme.hpp:249
Private member functions¶
Theme()¶
Theme()
Creates the instance and starts following desktop colour-scheme changes when the application provides style hints.
Private: use instance.
Declared in src/app/theme/theme.hpp:254 · defined in src/app/theme/theme.cpp:252
Private data members¶
mode_¶
Mode mode_{Mode::Night}
Mode last passed to apply; may be Mode::System.
Declared in src/app/theme/theme.hpp:257
resolved_¶
Mode resolved_{Mode::Night}
Look in use: Mode::Night or Mode::Day, never Mode::System.
Declared in src/app/theme/theme.hpp:259
applied_¶
bool applied_{false}
Whether apply has installed a look; until then the application has neither the palette nor the style sheet of resolved_.
Declared in src/app/theme/theme.hpp:262