Skip to content

nmeasim::app::theme

namespace nmeasim::app::theme · Applications

The look of the desktop application: the Theme singleton with its night-bridge and daylight looks and the option to follow the desktop, and the code-painted icons.

Each look is a Colors table of colours by role. Theme::apply turns the table into a QPalette and, through style_sheet, into a Qt style sheet by replacing the {token} placeholders of one template shared by both looks. Widgets that paint themselves (map, dials, status lights, console highlighting) read the table directly and repaint when Theme::changed is emitted. make_icon and themed_icon paint the toolbar and menu symbols in the colours of the look, so no image files are needed. Part of the desktop application, on Qt Widgets.

Types

Type Description
Colors Every colour of one look, by role.
Theme Applies the looks to the application and tells custom-painted widgets when they change.

Summary

Enumerations

Name Description
Icon The toolbar and menu symbols.
Mode What the operator chose under View → Theme.

Functions

Name Description
make_icon() Paints an icon in the given colours.
themed_icon() Paints an icon in the colours of the current theme.
to_string() Returns the name under which a mode is stored in the preferences.
mode_from_string() Parses a mode name stored in the preferences.
colors_for() Returns the colour table of a look.
style_sheet() Generates the application style sheet of a look from its colours.

Variables

Name Description
kAllIcons Every Icon value, in declaration order, for tests and for regenerating icons after a theme change.

Enumerations

Icon

enum class Icon

The toolbar and menu symbols.

They are painted in code, so they stay sharp at every size and follow the colours of the current theme.

Enumerator Value Description
NewProfile A page with a plus sign: new profile.
Open A folder: open a profile.
Save A floppy disk: save the profile.
Settings A cog wheel: the settings dialog.
Start A filled triangle pointing right: start the simulation.
Stop A filled square: stop the simulation.
Pause Two filled bars: pause the simulation.
Step A triangle against a bar: pause and advance by one tick.
Steering A ship's wheel with six spokes: steering mode.
Record A filled circle, always in the danger colour: record a log.
Track A polyline through four points: open a track to follow.
Log Four bulleted lines: open a log file for replay.
Follow Cross hairs around a dot: keep the vessel centred on the map.
Destination A diamond around a dot: clear the destination.

Declared in src/app/theme/icons.hpp:19

Mode

enum class Mode

What the operator chose under View → Theme.

Stored in the preferences under appearance/theme as the text given by to_string.

Enumerator Value Description
System Night or day, following the light or dark setting of the desktop; resolved by Theme::resolve. Stored as system.
Night The dark night bridge look: charcoal panels, cyan accents, dimmed map tiles. The default. Stored as night.
Day The light daylight look: white panels, teal accents, map tiles as they are. Stored as day.

Declared in src/app/theme/theme.hpp:35

Functions

make_icon()

QIcon make_icon(Icon icon, const QColor& color, const QColor& active, const QColor& disabled)

Paints an icon in the given colours.

The symbol is drawn with antialiasing on a transparent background, with round-capped strokes 1.8 units wide in a 24 by 24 unit design grid. Pixmaps are rendered in advance at 16, 20, 24 and 32 pixels, each at device pixel ratios 1 and 2 for HiDPI screens: 32 pixmaps in all, so the call is too costly for a paint event and its result is meant to be kept, for example on a QAction.

Parameters

Name Type Description
icon Icon Symbol to paint.
color const QColor& Colour of the normal, unchecked state.
active const QColor& Colour of the checked state of a checkable action (QIcon::On).
disabled const QColor& Colour of the disabled state, checked or not.

Returns QIcon: The icon with every size, mode and state filled in.

Declared in src/app/theme/icons.hpp:56 · defined in src/app/theme/icons.cpp:185

themed_icon()

QIcon themed_icon(Icon icon)

Paints an icon in the colours of the current theme.

Calls make_icon with Colors::text for the normal state, Colors::accent for the checked state and Colors::inactive when disabled. Icon::Record is painted in Colors::danger, checked or not, so that it always reads as a red record button.

Parameters

Name Type Description
icon Icon Symbol to paint.

Returns QIcon: The icon; it keeps its colours when the theme changes later, so request it again after Theme::changed.

Declared in src/app/theme/icons.hpp:68 · defined in src/app/theme/icons.cpp:198

to_string()

QString to_string(Mode mode)

Returns the name under which a mode is stored in the preferences.

Parameters

Name Type Description
mode Mode Mode to name.

Returns QString: system, night or day; night for a value outside the enumeration.

Declared in src/app/theme/theme.hpp:51 · defined in src/app/theme/theme.cpp:194

mode_from_string()

Mode mode_from_string(const QString& text)

Parses a mode name stored in the preferences.

The comparison is case-sensitive, as to_string writes lower case.

Parameters

Name Type Description
text const QString& Stored name: system, night or day.

Returns Mode: The matching mode; Mode::Night, the default, for an empty or unknown name.

Declared in src/app/theme/theme.hpp:58 · defined in src/app/theme/theme.cpp:206

colors_for()

const Colors& colors_for(Mode mode)

Returns the colour table of a look.

Parameters

Name Type Description
mode Mode Mode::Night or Mode::Day, or Mode::System, which is resolved from the desktop's colour scheme with Theme::resolve.

Returns const Colors&: The table of that look, valid for the lifetime of the program.

Declared in src/app/theme/theme.hpp:142 · defined in src/app/theme/theme.cpp:216

style_sheet()

QString style_sheet(const Colors& colors)

Generates the application style sheet of a look from its colours.

Every {token} of the template shared by both looks is replaced by a colour: the name of a Colors member ({window}, {panel}, {panel_raised}, {inset}, {border}, {border_strong}, {text}, {text_dim}, {text_value}, {accent}, {accent_text}, {warning}, {inactive}) stands for that colour, {accent_soft} for accent at 22 % opacity in a dark look and 15 % in a light one (checked tool buttons, table selection), and {panel_translucent} for panel at 88 % opacity (buttons floating over the map). Opaque colours are written as #rrggbb, translucent ones as rgba(r, g, b, a) with a from 0 to 255.

Input fields (line edits, spin boxes, combo boxes) are deliberately left out and follow the Fusion style and the palette: a style-sheet rule for them would also restyle the editor inside every QSpinBox and drop its arrows.

Parameters

Name Type Description
colors const Colors& Colours of the look.

Returns QString: The complete style sheet, with no {token} left.

Declared in src/app/theme/theme.hpp:161 · defined in src/app/theme/theme.cpp:222

Variables

kAllIcons

Icon kAllIcons[]{Icon::NewProfile, Icon::Open, Icon::Save, Icon::Settings, Icon::Start, Icon::Stop, Icon::Pause, Icon::Step, Icon::Steering, Icon::Record, Icon::Track, Icon::Log, Icon::Follow, Icon::Destination}

Every Icon value, in declaration order, for tests and for regenerating icons after a theme change.

Declared in src/app/theme/icons.hpp:38