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 <QPalette>
17
18#include <memory>
19#include <optional>
20
27using IconPaletteRef = std::shared_ptr<std::optional<QPalette>>;
28
29inline IconPaletteRef makeIconPaletteRef()
30{
31 return std::make_shared<std::optional<QPalette>>();
32}
33
34inline const QPalette *iconPalettePtr(const IconPaletteRef &ref)
35{
36 return (ref && ref->has_value()) ? &ref->value() : nullptr;
37}
38
50inline QColor resolveIconToken(ThemeManager::ThemeToken token, const QPalette *palette)
51{
52 if (palette) {
53 switch (token) {
54 case ThemeManager::PaletteWindow: return palette->color(QPalette::Window);
55 case ThemeManager::PaletteBase: return palette->color(QPalette::Base);
56 case ThemeManager::PaletteText: return palette->color(QPalette::Text);
57 case ThemeManager::PaletteWindowText: return palette->color(QPalette::WindowText);
58 case ThemeManager::PaletteAlternateBase: return palette->color(QPalette::AlternateBase);
59 case ThemeManager::PaletteMid: return palette->color(QPalette::Mid);
60 case ThemeManager::PaletteMidLight: return palette->color(QPalette::Midlight);
61 case ThemeManager::PaletteHighlightedText: return palette->color(QPalette::HighlightedText);
62 default: break;
63 }
64 }
65 const QColor c = ThemeManager::instance()->color(token);
66 if (c.isValid())
67 return c;
68 return (palette ? *palette : qApp->palette()).color(QPalette::Text);
69}
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:27
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:50