Fluid
Loading...
Searching...
No Matches
style.h
Go to the documentation of this file.
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2025 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#pragma once
16
17#include <QColor>
18#include <QtQml/QQmlEngine>
19#include <QtQuickControls2/QQuickAttachedPropertyPropagator>
20
21class Style : public QQuickAttachedPropertyPropagator
22{
23 Q_OBJECT
24 Q_DISABLE_COPY(Style)
25
26 Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL)
27 Q_PROPERTY(int elevation READ elevation WRITE setElevation RESET resetElevation NOTIFY
28 elevationChanged FINAL)
29
30 // Fonts
31 Q_PROPERTY(QString brandFontFamily READ brandFontFamily CONSTANT FINAL)
32 Q_PROPERTY(QString plainFontFamily READ plainFontFamily CONSTANT FINAL)
33
34 // Color properties - Primary
35 Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY themeChanged FINAL)
36 Q_PROPERTY(QColor onPrimaryColor READ onPrimaryColor NOTIFY themeChanged FINAL)
37 Q_PROPERTY(QColor primaryContainerColor READ primaryContainerColor NOTIFY themeChanged FINAL)
38 Q_PROPERTY(
40 Q_PROPERTY(QColor primaryFixedColor READ primaryFixedColor NOTIFY themeChanged FINAL)
41 Q_PROPERTY(QColor primaryFixedDimColor READ primaryFixedDimColor NOTIFY themeChanged FINAL)
42 Q_PROPERTY(QColor onPrimaryFixedColor READ onPrimaryFixedColor NOTIFY themeChanged FINAL)
44 FINAL)
45
46 // Color properties - Secondary
47 Q_PROPERTY(QColor secondaryColor READ secondaryColor NOTIFY themeChanged FINAL)
48 Q_PROPERTY(QColor onSecondaryColor READ onSecondaryColor NOTIFY themeChanged FINAL)
49 Q_PROPERTY(
52 FINAL)
53
54 // Color properties - Tertiary
55 Q_PROPERTY(QColor tertiaryColor READ tertiaryColor NOTIFY themeChanged FINAL)
56 Q_PROPERTY(QColor onTertiaryColor READ onTertiaryColor NOTIFY themeChanged FINAL)
57 Q_PROPERTY(QColor tertiaryContainerColor READ tertiaryContainerColor NOTIFY themeChanged FINAL)
58 Q_PROPERTY(
60
61 // Color properties - Error
62 Q_PROPERTY(QColor errorColor READ errorColor NOTIFY themeChanged FINAL)
63 Q_PROPERTY(QColor onErrorColor READ onErrorColor NOTIFY themeChanged FINAL)
64 Q_PROPERTY(QColor errorContainerColor READ errorContainerColor NOTIFY themeChanged FINAL)
65 Q_PROPERTY(QColor onErrorContainerColor READ onErrorContainerColor NOTIFY themeChanged FINAL)
66
67 // Color properties - Background
68 Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY themeChanged FINAL)
69 Q_PROPERTY(QColor onBackgroundColor READ onBackgroundColor NOTIFY themeChanged FINAL)
70
71 // Color properties - Surface
72 Q_PROPERTY(QColor surfaceColor READ surfaceColor NOTIFY themeChanged FINAL)
73 Q_PROPERTY(QColor onSurfaceColor READ onSurfaceColor NOTIFY themeChanged FINAL)
74 Q_PROPERTY(QColor surfaceBrightColor READ surfaceBrightColor NOTIFY themeChanged FINAL)
75 Q_PROPERTY(QColor surfaceDimColor READ surfaceDimColor NOTIFY themeChanged FINAL)
76 Q_PROPERTY(QColor surfaceVariantColor READ surfaceVariantColor NOTIFY themeChanged FINAL)
77 Q_PROPERTY(QColor onSurfaceVariantColor READ onSurfaceVariantColor NOTIFY themeChanged FINAL)
79 themeChanged FINAL)
80 Q_PROPERTY(
82 Q_PROPERTY(QColor surfaceContainerColor READ surfaceContainerColor NOTIFY themeChanged FINAL)
84 FINAL)
86 themeChanged FINAL)
87
88 // Color properties - Outline
89 Q_PROPERTY(QColor outlineColor READ outlineColor NOTIFY themeChanged FINAL)
90 Q_PROPERTY(QColor outlineVariantColor READ outlineVariantColor NOTIFY themeChanged FINAL)
91
92 // Color properties - Inverse
93 Q_PROPERTY(QColor inverseSurfaceColor READ inverseSurfaceColor NOTIFY themeChanged FINAL)
94 Q_PROPERTY(QColor inverseOnSurfaceColor READ inverseOnSurfaceColor NOTIFY themeChanged FINAL)
95 Q_PROPERTY(QColor inversePrimaryColor READ inversePrimaryColor NOTIFY themeChanged FINAL)
96
97 // Color properties - Scrim
98 Q_PROPERTY(QColor scrimColor READ scrimColor NOTIFY themeChanged FINAL)
99
100 // Color properties - Shadow
101 Q_PROPERTY(QColor shadowColor READ shadowColor NOTIFY themeChanged FINAL)
102
103 QML_NAMED_ELEMENT(Style)
104 QML_ATTACHED(Style)
105 QML_UNCREATABLE("")
106 QML_ADDED_IN_VERSION(2, 0)
107public:
113 Q_ENUM(Theme)
114
115 enum class TypeFace {
116 Brand,
117 Plain
118 };
119 Q_ENUM(TypeFace)
120
121 explicit Style(QObject *parent = nullptr);
122
123 Theme theme() const;
124 void setTheme(Theme theme);
125 void resetTheme();
126
127 int elevation() const;
128 void setElevation(int elevation);
129 void resetElevation();
130
131 // Font getters
132 QString brandFontFamily() const;
133 QString plainFontFamily() const;
134
135 // Color getters - Primary
136 QColor primaryColor() const;
137 QColor onPrimaryColor() const;
138 QColor primaryContainerColor() const;
139 QColor onPrimaryContainerColor() const;
140 QColor primaryFixedColor() const;
141 QColor primaryFixedDimColor() const;
142 QColor onPrimaryFixedColor() const;
143 QColor onPrimaryFixedVariantColor() const;
144
145 // Color getters - Secondary
146 QColor secondaryColor() const;
147 QColor onSecondaryColor() const;
148 QColor secondaryContainerColor() const;
149 QColor onSecondaryContainerColor() const;
150
151 // Color getters - Tertiary
152 QColor tertiaryColor() const;
153 QColor onTertiaryColor() const;
154 QColor tertiaryContainerColor() const;
155 QColor onTertiaryContainerColor() const;
156
157 // Color getters - Error
158 QColor errorColor() const;
159 QColor onErrorColor() const;
160 QColor errorContainerColor() const;
161 QColor onErrorContainerColor() const;
162
163 // Color getters - Background
164 QColor backgroundColor() const;
165 QColor onBackgroundColor() const;
166
167 // Color getters - Surface
168 QColor surfaceColor() const;
169 QColor onSurfaceColor() const;
170 QColor surfaceBrightColor() const;
171 QColor surfaceDimColor() const;
172 QColor surfaceVariantColor() const;
173 QColor onSurfaceVariantColor() const;
174 QColor surfaceContainerLowestColor() const;
175 QColor surfaceContainerLowColor() const;
176 QColor surfaceContainerColor() const;
177 QColor surfaceContainerHighColor() const;
178 QColor surfaceContainerHighestColor() const;
179
180 // Color getters - Outline
181 QColor outlineColor() const;
182 QColor outlineVariantColor() const;
183
184 // Color getters - Inverse
185 QColor inverseSurfaceColor() const;
186 QColor inverseOnSurfaceColor() const;
187 QColor inversePrimaryColor() const;
188
189 // Color getters - Scrim
190 QColor scrimColor() const;
191
192 // Color getters - Shadow
193 QColor shadowColor() const;
194
195 static Style *qmlAttachedProperties(QObject *object);
196
197 static bool isDarkSystemTheme();
199
200Q_SIGNALS:
203
204protected:
205 void attachedParentChange(QQuickAttachedPropertyPropagator *newParent,
206 QQuickAttachedPropertyPropagator *oldParent) override;
207
208private:
209 // Whether a particular setting was explicitly set on this instance
210 bool m_explicitTheme = false;
211
212 // Actual property values
213 bool m_systemTheme = false;
214 Style::Theme m_theme = Style::Light;
215 int m_elevation = 0;
216
217 void inheritTheme(Style::Theme theme);
218 void propagateTheme();
219};
Definition style.h:22
QColor surfaceContainerLowColor
Definition style.h:81
QColor outlineVariantColor
Definition style.h:90
QColor surfaceContainerHighColor
Definition style.h:84
QColor surfaceContainerLowestColor
Definition style.h:79
TypeFace
Definition style.h:115
void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override
Definition style.cpp:357
void setTheme(Theme theme)
Definition style.cpp:43
QColor tertiaryContainerColor
Definition style.h:57
QColor errorContainerColor
Definition style.h:64
QColor onSurfaceColor
Definition style.h:73
QColor onPrimaryFixedColor
Definition style.h:42
QColor surfaceVariantColor
Definition style.h:76
QColor onSurfaceVariantColor
Definition style.h:77
Theme theme
Definition style.h:26
static Style * qmlAttachedProperties(QObject *object)
Definition style.cpp:352
QColor scrimColor
Definition style.h:98
int elevation
Definition style.h:28
QColor onSecondaryContainerColor
Definition style.h:52
QColor surfaceColor
Definition style.h:72
QColor onPrimaryFixedVariantColor
Definition style.h:44
QColor errorColor
Definition style.h:62
void elevationChanged()
QColor inversePrimaryColor
Definition style.h:95
QColor onSecondaryColor
Definition style.h:48
void themeChanged()
QColor inverseSurfaceColor
Definition style.h:93
QColor tertiaryColor
Definition style.h:55
QColor primaryFixedDimColor
Definition style.h:41
Theme
Definition style.h:108
@ System
Definition style.h:111
@ Light
Definition style.h:109
@ Dark
Definition style.h:110
QColor onPrimaryContainerColor
Definition style.h:39
void resetTheme()
Definition style.cpp:61
QColor secondaryContainerColor
Definition style.h:50
QString plainFontFamily
Definition style.h:32
QColor onBackgroundColor
Definition style.h:69
QColor onErrorContainerColor
Definition style.h:65
QColor outlineColor
Definition style.h:89
static Theme effectiveTheme(Theme theme)
Definition style.cpp:379
QColor backgroundColor
Definition style.h:68
void setElevation(int elevation)
Definition style.cpp:77
QColor secondaryColor
Definition style.h:47
QColor onTertiaryContainerColor
Definition style.h:59
QColor onTertiaryColor
Definition style.h:56
QColor surfaceDimColor
Definition style.h:75
QString brandFontFamily
Definition style.h:31
QColor surfaceContainerHighestColor
Definition style.h:86
QColor inverseOnSurfaceColor
Definition style.h:94
QColor surfaceContainerColor
Definition style.h:82
void resetElevation()
Definition style.cpp:85
static bool isDarkSystemTheme()
Definition style.cpp:368
QColor surfaceBrightColor
Definition style.h:74
QColor onPrimaryColor
Definition style.h:36
QColor shadowColor
Definition style.h:101
QColor primaryContainerColor
Definition style.h:37
QColor onErrorColor
Definition style.h:63
QColor primaryFixedColor
Definition style.h:40
QColor primaryColor
Definition style.h:35
Definition theme.h:9