Loading...
Searching...
No Matches
Skin.hpp
1#pragma once
2#include <QBrush>
3#include <QCursor>
4#include <QFont>
5#include <QObject>
6#include <QPair>
7#include <QPalette>
8#include <QPen>
9#include <QSize>
10#include <QVector>
11
12#include <score_lib_base_export.h>
13
14#include <verdigris>
15
16#include <functional>
17#include <utility>
18#include <vector>
19class QJsonObject;
20namespace score
21{
22struct Brush;
23class Skin;
24struct SCORE_LIB_BASE_EXPORT BrushSet
25{
26 QBrush brush;
27 QPen pen_cosmetic;
28 QPen pen0;
29 QPen pen0_solid_round;
30 QPen pen1;
31 QPen pen1_dotted;
32 QPen pen1_solid_flat_miter;
33 QPen pen1_5;
34 QPen pen2;
35 QPen pen2_solid_round_round;
36 QPen pen2_solid_flat_miter;
37 QPen pen2_dashdot_square_miter;
38 QPen pen2_dotted_square_miter;
39 QPen pen3;
40 QPen pen3_solid_flat_miter;
41 QPen pen3_solid_round_round;
42 QPen pen3_dashed_flat_miter;
43
44 void setupPens();
45
46private:
47 BrushSet() noexcept;
48 BrushSet(const BrushSet&) noexcept;
49 BrushSet(BrushSet&&) noexcept;
50 BrushSet& operator=(const BrushSet&) noexcept;
51 BrushSet& operator=(BrushSet&&) noexcept;
52 ~BrushSet();
53
54 explicit BrushSet(const QBrush& b) noexcept;
55
56 BrushSet& operator=(const QBrush& b) noexcept;
57 friend struct Brush;
58 friend class Skin;
59};
60
61struct SCORE_LIB_BASE_EXPORT Brush
62{
63 operator const QBrush&() const noexcept { return main.brush; }
64 QColor color() const noexcept { return main.brush.color(); }
65
66 BrushSet main;
67 BrushSet darker;
68 BrushSet darker300;
69 BrushSet lighter;
70 BrushSet lighter180;
71
72 void reload(QColor color) noexcept;
73
74 struct Pair;
75
76private:
77 Brush() noexcept;
78 Brush(const Brush&) noexcept;
79 Brush(Brush&&) noexcept;
80 Brush& operator=(const Brush&) noexcept;
81 Brush& operator=(Brush&&) noexcept;
82 ~Brush();
83
84 explicit Brush(const QBrush& b) noexcept;
85 Brush& operator=(const QBrush& b) noexcept;
86
87 friend class Skin;
88};
90{
91 Pair(QString&& str, QColor&& c)
92 : first{std::move(str)}
93 , second{std::move(c)}
94 {
95 }
96 QString first;
97 Brush second;
98};
99class SCORE_LIB_BASE_EXPORT Skin : public QObject
100{
101 W_OBJECT(Skin)
102public:
103 static Skin& instance() noexcept;
104
108 static bool exists() noexcept;
109 ~Skin() override;
110
112 enum Part
113 {
114 Colours = 1,
115 Fonts = 2,
116 Everything = Colours | Fonts
117 };
118
119 void load(const QJsonObject& style, int parts = Everything);
120
123 QJsonObject toJson() const;
124
127 static QJsonObject merged(const QJsonObject& base, const QJsonObject& over);
128
131 static const std::vector<std::pair<const char*, QPalette::ColorRole>>&
132 paletteRoles() noexcept;
133
137 std::vector<std::pair<const char*, QFont*>> fonts() noexcept;
138
140 QFont ApplicationFont;
141
142 QFont SansFont;
143 QFont MonoFont;
144 QFont MonoFontSmall;
145 QFont SansFontSmall;
146
147 QFont Bold10Pt;
148 QFont Bold12Pt;
149 QFont Medium7Pt;
150 QFont Medium8Pt;
151 QFont Medium10Pt;
152 QFont Medium12Pt;
153
154 QFont TitleFont;
155
158 QFont SectionTitleFont;
159
162 QFont TimecodeFont;
163
166 QFont RulerFont;
167
169 QFont CodeFont;
170
171 Brush Dark;
172 Brush HalfDark;
173 Brush DarkGray;
174 Brush Gray;
175 Brush LightGray;
176 Brush HalfLight;
177 Brush Light;
178
179 Brush Emphasis1;
180 Brush Emphasis2;
181 Brush Emphasis3;
182 Brush Emphasis4;
183 Brush Emphasis5;
184
185 Brush Base1;
186 Brush Base2;
187 Brush Base3;
188 Brush Base4;
189 Brush Base5;
190
191 Brush Warn1;
192 Brush Warn2;
193 Brush Warn3;
194
195 Brush Background1;
196 Brush Background2;
197
198 Brush Transparent1;
199 Brush Transparent2;
200 Brush Transparent3;
201
202 Brush Smooth1;
203 Brush Smooth2;
204 Brush Smooth3;
205
206 Brush Tender1;
207 Brush Tender2;
208 Brush Tender3;
209
210 Brush Cable1;
211 Brush Cable2;
212 Brush Cable3;
213 Brush Cable4;
214 Brush Cable5;
215
216 Brush SelectedCable1;
217 Brush SelectedCable2;
218 Brush SelectedCable3;
219 Brush SelectedCable4;
220 Brush SelectedCable5;
221
224 Brush Port1;
225 Brush Port2;
226 Brush Port3;
227 Brush Port4;
228 Brush Port5;
229
230 Brush Pulse1;
231 Brush Pulse2;
232
234 Brush Waveform1;
235 Brush Waveform2;
236
243 QPalette WidgetPalette;
244
245 const QPen TransparentPen;
246 const QBrush TransparentBrush;
247 const QPen NoPen;
248 const QBrush NoBrush;
249 QBrush TextBrush;
250
251 QPen TextItemPen;
252
253 QBrush SliderBrush;
254 QPen SliderPen;
255 QBrush SliderInteriorBrush;
256 QPen SliderLine;
257 QPen SliderTextPen;
258 QFont SliderFont;
259
260 QCursor CursorPointer;
261 QCursor CursorOpenHand;
262 QCursor CursorClosedHand;
263 QCursor CursorPointingHand;
264 QCursor CursorMagnifier;
265 QCursor CursorMove;
266 QCursor CursorScaleH;
267 QCursor CursorScaleV;
268 QCursor CursorScaleFDiag;
269 QCursor CursorSpin;
270
271 QCursor CursorPlayFromHere;
272 QCursor CursorCreationMode;
273
274 const Brush* fromString(const QString& s) const;
275 Brush* fromString(const QString& s);
276 QString toString(const Brush*) const;
277
278 QVector<QPair<QColor, QString>> getColors() const;
279 QVector<QPair<QColor, QString>> getDefaultPaletteColors() const;
280
281 // In [0; 25[
282 int PulseIndex{};
283
284 int LoadIndex{};
285
286public:
287 void changed() E_SIGNAL(SCORE_LIB_BASE_EXPORT, changed)
288
289private:
290 void timerEvent(QTimerEvent* event) override;
291 Skin() noexcept;
292
293 struct NoGUI
294 {
295 };
296 explicit Skin(NoGUI);
297
300 void setupFonts();
301
303 void loadFonts(const QJsonObject& spec_obj);
304
306 QJsonObject saveFonts() const;
307
310 void setupPalette();
311
314 void setupColors();
315
317 void fixupColors();
318
320 void loadPalette(const QJsonObject& spec);
321
323 QJsonObject savePalette() const;
324
328 QVector<QPair<QColor, QString>> m_builtinColours;
329
332 QPalette m_basePalette;
333
334 struct color_map;
335 color_map* initColorMap() noexcept;
336 color_map* m_colorMap{};
337 std::vector<Brush::Pair> m_defaultPalette;
338
339 bool m_pulseDirection{false};
340};
341
344SCORE_LIB_BASE_EXPORT int uiFontSize() noexcept;
345
348inline constexpr int referenceFontSize = 13;
349
351SCORE_LIB_BASE_EXPORT double fontScale() noexcept;
352
355SCORE_LIB_BASE_EXPORT int scaledPixels(int px) noexcept;
356
358SCORE_LIB_BASE_EXPORT QSize scaledIcon(int px) noexcept;
359
367SCORE_LIB_BASE_EXPORT void applyDefaultPalette(QPalette& p);
368
369SCORE_LIB_BASE_EXPORT void onSkinChange(QObject* owner, std::function<void()> f);
370
372template <typename T>
373void setSkinIconSize(T* widget, int px)
374{
375 onSkinChange(widget, [widget, px] { widget->setIconSize(scaledIcon(px)); });
376}
377
380SCORE_LIB_BASE_EXPORT QFont::HintingPreference uiFontHinting() noexcept;
381
384SCORE_LIB_BASE_EXPORT QFont::StyleStrategy uiFontStyleStrategy() noexcept;
385
388SCORE_LIB_BASE_EXPORT int pixelFontGrid(const QString& family) noexcept;
389
393SCORE_LIB_BASE_EXPORT int snapToFontGrid(const QFont& f, int px) noexcept;
394
396SCORE_LIB_BASE_EXPORT void setSnappedPixelSize(QFont& f, int px) noexcept;
397
400SCORE_LIB_BASE_EXPORT void registerApplicationFonts();
401
404SCORE_LIB_BASE_EXPORT QFont defaultApplicationFont() noexcept;
405
409SCORE_LIB_BASE_EXPORT bool canSetGlobalScaleFactorLive() noexcept;
410
415SCORE_LIB_BASE_EXPORT bool setGlobalScaleFactor(double factor);
416
420SCORE_LIB_BASE_EXPORT void setupApplicationFont(const QFont& f);
421
422}
Definition Skin.hpp:100
Part
Which halves of a skin file to apply.
Definition Skin.hpp:113
Base toolkit upon which the software is built.
Definition Application.cpp:83
int pixelFontGrid(const QString &family) noexcept
Definition Skin.cpp:145
bool canSetGlobalScaleFactorLive() noexcept
Definition Skin.cpp:225
int uiFontSize() noexcept
Definition Skin.cpp:72
constexpr int referenceFontSize
Definition Skin.hpp:348
bool setGlobalScaleFactor(double factor)
Definition Skin.cpp:234
void setSkinIconSize(T *widget, int px)
onSkinChange(widget, setIconSize(scaledIcon(px))).
Definition Skin.hpp:373
double fontScale() noexcept
Current application font size over referenceFontSize.
Definition Skin.cpp:81
QFont::HintingPreference uiFontHinting() noexcept
Definition Skin.cpp:123
void setSnappedPixelSize(QFont &f, int px) noexcept
setPixelSize through snapToFontGrid.
Definition Skin.cpp:188
void registerApplicationFonts()
Definition Skin.cpp:193
QFont defaultApplicationFont() noexcept
Definition Skin.cpp:214
QSize scaledIcon(int px) noexcept
scaledPixels() as a square.
Definition Skin.cpp:100
int snapToFontGrid(const QFont &f, int px) noexcept
Definition Skin.cpp:174
QFont::StyleStrategy uiFontStyleStrategy() noexcept
Definition Skin.cpp:128
void applyDefaultPalette(QPalette &p)
Definition Skin.cpp:451
int scaledPixels(int px) noexcept
Definition Skin.cpp:95
STL namespace.
Definition Skin.hpp:90
Definition Skin.hpp:62
Definition Skin.hpp:25