Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
ThemeStyleSheetLoader Class Reference

#include <theme_stylesheet_loader.h>

Public Types

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

Static Public Member Functions

static QString load (const QString &name, const TokenMap &tokens, bool isDarkMode)
static QString resolvePaletteRoles (const QString &sheet, const QPalette &palette)

Detailed Description

Loads a QSS stylesheet from the built-in :/stylesheets/ resource tree and resolves every wstheme(RoleName) token by looking up RoleName in the current theme's color map.

Split out of ThemeManager so the loader logic — stylesheet path sanitization, QSS read, token regex, role-enum lookup — lives alongside the other theme helpers under ui/qt/utils/themes/.

Stateless: every call reads fresh resource contents and resolves tokens against the token map the caller provides. ThemeManager is the usual caller and passes its own themeColors_ / isDarkMode().

Member Function Documentation

◆ load()

QString ThemeStyleSheetLoader::load ( const QString & name,
const TokenMap & tokens,
bool isDarkMode )
static

Load :/stylesheets/<name>.qss and return its contents with every wstheme(RoleName) token replaced by the resolved #rrggbb hex of the corresponding ThemeToken, picked from tokens using isDarkMode to choose the light/dark side.

Returns an empty QString on any of:

  • name is empty or contains illegal characters / path traversal attempts (.., leading /, leading ., backslash, etc.)
  • The resource file cannot be opened.

Tokens that don't resolve (unknown role name or missing color in the map) are stripped from the output and a qWarning is emitted — Qt's QSS parser is all-or-nothing per object, so leaving a literal wstheme(Foo) in place would silently drop the entire rule on the first typo; stripping keeps the rest of the rules valid and the warning surfaces the typo.

Parameters
nameLogical name under :/stylesheets/, without extension (e.g. "widgets/learn-card").
tokensCurrent theme's color map.
isDarkModeWhich side of color pairs to select.

◆ resolvePaletteRoles()

QString ThemeStyleSheetLoader::resolvePaletteRoles ( const QString & sheet,
const QPalette & palette )
static

Replaces every palette(<role>) in sheet with palette's Active color for that role. Qt resolves palette() in style sheets against the application palette, not the widget's, so a sheet previewing another palette resolves the references itself. Role names are the ones Qt's style sheet grammar accepts, derived from QPalette::ColorRole. A name that matches no role is left as written (Qt ignores it on the live page too) and logged with qWarning once per name.

Parameters
sheetStyle sheet text.
palettePalette whose Active colors are substituted.
Returns
The sheet with the palette() references resolved.

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