Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickmaterialstyle_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKMATERIALSTYLE_P_H
5#define QQUICKMATERIALSTYLE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/qcolor.h>
19#include <QtQml/qqml.h>
20#include <QtQuickControls2/qquickattachedpropertypropagator.h>
21
23
25{
27 Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL)
34 NOTIFY roundedScaleChanged FINAL)
36 NOTIFY containerStyleChanged FINAL)
37
38 Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY primaryChanged FINAL) // TODO: remove?
39 Q_PROPERTY(QColor accentColor READ accentColor NOTIFY accentChanged FINAL) // TODO: remove?
77
78 Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL)
79 Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL)
80 Q_PROPERTY(int delegateHeight READ delegateHeight CONSTANT FINAL)
83 Q_PROPERTY(int menuItemHeight READ menuItemHeight CONSTANT FINAL)
86 Q_PROPERTY(int textFieldHeight READ textFieldHeight CONSTANT FINAL)
89 Q_PROPERTY(int tooltipHeight READ tooltipHeight CONSTANT FINAL)
90
91 QML_NAMED_ELEMENT(Material)
95
96public:
97 enum Theme {
100 System
101 };
102
103 enum Variant {
105 Dense
106 };
107
108 enum Color {
128 };
129
130 enum Shade {
145 };
146
147 enum class RoundedScale {
149 ExtraSmallScale = 4,
150 SmallScale = 8,
151 MediumScale = 12,
152 LargeScale = 16,
153 ExtraLargeScale = 28,
154 FullScale = 0xFF // For full we use half the height of the item.
155 };
156
157 enum class ContainerStyle {
158 Filled,
160 };
161
168
169 explicit QQuickMaterialStyle(QObject *parent = nullptr);
170
172
173 Theme theme() const;
174 void setTheme(Theme theme);
176 void propagateTheme();
177 void resetTheme();
178 void themeChange();
179
180 QVariant primary() const;
181 void setPrimary(const QVariant &accent);
182 void inheritPrimary(uint primary, bool custom);
183 void propagatePrimary();
184 void resetPrimary();
185 void primaryChange();
186
187 QVariant accent() const;
188 void setAccent(const QVariant &accent);
189 void inheritAccent(uint accent, bool custom);
190 void propagateAccent();
191 void resetAccent();
192 void accentChange();
193
194 QVariant foreground() const;
195 void setForeground(const QVariant &foreground);
196 void inheritForeground(uint foreground, bool custom, bool has);
197 void propagateForeground();
198 void resetForeground();
199 void foregroundChange();
200
201 QVariant background() const;
202 void setBackground(const QVariant &background);
203 void inheritBackground(uint background, bool custom, bool has);
204 void propagateBackground();
205 void resetBackground();
206 void backgroundChange();
207
208 int elevation() const;
209 void setElevation(int elevation);
210 void resetElevation();
211 void elevationChange();
212
215 void resetRoundedScale();
216
219 void resetContainerStyle();
220
221 QColor primaryColor() const;
222 QColor accentColor() const;
223 QColor backgroundColor() const;
224 QColor primaryTextColor() const;
227 QColor hintTextColor() const;
229 QColor dropShadowColor() const;
230 QColor dividerColor() const;
231 QColor iconColor() const;
234 bool enabled, bool flat, bool highlighted, bool checked) const;
235 QColor frameColor() const;
236 QColor rippleColor() const;
250 QColor scrollBarColor() const;
253 QColor dialogColor() const;
256 QColor tooltipColor() const;
257 QColor toolBarColor() const;
258 QColor toolTextColor() const;
262
265
266 int touchTarget() const;
267 int buttonHeight() const;
268 int delegateHeight() const;
269 int dialogButtonBoxHeight() const;
270 int frameVerticalPadding() const;
271 int menuItemHeight() const;
272 int menuItemVerticalPadding() const;
274 int textFieldHeight() const;
275 int textFieldHorizontalPadding() const;
276 int textFieldVerticalPadding() const;
277 int tooltipHeight() const;
278
279 static void initGlobals();
280
281 static Variant variant();
282
290
292
300
301protected:
303
304private:
305 void init();
306 bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const;
307
310
311 Shade themeShade() const;
312
313 // These reflect whether a color value was explicitly set on the specific
314 // item that this attached style object represents.
315 bool m_explicitTheme = false;
316 bool m_explicitPrimary = false;
317 bool m_explicitAccent = false;
318 bool m_explicitForeground = false;
319 bool m_explicitBackground = false;
320 // These reflect whether the color value that was either inherited or
321 // explicitly set is in the form that QColor expects, rather than one of
322 // our pre-defined color enum values.
323 bool m_customPrimary = false;
324 bool m_customAccent = false;
325 bool m_customForeground = false;
326 bool m_customBackground = false;
327 // These will be true when this item has an explicit or inherited foreground/background
328 // color, or these colors were declared globally via settings (e.g. conf or env vars).
329 // Some color properties of the style will return different values depending on whether
330 // or not these are set.
331 bool m_hasForeground = false;
332 bool m_hasBackground = false;
333 // The actual values for this item, whether explicit, inherited or globally set.
334 Theme m_theme = Light;
335 uint m_primary = 0;
336 uint m_accent = 0;
337 uint m_foreground = 0;
338 uint m_background = 0;
339 int m_elevation = 0;
340 RoundedScale m_roundedScale = RoundedScale::NotRounded;
341 ContainerStyle m_containerStyle = ContainerStyle::Filled;
342};
343
345
346#endif // QQUICKMATERIALSTYLE_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
The QQuickAttachedPropertyPropagator class provides a way to propagate attached properties.
void inheritAccent(uint accent, bool custom)
void setContainerStyle(ContainerStyle containerStyle)
void primaryHighlightedTextColorChanged()
void inheritForeground(uint foreground, bool custom, bool has)
Q_INVOKABLE QColor buttonColor(Theme theme, const QVariant &background, const QVariant &accent, bool enabled, bool flat, bool highlighted, bool checked) const
void inheritBackground(uint background, bool custom, bool has)
void setElevation(int elevation)
void setBackground(const QVariant &background)
void inheritTheme(Theme theme)
Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const
void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override
This function is called whenever the attached parent of this QQuickAttachedPropertyPropagator changes...
void inheritPrimary(uint primary, bool custom)
void containerStyleChanged()
void setAccent(const QVariant &accent)
void setPrimary(const QVariant &accent)
static QQuickMaterialStyle * qmlAttachedProperties(QObject *object)
void setRoundedScale(RoundedScale roundedScale)
\inmodule QtCore
Definition qvariant.h:64
Combined button and popup list for selecting options.
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLuint name
#define QML_UNCREATABLE(REASON)
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QML_ATTACHED(ATTACHED_TYPE)
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName setForeground
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SIGNALS
unsigned int uint
Definition qtypes.h:29