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

#include <theme_token_handler.h>

Public Types

using TokenMap = QHash<ThemeManager::ThemeToken, ThemeColorPair>
using SourceMap = QHash<ThemeManager::ThemeToken, const char *>

Static Public Member Functions

static QColor sideOf (const TokenMap &tokens, ThemeManager::ThemeToken role, bool isDarkMode)
static void deriveAll (TokenMap &tokens, bool isDarkMode, const QPalette &palette, const ColorMath::ContrastRatios &ratios, SourceMap *sources=nullptr)
static QList< ThemeManager::ThemeToken > sourceTokens (const char *source)

Detailed Description

Computes every derived token from the mandatory brand+accent colors (plus the current QPalette for section-header-style derivations).

The handler reads the already-populated token map (brand / accent / expert / packets / conversation / palette from the theme), and enriches it in place with the generated tokens:

SectionHeader / SectionHeaderHover (from brand + QPalette::Mid) ControlBorder / Border* (from QPalette::Mid + Base) Card* / OverlayCard* (from palette.alternateBase pin or Base, BorderSeparator, Highlight, Link) SyntaxKey (from QPalette::Mid + Base) HeaderBackground / HeaderText / HeaderTextMuted (from QPalette Highlight / HighlightedText / Window) Update* (from accent.success) Packets* (from brand + palette base/text) Conversation* (from brand + accent + base) Expert* (from accent variants — alpha-blend) Filter* (from accent + base) Code* (fixed light / dark code editor defaults) Syntax* (from palette.mid + accent) ControlBorder / Border* / MutedText (from palette base/mid/text) TextOn* (black or white on accent / filter tints) Diff* / Notice* (from base + accent) HighlightColorOrange / HighlightColorGreen (aliases from accent)

Only-if-missing semantics: if a theme has already supplied a specific token explicitly (e.g. a theme that overrides PacketsSelection), the derivation leaves that value alone. Matches the behavior ThemeManager::derive() had with overwrite=false.

Member Typedef Documentation

◆ SourceMap

using ThemeTokenHandler::SourceMap = QHash<ThemeManager::ThemeToken, const char *>

Rule text per token, untranslated; translate in the "ThemeTokenHandler" context.

Member Function Documentation

◆ deriveAll()

void ThemeTokenHandler::deriveAll ( TokenMap & tokens,
bool isDarkMode,
const QPalette & palette,
const ColorMath::ContrastRatios & ratios,
SourceMap * sources = nullptr )
static

Enriches tokens in-place with every derived role.

Parameters
tokensMap populated from theme.jsonc parsing. Must contain the mandatory brand + accent colors; the derivation will read them and write back the generated entries.
isDarkModeSelects which side of palette-override color pairs to consult for Packets/Conversation derivations. Does not affect tokens that store both light/dark variants — those are derived from the pair wholesale.
paletteThe palette to read Mid and other base roles from. Pass the palette returned by ThemePaletteBuilder::build() so derivation uses the new values even before the palette has been pushed to QApplication (fixes Qt 5 signal-ordering: ApplicationPaletteChanged fires synchronously inside setPalette(), so tokens must be ready before that call). Defaults to QApplication::palette() for backwards-compatible call sites.
ratiosThe contrast ratio set every derivation targets. Passed explicitly rather than read from ColorMath::activeRatios(), so a preview can derive for a contrast level that is not applied.
sourcesWhen not null, receives for every token this function assigns the rule it applied, as written next to the rule (QT_TRANSLATE_NOOP). Recorded whether or not the theme already set the token.

◆ sideOf()

QColor ThemeTokenHandler::sideOf ( const TokenMap & tokens,
ThemeManager::ThemeToken role,
bool isDarkMode )
static

The color of role for one mode: the dark side when isDarkMode, else the light side. Invalid when role is NoRole, absent from tokens, or has no valid color on that side.

◆ sourceTokens()

QList< ThemeManager::ThemeToken > ThemeTokenHandler::sourceTokens ( const char * source)
static

The colors an untranslated rule text names, in order of first appearance (the main source first), without duplicates.

Parameters
sourcea rule text as recorded by deriveAll() or ThemePaletteBuilder::build().

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