Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqstylekitreader_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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// Qt-Security score:significant reason:default
4
5#ifndef QQSTYLEKITREADER_P_H
6#define QQSTYLEKITREADER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQml/QtQml>
20#include <QtQuick/private/qquickpalette_p.h>
21
25
26#include <QtCore/qcompare.h>
27
29
30class QQuickPalette;
33
34class Q_LABSSTYLEKIT_EXPORT QQStyleKitReader : public QQStyleKitControlProperties
35{
36 Q_OBJECT
37 Q_PROPERTY(QQStyleKitExtendableControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged FINAL)
38 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
39 Q_PROPERTY(bool focused READ focused WRITE setFocused NOTIFY focusedChanged FINAL)
40 Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged FINAL)
41 Q_PROPERTY(bool hovered READ hovered WRITE setHovered NOTIFY hoveredChanged FINAL)
42 Q_PROPERTY(bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL)
43 Q_PROPERTY(bool vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL)
44 Q_PROPERTY(bool highlighted READ highlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL)
45 Q_PROPERTY(QFont font READ font NOTIFY fontChanged FINAL)
46 Q_PROPERTY(QQuickPalette *palette READ palette WRITE setPalette NOTIFY paletteChanged FINAL)
47 Q_PROPERTY(QQStyleKitControlProperties *global READ global CONSTANT FINAL)
48
49 QML_NAMED_ELEMENT(StyleReader)
50
51public:
52 enum ControlType {
53 Unspecified = 100000,
54 Control,
55 AbstractButton,
56 ApplicationWindow,
57 Button,
58 CheckBox,
59 ComboBox,
60 FlatButton,
61 ProgressBar,
62 ScrollBar,
63 ScrollIndicator,
64 ScrollView,
65 Slider,
66 SpinBox,
67 SwitchControl,
68 SearchField,
69 TabBar,
70 TabButton,
71 TextArea,
72 TextField,
73 TextInput,
74 ToolBar,
75 ToolButton,
76 ToolSeparator,
77 RadioButton,
78 ItemDelegate,
79 Popup,
80 Menu,
81 Dialog,
82 Pane,
83 Page,
84 Frame,
85 Label,
86 GroupBox
87 };
88 Q_ENUM(ControlType)
89
90 enum class AlternateState {
91 Alternate1,
92 Alternate2
93 };
94 Q_ENUM(AlternateState)
95
96 QQStyleKitReader(QObject *parent = nullptr);
97 ~QQStyleKitReader();
98
99 QQStyleKitExtendableControlType controlType() const;
100 void setControlType(QQStyleKitExtendableControlType type);
101#ifdef QT_DEBUG
102 ControlType typeAsControlType() const;
103#endif
104
105 bool hovered() const;
106 void setHovered(bool hovered);
107
108 bool enabled() const;
109 void setEnabled(bool enabled);
110
111 bool focused() const;
112 void setFocused(bool focused);
113
114 bool checked() const;
115 void setChecked(bool checked);
116
117 bool pressed() const;
118 void setPressed(bool pressed);
119
120 QQuickPalette *palette() const;
121 void setPalette(QQuickPalette *palette);
122 QPalette effectivePalette() const;
123
124 bool vertical() const;
125 void setVertical(bool vertical);
126
127 bool highlighted() const;
128 void setHighlighted(bool highlighted);
129
130 QQStyleKitStyle *explicitStyle() const;
131 void setExplicitStyle(QQStyleKitStyle *style);
132
133 QFont font() const;
134
135 QQStyleKitControlProperties *global() const;
136
137 QVariant readStyleProperty(PropertyStorageId key) const;
138 void writeStyleProperty(PropertyStorageId key, const QVariant &value);
139 void clearLocalStorage();
140
141 QQSK::State controlState() const;
142
143 void setControlTypeAndState(QQStyleKitExtendableControlType controlType, QQSK::State flags);
144
145 QObject *target() const;
146 void setTarget(QObject *target);
147
148 bool transitionsEnabled() const;
149 void setTransitionsEnabled(bool enabled);
150
151 static void resetReadersForStyle(const QQStyleKitStyle *style);
152
153 static QList<QQStyleKitReader *> s_allReaders;
154
155signals:
156 void controlTypeChanged();
157 void customTypeChanged();
158 void propertiesChanged();
159 void enabledChanged();
160 void focusedChanged();
161 void checkedChanged();
162 void hoveredChanged();
163 void pressedChanged();
164 void paletteChanged();
165 void verticalChanged();
166 void highlightedChanged();
167 void fontChanged();
168
169private slots:
170 void onPaletteChanged();
171
172private:
173 void updateControl();
174 void populateLocalStorage();
175 bool dontEmitChangedSignals() const;
176
177 QQuickStateGroup *stateGroup();
178 QQmlComponent *createControlChangesComponent() const;
179 QQmlComponent *createDelegateChangesComponent(const QString &delegateName) const;
180 void instantiatePropertyChanges(QQmlComponent *comp);
181 void maybeTrackDelegates();
182
183 bool rebuildEffectivePalette();
184 bool rebuildEffectiveFont();
185
186private:
187 Q_DISABLE_COPY(QQStyleKitReader)
188
189 /* The reason we have a QQStyleKitExtendableControlType in addition to
190 * QQStyleKitReader::ControlType, is that we allow the style to define controls types
191 * in the style beyond the types we offer in Qt Quick Controls. The predefined controls
192 * (QQStyleKitReader::ControlType) have types that starts at 100000 (ControlType::Unspecified),
193 * and any number before that is available for use for defining custom controls. */
194 QQStyleKitExtendableControlType m_type = ControlType::Unspecified;
195
196 bool m_dontEmitChangedSignals: 1;
197 bool m_effectiveVariationsDirty: 1;
198 bool m_transitionsEnabled: 1;
199
200 QPointer<QQuickPalette> m_palette;
201 QPalette m_effectivePalette;
202 QFont m_font;
203 bool m_fontDirty = true;
204 quint64 m_lastTextFontOverridesSignature = 0;
205 mutable QQStyleKitPropertyStorage m_storage;
206 AlternateState m_alternateState = AlternateState::Alternate1;
207 QQSK::State m_state = QQSK::StateFlag::Unspecified;
208 QQuickStateGroup *m_stateGroup = nullptr;
209 QQSK::Delegates m_trackedDelegates = QQSK::Delegate::NoDelegate;
210
211 QPointer<QObject> m_target;
212 QPointer<QQStyleKitStyle> m_explicitStyle;
213 QPointer<QQStyleKitReader> m_parentReader;
214 QList<QPointer<QQStyleKitVariation>> m_effectiveVariations;
215
216 QQStyleKitControlProperties m_global;
217
218 using PropertyChangesComponents = QMap<std::pair<Qt::totally_ordered_wrapper<QQmlEngine*>, QString>, QQmlComponent *>;
219 static PropertyChangesComponents s_propertyChangesComponents;
220
221 friend class QQStyleKitControlProperties;
222 friend class QQStyleKitPropertyResolver;
223 friend class QQStyleKitPropertyGroup;
224};
225
226QT_END_NAMESPACE
227
228#endif // QQSTYLEKITREADER_P_H
Q_INVOKABLE bool styleLoaded() const
QQStyleKitStyle * style() const
QUrl styleUrl() const
void transitionsEnabledChanged()
void setStyle(QQStyleKitStyle *style)
void setTransitionsEnabled(bool enabled)
QQStyleKitDebug * debug() const
bool transitionsEnabled() const
void setStyleUrl(const QUrl &styleUrl)
void filterChanged()
QString filter() const
void setFilter(const QString &filter)
void setControl(QQuickItem *item)
static Q_INVOKABLE bool insideControl(const QObject *child)
static QQStyleKitAttached * qmlAttachedProperties(QObject *obj=nullptr)
Combined button and popup list for selecting options.