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 // Color properties - Primary
31 Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY themeChanged FINAL)
32 Q_PROPERTY(QColor onPrimaryColor READ onPrimaryColor NOTIFY themeChanged FINAL)
33 Q_PROPERTY(QColor primaryContainerColor READ primaryContainerColor NOTIFY themeChanged FINAL)
34 Q_PROPERTY(
36
37 // Color properties - Secondary
38 Q_PROPERTY(QColor secondaryColor READ secondaryColor NOTIFY themeChanged FINAL)
39 Q_PROPERTY(QColor onSecondaryColor READ onSecondaryColor NOTIFY themeChanged FINAL)
40 Q_PROPERTY(
43 FINAL)
44
45 // Color properties - Tertiary
46 Q_PROPERTY(QColor tertiaryColor READ tertiaryColor NOTIFY themeChanged FINAL)
47 Q_PROPERTY(QColor onTertiaryColor READ onTertiaryColor NOTIFY themeChanged FINAL)
48 Q_PROPERTY(QColor tertiaryContainerColor READ tertiaryContainerColor NOTIFY themeChanged FINAL)
49 Q_PROPERTY(
51
52 // Color properties - Error
53 Q_PROPERTY(QColor errorColor READ errorColor NOTIFY themeChanged FINAL)
54 Q_PROPERTY(QColor onErrorColor READ onErrorColor NOTIFY themeChanged FINAL)
55 Q_PROPERTY(QColor errorContainerColor READ errorContainerColor NOTIFY themeChanged FINAL)
56 Q_PROPERTY(QColor onErrorContainerColor READ onErrorContainerColor NOTIFY themeChanged FINAL)
57
58 // Color properties - Background
59 Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY themeChanged FINAL)
60 Q_PROPERTY(QColor onBackgroundColor READ onBackgroundColor NOTIFY themeChanged FINAL)
61
62 // Color properties - Surface
63 Q_PROPERTY(QColor surfaceColor READ surfaceColor NOTIFY themeChanged FINAL)
64 Q_PROPERTY(QColor onSurfaceColor READ onSurfaceColor NOTIFY themeChanged FINAL)
65 Q_PROPERTY(QColor surfaceVariantColor READ surfaceVariantColor NOTIFY themeChanged FINAL)
66 Q_PROPERTY(QColor onSurfaceVariantColor READ onSurfaceVariantColor NOTIFY themeChanged FINAL)
67 Q_PROPERTY(QColor surfaceTintColor READ surfaceTintColor NOTIFY themeChanged FINAL)
68
69 // Color properties - Outline
70 Q_PROPERTY(QColor outlineColor READ outlineColor NOTIFY themeChanged FINAL)
71 Q_PROPERTY(QColor outlineVariantColor READ outlineVariantColor NOTIFY themeChanged FINAL)
72
73 // Color properties - Inverse
74 Q_PROPERTY(QColor inverseSurfaceColor READ inverseSurfaceColor NOTIFY themeChanged FINAL)
75 Q_PROPERTY(QColor inverseOnSurfaceColor READ inverseOnSurfaceColor NOTIFY themeChanged FINAL)
76 Q_PROPERTY(QColor inversePrimaryColor READ inversePrimaryColor NOTIFY themeChanged FINAL)
77
78 // Color properties - Scrim
79 Q_PROPERTY(QColor scrimColor READ scrimColor NOTIFY themeChanged FINAL)
80
81 // Color properties - Shadow
82 Q_PROPERTY(QColor shadowColor READ shadowColor NOTIFY themeChanged FINAL)
83
84 QML_NAMED_ELEMENT(Style)
85 QML_ATTACHED(Style)
86 QML_UNCREATABLE("")
87 QML_ADDED_IN_VERSION(2, 0)
88public:
94 Q_ENUM(Theme)
95
96 explicit Style(QObject *parent = nullptr);
97
98 Theme theme() const;
99 void setTheme(Theme theme);
100 void resetTheme();
101
102 int elevation() const;
103 void setElevation(int elevation);
104 void resetElevation();
105
106 // Color getters - Primary
107 QColor primaryColor() const;
108 QColor onPrimaryColor() const;
109 QColor primaryContainerColor() const;
110 QColor onPrimaryContainerColor() const;
111
112 // Color getters - Secondary
113 QColor secondaryColor() const;
114 QColor onSecondaryColor() const;
115 QColor secondaryContainerColor() const;
116 QColor onSecondaryContainerColor() const;
117
118 // Color getters - Tertiary
119 QColor tertiaryColor() const;
120 QColor onTertiaryColor() const;
121 QColor tertiaryContainerColor() const;
122 QColor onTertiaryContainerColor() const;
123
124 // Color getters - Error
125 QColor errorColor() const;
126 QColor onErrorColor() const;
127 QColor errorContainerColor() const;
128 QColor onErrorContainerColor() const;
129
130 // Color getters - Background
131 QColor backgroundColor() const;
132 QColor onBackgroundColor() const;
133
134 // Color getters - Surface
135 QColor surfaceColor() const;
136 QColor onSurfaceColor() const;
137 QColor surfaceVariantColor() const;
138 QColor onSurfaceVariantColor() const;
139 QColor surfaceTintColor() const;
140
141 // Color getters - Outline
142 QColor outlineColor() const;
143 QColor outlineVariantColor() const;
144
145 // Color getters - Inverse
146 QColor inverseSurfaceColor() const;
147 QColor inverseOnSurfaceColor() const;
148 QColor inversePrimaryColor() const;
149
150 // Color getters - Scrim
151 QColor scrimColor() const;
152
153 // Color getters - Shadow
154 QColor shadowColor() const;
155
156 static Style *qmlAttachedProperties(QObject *object);
157
158 static bool isDarkSystemTheme();
160
161Q_SIGNALS:
164
165protected:
166 void attachedParentChange(QQuickAttachedPropertyPropagator *newParent,
167 QQuickAttachedPropertyPropagator *oldParent) override;
168
169private:
170 // Whether a particular setting was explicitly set on this instance
171 bool m_explicitTheme = false;
172
173 // Actual property values
174 bool m_systemTheme = false;
175 Style::Theme m_theme = Style::Light;
176 int m_elevation = 0;
177
178 void inheritTheme(Style::Theme theme);
179 void propagateTheme();
180};
Definition style.h:22
QColor outlineVariantColor
Definition style.h:71
void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override
Definition style.cpp:252
void setTheme(Theme theme)
Definition style.cpp:40
QColor tertiaryContainerColor
Definition style.h:48
QColor errorContainerColor
Definition style.h:55
QColor onSurfaceColor
Definition style.h:64
QColor surfaceTintColor
Definition style.h:67
QColor surfaceVariantColor
Definition style.h:65
QColor onSurfaceVariantColor
Definition style.h:66
Theme theme
Definition style.h:26
static Style * qmlAttachedProperties(QObject *object)
Definition style.cpp:247
QColor scrimColor
Definition style.h:79
int elevation
Definition style.h:28
QColor onSecondaryContainerColor
Definition style.h:43
QColor surfaceColor
Definition style.h:63
QColor errorColor
Definition style.h:53
void elevationChanged()
QColor inversePrimaryColor
Definition style.h:76
QColor onSecondaryColor
Definition style.h:39
void themeChanged()
QColor inverseSurfaceColor
Definition style.h:74
QColor tertiaryColor
Definition style.h:46
Theme
Definition style.h:89
@ System
Definition style.h:92
@ Light
Definition style.h:90
@ Dark
Definition style.h:91
QColor onPrimaryContainerColor
Definition style.h:35
void resetTheme()
Definition style.cpp:58
QColor secondaryContainerColor
Definition style.h:41
QColor onBackgroundColor
Definition style.h:60
QColor onErrorContainerColor
Definition style.h:56
QColor outlineColor
Definition style.h:70
static Theme effectiveTheme(Theme theme)
Definition style.cpp:274
QColor backgroundColor
Definition style.h:59
void setElevation(int elevation)
Definition style.cpp:74
QColor secondaryColor
Definition style.h:38
QColor onTertiaryContainerColor
Definition style.h:50
QColor onTertiaryColor
Definition style.h:47
QColor inverseOnSurfaceColor
Definition style.h:75
void resetElevation()
Definition style.cpp:82
static bool isDarkSystemTheme()
Definition style.cpp:263
QColor onPrimaryColor
Definition style.h:32
QColor shadowColor
Definition style.h:82
QColor primaryContainerColor
Definition style.h:33
QColor onErrorColor
Definition style.h:54
QColor primaryColor
Definition style.h:31