1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
# Theme System
## Overview
MeshMC supports application-wide theming through a `ThemeManager` that manages both visual themes (widget styling, colors) and icon themes. Themes can be built-in or user-provided via the `themes/` directory.
## Architecture
### Key Classes
| Class | File | Purpose |
|---|---|---|
| `ThemeManager` | `ui/themes/ThemeManager.{h,cpp}` | Theme registry and lifecycle |
| `ITheme` | `ui/themes/ITheme.{h,cpp}` | Abstract theme interface |
| `BrightTheme` | `ui/themes/BrightTheme.{h,cpp}` | Built-in light theme |
| `DarkTheme` | `ui/themes/DarkTheme.{h,cpp}` | Built-in dark theme |
| `FusionTheme` | `ui/themes/FusionTheme.{h,cpp}` | Qt Fusion-based theme |
| `SystemTheme` | `ui/themes/SystemTheme.{h,cpp}` | OS-native theme |
| `CustomTheme` | `ui/themes/CustomTheme.{h,cpp}` | User-defined theme |
| `CatPack` | `ui/themes/CatPack.{h,cpp}` | Cat background customization |
## ITheme Interface
All themes implement the `ITheme` interface:
```cpp
class ITheme
{
public:
virtual ~ITheme() {}
// Identity
virtual QString id() = 0;
virtual QString name() = 0;
// Application
virtual void apply(bool initial);
// Qt integration
virtual bool hasStyleSheet() = 0;
virtual QString appStyleSheet() = 0;
virtual QString qtTheme() = 0;
// Colors
virtual Qt::ColorScheme colorScheme() = 0;
virtual QPalette colorScheme(QPalette basePalette);
virtual double fadeAmount() = 0;
virtual QColor fadeColor() = 0;
// Badges
virtual QString postprocessSVG(QString svg);
// Tooltip colors
virtual QColor tooltipBackground();
virtual QColor tooltipForeground();
};
```
### apply()
The `apply()` method is called when activating a theme:
1. Sets `QApplication::setStyle()` based on `qtTheme()`
2. Sets the palette via `QApplication::setPalette()`
3. Applies stylesheet from `appStyleSheet()` if `hasStyleSheet()` is true
4. Emits color scheme change for Qt6 integration
### Color Scheme
`colorScheme()` returns `Qt::ColorScheme::Light` or `Qt::ColorScheme::Dark`, used by Qt6 to adjust native widget rendering.
### Fade
`fadeAmount()` and `fadeColor()` control the disabled-state appearance of instances in the grid view:
- `fadeColor()` — base color for fade overlay (typically background color)
- `fadeAmount()` — opacity of the fade (0.0 = no fade, 1.0 = fully faded)
## Built-in Themes
### SystemTheme
Uses the OS-provided widget style and colors:
```cpp
class SystemTheme : public ITheme {
public:
QString id() override { return "system"; }
QString name() override { return QObject::tr("System"); }
bool hasStyleSheet() override { return false; }
QString qtTheme() override { return QStyleFactory::keys().first(); }
Qt::ColorScheme colorScheme() override { return Qt::ColorScheme::Unknown; }
};
```
### BrightTheme
A clean light theme with custom palette:
```cpp
class BrightTheme : public FusionTheme {
public:
QString id() override { return "bright"; }
QString name() override { return QObject::tr("Bright"); }
Qt::ColorScheme colorScheme() override { return Qt::ColorScheme::Light; }
bool hasStyleSheet() override { return true; }
// Custom color palette with light backgrounds and dark text
};
```
### DarkTheme
A dark theme for low-light environments:
```cpp
class DarkTheme : public FusionTheme {
public:
QString id() override { return "dark"; }
QString name() override { return QObject::tr("Dark"); }
Qt::ColorScheme colorScheme() override { return Qt::ColorScheme::Dark; }
bool hasStyleSheet() override { return true; }
// Custom color palette with dark backgrounds and light text
};
```
### FusionTheme
Base class for Bright and Dark themes, using Qt's Fusion style:
```cpp
class FusionTheme : public ITheme {
public:
QString qtTheme() override { return "Fusion"; }
// Shared Fusion-based styling logic
};
```
## CustomTheme
User-provided themes loaded from the `themes/` directory:
```cpp
class CustomTheme : public ITheme {
public:
CustomTheme(ITheme* baseTheme, const QString& folder);
QString id() override;
QString name() override;
bool hasStyleSheet() override;
QString appStyleSheet() override;
Qt::ColorScheme colorScheme() override;
private:
ITheme* m_baseTheme; // Fallback theme
QString m_id;
QString m_name;
QString m_styleSheet;
QString m_folder;
// Custom palette overrides
};
```
### Custom Theme Format
A custom theme is a directory in `themes/` containing:
```
themes/my-theme/
├── theme.json # Theme metadata and palette
└── themeStyle.css # Qt stylesheet (optional)
```
#### theme.json
```json
{
"name": "My Custom Theme",
"baseTheme": "dark",
"colors": {
"Window": "#1a1b26",
"WindowText": "#c0caf5",
"Base": "#16161e",
"AlternateBase": "#1a1b26",
"ToolTipBase": "#1a1b26",
"ToolTipText": "#c0caf5",
"Text": "#c0caf5",
"Button": "#24283b",
"ButtonText": "#c0caf5",
"BrightText": "#ff0000",
"Link": "#7aa2f7",
"Highlight": "#3d59a1",
"HighlightedText": "#c0caf5",
"fadeColor": "#1a1b26",
"fadeAmount": 0.5
}
}
```
- `baseTheme` — fallback theme ID (`bright`, `dark`, `system`)
- `colors` — QPalette color role overrides (any role not specified falls back to base theme)
- `fadeColor` / `fadeAmount` — instance fade styling
#### themeStyle.css
Optional Qt stylesheet for fine-grained control:
```css
QMainWindow {
background-color: #1a1b26;
}
QToolBar {
background-color: #24283b;
border: none;
}
QPushButton {
background-color: #3d59a1;
color: #c0caf5;
border: 1px solid #565f89;
border-radius: 4px;
padding: 4px 12px;
}
QPushButton:hover {
background-color: #7aa2f7;
}
```
## ThemeManager
The central theme registry:
```cpp
class ThemeManager : public QObject
{
Q_OBJECT
public:
ThemeManager();
QList<ITheme*> getValidApplicationThemes();
ITheme* getTheme(const QString& themeId);
void applyCurrentlySelectedTheme(bool initial = false);
void setApplicationTheme(const QString& name, bool initial = false);
// Icon themes
void applyCurrentlySelectedIconTheme();
void setIconTheme(const QString& name);
QList<IconThemeEntry> getValidIconThemes();
// Cat packs
void setCatPack(const QString& name);
QList<CatPack*> getValidCatPacks();
CatPack* getCatPack(const QString& name);
private:
void initializeThemes();
void initializeIcons();
void initializeCatPacks();
QMap<QString, ITheme*> m_themes;
QMap<QString, IconThemeEntry> m_iconThemes;
QMap<QString, CatPack*> m_catPacks;
ITheme* m_currentTheme = nullptr;
};
```
### Initialization
On startup, `ThemeManager` discovers:
1. **Built-in themes**: System, Bright, Dark (always available)
2. **Custom themes**: Scans `themes/` directory for `theme.json` files, creates `CustomTheme` instances
3. **Icon themes**: Scans for icon theme directories
4. **Cat packs**: Scans for cat background packs
### Theme Application
```cpp
void ThemeManager::setApplicationTheme(const QString& name, bool initial)
{
auto theme = m_themes.value(name);
if (!theme)
theme = m_themes.value("system"); // Fallback
m_currentTheme = theme;
theme->apply(initial);
}
```
## Icon Theme System
### IconThemeEntry
```cpp
struct IconThemeEntry {
QString id;
QString name;
QString path;
};
```
### Built-in Icon Themes
| ID | Name | Description |
|---|---|---|
| `pe_colored` | PE Colored | Colorful flat icons (default) |
| `pe_dark` | PE Dark | Dark variant |
| `pe_light` | PE Light | Light variant |
| `pe_blue` | PE Blue | Blue-tinted variant |
| `OSX` | OSX | macOS-style icons |
| `iOS` | iOS | iOS-style icons |
| `flat` | Flat | Minimal flat icons |
| `flat_white` | Flat White | White flat icons |
| `multimc` | MultiMC | Classic MultiMC icons |
| `custom` | Custom | User-provided icons |
### Icon Resolution
Icons are resolved through Qt's resource system and theme hierarchy:
```cpp
// Standard icon lookup
QIcon::fromTheme("instances/creeper")
// Falls back through:
// 1. Current icon theme directory
// 2. Default (pe_colored) theme
// 3. Built-in Qt resources
```
### Custom Instance Icons
Users can set custom icons per-instance:
- Icons stored in `icons/` directory in the data path
- PNG, SVG, ICO formats supported
- `IconPickerDialog` provides selection UI
- Custom icons override theme icons
## CatPack System
CatPack provides the cat/background image shown in the main window:
```cpp
class CatPack {
public:
virtual ~CatPack() {}
virtual QString id() = 0;
virtual QString name() = 0;
virtual QDate startDate();
virtual QDate endDate();
virtual QString path();
};
```
### Built-in Cat Packs
- **kitteh** — Standard cat background
- **rory** — Rory the cat
Cat packs can have date ranges for seasonal variants.
### Custom Cat Packs
User-provided cat packs in `catpacks/`:
```
catpacks/my-cats/
├── catpack.json
└── images/
├── default.png
├── christmas.png # Dec 24 - Dec 26
└── halloween.png # Oct 31 - Nov 1
```
```json
{
"name": "My Cats",
"default": "images/default.png",
"variants": [
{
"startDate": "12-24",
"endDate": "12-26",
"path": "images/christmas.png"
}
]
}
```
## SVG Post-Processing
Themes can customize SVG icons at runtime:
```cpp
QString ITheme::postprocessSVG(QString svg)
{
// Replace placeholder colors in SVG with theme colors
svg.replace("%%BADGE_COLOR%%", badgeColor().name());
svg.replace("%%BADGE_TEXT%%", badgeTextColor().name());
return svg;
}
```
This allows icon badges (e.g., update counts, status indicators) to adapt to the current theme's color scheme.
## Theme Settings Integration
Theme selection is stored in global settings:
```cpp
// Settings registration (Application.cpp)
m_settings->registerSetting("ApplicationTheme", "system");
m_settings->registerSetting("IconTheme", "pe_colored");
m_settings->registerSetting("CatStyle", "kitteh");
```
The `AppearancePage` in global settings provides the UI for theme selection with live preview.
|