Wireshark 4.7.2
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
ThemePaletteBuilder Class Reference

#include <theme_palette_builder.h>

Public Types

using TokenMap = QHash<ThemeManager::ThemeToken, ThemeColorPair>

Static Public Member Functions

static QPalette build (const TokenMap &tokens, bool isDarkMode, const QHash< QString, ThemeManager::ThemeToken > &tokenNameCache, const QHash< QString, QPalette::ColorRole > &paletteRoleCache, const QPalette &osBaseline)
static void apply (const TokenMap &tokens, bool isDarkMode, const QHash< QString, ThemeManager::ThemeToken > &tokenNameCache, const QHash< QString, QPalette::ColorRole > &paletteRoleCache, const QPalette &osBaseline)
static QPalette builtInDarkPalette ()
static QPalette builtInLightPalette ()

Detailed Description

Builds the QApplication::palette() from the current theme's token map and mode, and pushes it via QApplication::setPalette().

The baseline palette comes from:

  • macOS (any supported Qt) and Windows on Qt ≥ 6.8: a caller- supplied osBaseline snapshot. ThemeManager captures this from the platform style at construction time (when the palette is pristine) and refreshes it whenever the effective scheme flips. Reading QApplication::palette() here would be wrong: once the builder has pushed any palette via setPalette(), subsequent reads return that customized palette — so consecutive theme switches would accumulate overrides instead of restarting from a clean OS baseline.
  • Linux (any Qt) and Windows on Qt < 6.8: our own built-in light or dark palette (see builtInLightPalette() / builtInDarkPalette()). The Linux platform themes (gnome/gtk3/qt6ct) silently ignore QStyleHints::setColorScheme() and pin both the hint and standardPalette() to the OS value, which makes "Dark mode on a Light OS" (or vice versa) impossible to honor without supplying our own palette. Old Fusion has the same problem. osBaseline is ignored on these platforms.

Theme-provided palette overrides (the palette: section of theme.jsonc) are applied on top of the baseline. Brand-driven roles (Highlight, Link, Accent, HighlightedText) are always overlaid last, so themes don't need to set them.

Member Function Documentation

◆ apply()

void ThemePaletteBuilder::apply ( const TokenMap & tokens,
bool isDarkMode,
const QHash< QString, ThemeManager::ThemeToken > & tokenNameCache,
const QHash< QString, QPalette::ColorRole > & paletteRoleCache,
const QPalette & osBaseline )
static

Convenience wrapper: calls build() and pushes the result via QApplication::setPalette().

◆ build()

QPalette ThemePaletteBuilder::build ( const TokenMap & tokens,
bool isDarkMode,
const QHash< QString, ThemeManager::ThemeToken > & tokenNameCache,
const QHash< QString, QPalette::ColorRole > & paletteRoleCache,
const QPalette & osBaseline )
static

Build and return the full QPalette from the token map without pushing it to QApplication. Callers that need the palette value before it is applied (e.g. to derive tokens first) should call this and then push the result themselves via QApplication::setPalette().

Parameters
tokensPopulated theme token map (brand, accent, optional palette overrides).
isDarkModeWhich side of color pairs to use.
tokenNameCacheMap "palettewindow" → ThemeToken::PaletteWindow (etc.), shared with the parser/QSS loader.
paletteRoleCacheMap "palettewindow" → QPalette::Window (etc.) — Qt's 21 palette-role keys by lowercased enumerator name.
osBaselinePristine OS palette snapshot supplied by ThemeManager; used as the baseline on macOS and Windows Qt ≥ 6.8. Ignored on Linux and Windows Qt < 6.8.

◆ builtInDarkPalette()

QPalette ThemePaletteBuilder::builtInDarkPalette ( )
static

Built-in dark QPalette used as the baseline on non-macOS platforms when the current mode is dark. Based on https://gist.github.com/QuantumCD/6245215 with Disabled-group coverage added.

◆ builtInLightPalette()

QPalette ThemePaletteBuilder::builtInLightPalette ( )
static

Built-in light QPalette used as the baseline on non-macOS platforms when the current mode is light. Mirrors Qt Fusion's default light palette so the visual identity stays familiar when our override replaces the system's.


The documentation for this class was generated from the following files: