Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
theme_manager.h
Go to the documentation of this file.
1
6
7#ifndef THEMEMANAGER_H
8#define THEMEMANAGER_H
9
10#include "theme_config.h"
11
12#include <QBrush>
13#include <QDir>
14#include <QLoggingCategory>
15#include <QMap>
16#include <QObject>
17#include <QPixmap>
18#include <QString>
19#include <array>
20
21inline Q_LOGGING_CATEGORY(ThemeManagerLog, "theme_manager");
22
23typedef QMap<QString, QString> QStringMap;
24typedef QMap<int, QBrush> QBrushMap;
25
26class QApplication;
27
28class ThemeManager : public QObject
29{
30 Q_OBJECT
31public:
32 ThemeManager(QObject *parent = nullptr);
33
43
44private:
46 // Pristine application palette captured at startup, before any custom theme
47 // palette is applied. Used as the base when a theme supplies no palette, so
48 // switching away from a custom palette restores the original colours.
51 std::array<QBrush, Role::MaxRole + 1> brushes;
53 /*
54 Internal cache for multiple backgrounds
55 */
56 std::array<QBrushMap, Role::MaxRole + 1> brushesCache;
57
58protected:
60 QBrush loadBrush(QString fileName, QColor fallbackColor);
61 QBrush loadExtraBrush(QString fileName, QBrush &fallbackBrush);
62 void applyStyleAndPalette(const QString &themeName,
63 const ThemeConfig &themeCfg,
64 const PaletteConfig &palCfg,
65 const QString &activeScheme);
66
67public:
68 bool isBuiltInTheme();
69 // Explicit color scheme of the theme: theme.cfg's ColorScheme setting
70 // (Dark/Light), falling back to the OS color scheme when it is "System".
71 bool isDarkMode(const QString &themeDirPath) const;
72 // The resolved scheme of the currently active theme.
73 bool isDarkModeActive() const
74 {
76 }
78 // Returns the path to the currently active theme directory (empty = default)
79 QString getCurrentThemePath() const
80 {
81 return currentThemePath;
82 }
83 // Load the global theme settings (style + color scheme preference)
84 static ThemeConfig loadGlobalConfig(const QString &themeDirPath);
85 static bool saveGlobalConfig(const QString &themeDirPath, const ThemeConfig &cfg);
86
87 // Load/save per-scheme palette colors
88 static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme);
89 static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
90 // Load the theme's shipped default palette, falling back to the system
91 // theme directory when it is absent from the resolved (user) directory.
92 static PaletteConfig
93 loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme);
97 static bool commitPalette(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
98 void setColorScheme(const QString &scheme);
99 void setStyleName(const QString &styleName);
100
101 void reloadCurrentTheme();
102 void previewPalette(const PaletteConfig &cfg, const QString &scheme);
103
104 QBrush &getBgBrush(Role zone);
105 QBrush getExtraBgBrush(Role zone, int zoneId = 0);
106protected slots:
107 void themeChangedSlot();
108signals:
110};
111
113
114#endif
Definition theme_manager.h:29
QBrush loadBrush(QString fileName, QColor fallbackColor)
Definition theme_manager.cpp:195
QBrush & getBgBrush(Role zone)
Definition theme_manager.cpp:474
void setStyleName(const QString &styleName)
Definition theme_manager.cpp:299
QString defaultStyleName
Definition theme_manager.h:45
Role
Definition theme_manager.h:35
@ Table
Definition theme_manager.h:39
@ Hand
Definition theme_manager.h:37
@ MinRole
Definition theme_manager.h:36
@ Player
Definition theme_manager.h:40
@ MaxRole
Definition theme_manager.h:41
@ Stack
Definition theme_manager.h:38
std::array< QBrushMap, Role::MaxRole+1 > brushesCache
Definition theme_manager.h:56
bool isDarkMode(const QString &themeDirPath) const
Definition theme_manager.cpp:126
static PaletteConfig loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme)
Definition theme_manager.cpp:261
std::array< QBrush, Role::MaxRole+1 > brushes
Definition theme_manager.h:51
QString currentThemePath
Definition theme_manager.h:50
void setColorScheme(const QString &scheme)
Definition theme_manager.cpp:288
static ThemeConfig loadGlobalConfig(const QString &themeDirPath)
Definition theme_manager.cpp:223
void themeChanged()
static bool saveGlobalConfig(const QString &themeDirPath, const ThemeConfig &cfg)
Definition theme_manager.cpp:228
bool isDarkModeActive() const
Definition theme_manager.h:73
void themeChangedSlot()
Definition theme_manager.cpp:389
QBrush loadExtraBrush(QString fileName, QBrush &fallbackBrush)
Definition theme_manager.cpp:209
QPalette defaultPalette
Definition theme_manager.h:49
bool isBuiltInTheme()
Definition theme_manager.cpp:143
void applyStyleAndPalette(const QString &themeName, const ThemeConfig &themeCfg, const PaletteConfig &palCfg, const QString &activeScheme)
Definition theme_manager.cpp:323
void reloadCurrentTheme()
Definition theme_manager.cpp:310
QStringMap & getAvailableThemes()
Definition theme_manager.cpp:164
static bool commitPalette(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg)
Writes cfg to disk as the theme's palette-<scheme>.toml and updates the theme's stored colour scheme ...
Definition theme_manager.cpp:275
QString getCurrentThemePath() const
Definition theme_manager.h:79
static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme)
Definition theme_manager.cpp:233
QBrush getExtraBgBrush(Role zone, int zoneId=0)
Definition theme_manager.cpp:479
static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg)
Definition theme_manager.cpp:241
void previewPalette(const PaletteConfig &cfg, const QString &scheme)
Definition theme_manager.cpp:315
void ensureThemeDirectoryExists()
Definition theme_manager.cpp:117
ThemeManager(QObject *parent=nullptr)
Definition theme_manager.cpp:101
QStringMap availableThemes
Definition theme_manager.h:52
QMap< QString, QString > QStringMap
Definition sound_engine.h:21
Definition theme_config.h:22
Definition theme_config.h:10
QMap< int, QBrush > QBrushMap
Definition theme_manager.h:24
Q_LOGGING_CATEGORY(ThemeManagerLog, "theme_manager")
ThemeManager * themeManager
Definition main.cpp:61
QMap< QString, QString > QStringMap
Definition theme_manager.h:23