Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
token_palette.h
Go to the documentation of this file.
1
9
10#pragma once
11
13
14#include <QApplication>
15#include <QColor>
16#include <QHash>
17#include <QPalette>
18
19#include <memory>
20#include <optional>
21
28using IconPaletteRef = std::shared_ptr<std::optional<QPalette>>;
29
30inline IconPaletteRef makeIconPaletteRef()
31{
32 return std::make_shared<std::optional<QPalette>>();
33}
34
40using IconTokenColorsRef = std::shared_ptr<QHash<ThemeManager::ThemeToken, QColor>>;
41
42inline IconTokenColorsRef makeIconTokenColorsRef()
43{
44 return std::make_shared<QHash<ThemeManager::ThemeToken, QColor>>();
45}
46
47inline const QPalette *iconPalettePtr(const IconPaletteRef &ref)
48{
49 return (ref && ref->has_value()) ? &ref->value() : nullptr;
50}
51
63inline QColor resolveIconToken(ThemeManager::ThemeToken token, const QPalette *palette)
64{
65 if (palette) {
66 switch (token) {
67 case ThemeManager::PaletteWindow: return palette->color(QPalette::Window);
68 case ThemeManager::PaletteBase: return palette->color(QPalette::Base);
69 case ThemeManager::PaletteText: return palette->color(QPalette::Text);
70 case ThemeManager::PaletteWindowText: return palette->color(QPalette::WindowText);
71 case ThemeManager::PaletteAlternateBase: return palette->color(QPalette::AlternateBase);
72 case ThemeManager::PaletteMid: return palette->color(QPalette::Mid);
73 case ThemeManager::PaletteMidlight: return palette->color(QPalette::Midlight);
74 case ThemeManager::PaletteHighlightedText: return palette->color(QPalette::HighlightedText);
75 default: break;
76 }
77 }
78 const QColor c = ThemeManager::instance()->color(token);
79 if (c.isValid())
80 return c;
81 return (palette ? *palette : qApp->palette()).color(QPalette::Text);
82}
std::shared_ptr< QHash< ThemeManager::ThemeToken, QColor > > IconTokenColorsRef
Token colour overrides shared between a ContrastAdaptIcon and its engine, so that ContrastAdaptIcon::...
Definition token_palette.h:40
std::shared_ptr< std::optional< QPalette > > IconPaletteRef
Palette override shared between an icon object and its engine, so that ThemedIcon::setPalette() / Con...
Definition token_palette.h:28
QColor resolveIconToken(ThemeManager::ThemeToken token, const QPalette *palette)
Resolve a theme token for an icon engine, optionally against a caller-supplied palette.
Definition token_palette.h:63