Cockatrice 2026-06-01-Development-3.1.0-beta.3
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:
47 std::array<QBrush, Role::MaxRole + 1> brushes;
49 /*
50 Internal cache for multiple backgrounds
51 */
52 std::array<QBrushMap, Role::MaxRole + 1> brushesCache;
53
54protected:
56 QBrush loadBrush(QString fileName, QColor fallbackColor);
57 QBrush loadExtraBrush(QString fileName, QBrush &fallbackBrush);
58 void applyStyleAndPalette(const QString &themeName,
59 const ThemeConfig &themeCfg,
60 const PaletteConfig &palCfg,
61 const QString &activeScheme);
62
63public:
64 bool isBuiltInTheme();
65 bool isDarkMode(const QString &themeDirPath);
67 // Returns the path to the currently active theme directory (empty = default)
68 QString getCurrentThemePath() const
69 {
70 return currentThemePath;
71 }
72 // Load the global theme settings (style + color scheme preference)
73 static ThemeConfig loadGlobalConfig(const QString &themeDirPath);
74 static bool saveGlobalConfig(const QString &themeDirPath, const ThemeConfig &cfg);
75
76 // Load/save per-scheme palette colors
77 static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme);
78 static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
79 void setColorScheme(const QString &scheme);
80
81 void reloadCurrentTheme();
82 void previewPalette(const PaletteConfig &cfg, const QString &scheme);
83
84 QBrush &getBgBrush(Role zone);
85 QBrush getExtraBgBrush(Role zone, int zoneId = 0);
86protected slots:
87 void themeChangedSlot();
88signals:
90};
91
93
94#endif
Definition theme_manager.h:29
QBrush loadBrush(QString fileName, QColor fallbackColor)
Definition theme_manager.cpp:179
QBrush & getBgBrush(Role zone)
Definition theme_manager.cpp:402
bool isDarkMode(const QString &themeDirPath)
Definition theme_manager.cpp:116
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:52
std::array< QBrush, Role::MaxRole+1 > brushes
Definition theme_manager.h:47
QString currentThemePath
Definition theme_manager.h:46
void setColorScheme(const QString &scheme)
Definition theme_manager.cpp:245
static ThemeConfig loadGlobalConfig(const QString &themeDirPath)
Definition theme_manager.cpp:207
void themeChanged()
static bool saveGlobalConfig(const QString &themeDirPath, const ThemeConfig &cfg)
Definition theme_manager.cpp:212
void themeChangedSlot()
Definition theme_manager.cpp:328
QBrush loadExtraBrush(QString fileName, QBrush &fallbackBrush)
Definition theme_manager.cpp:193
bool isBuiltInTheme()
Definition theme_manager.cpp:133
void applyStyleAndPalette(const QString &themeName, const ThemeConfig &themeCfg, const PaletteConfig &palCfg, const QString &activeScheme)
Definition theme_manager.cpp:269
void reloadCurrentTheme()
Definition theme_manager.cpp:256
QStringMap & getAvailableThemes()
Definition theme_manager.cpp:140
QString getCurrentThemePath() const
Definition theme_manager.h:68
static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme)
Definition theme_manager.cpp:217
QBrush getExtraBgBrush(Role zone, int zoneId=0)
Definition theme_manager.cpp:407
static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg)
Definition theme_manager.cpp:225
void previewPalette(const PaletteConfig &cfg, const QString &scheme)
Definition theme_manager.cpp:261
void ensureThemeDirectoryExists()
Definition theme_manager.cpp:107
ThemeManager(QObject *parent=nullptr)
Definition theme_manager.cpp:92
QStringMap availableThemes
Definition theme_manager.h:48
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:49
QMap< QString, QString > QStringMap
Definition theme_manager.h:23