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, public QQmlParserStatus
35{
36 Q_OBJECT
37 Q_INTERFACES(QQmlParserStatus)
38 Q_PROPERTY(QQStyleKitExtendableControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged FINAL)
39 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
40 Q_PROPERTY(bool focused READ focused WRITE setFocused NOTIFY focusedChanged FINAL)
41 Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged FINAL)
42 Q_PROPERTY(bool hovered READ hovered WRITE setHovered NOTIFY hoveredChanged FINAL)
43 Q_PROPERTY(bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL)
44 Q_PROPERTY(bool vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL)
45 Q_PROPERTY(bool highlighted READ highlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL)
46 Q_PROPERTY(QFont font READ font NOTIFY fontChanged FINAL)
47 Q_PROPERTY(QQuickPalette *palette READ palette WRITE setPalette NOTIFY paletteChanged FINAL)
48 Q_PROPERTY(QQStyleKitControlProperties *global READ global CONSTANT FINAL)
49
50 QML_NAMED_ELEMENT(StyleReader)
51
52public:
53 enum ControlType {
54 Unspecified = 100000,
55 Control,
56 AbstractButton,
57 ApplicationWindow,
58 Button,
59 CheckBox,
60 ComboBox,
61 FlatButton,
62 ProgressBar,
63 ScrollBar,
64 ScrollIndicator,
65 ScrollView,
66 Slider,
67 SpinBox,
68 SwitchControl,
69 SearchField,
70 TabBar,
71 TabButton,
72 TextArea,
73 TextField,
74 TextInput,
75 ToolBar,
76 ToolButton,
77 ToolSeparator,
78 RadioButton,
79 RoundButton,
80 ItemDelegate,
81 Popup,
82 Menu,
83 MenuBarItem,
84 MenuSeparator,
85 Dialog,
86 Pane,
87 Page,
88 Frame,
89 Label,
90 GroupBox
91 };
92 Q_ENUM(ControlType)
93
94 enum class AlternateState {
95 Alternate1,
96 Alternate2
97 };
98 Q_ENUM(AlternateState)
99
100 QQStyleKitReader(QObject *parent = nullptr);
101 ~QQStyleKitReader();
102
103 QQStyleKitExtendableControlType controlType() const;
104 void setControlType(QQStyleKitExtendableControlType type);
105#ifdef QT_DEBUG
106 ControlType typeAsControlType() const;
107#endif
108
109 bool hovered() const;
110 void setHovered(bool hovered);
111
112 bool enabled() const;
113 void setEnabled(bool enabled);
114
115 bool focused() const;
116 void setFocused(bool focused);
117
118 bool checked() const;
119 void setChecked(bool checked);
120
121 bool pressed() const;
122 void setPressed(bool pressed);
123
124 QQuickPalette *palette() const;
125 void setPalette(QQuickPalette *palette);
126 QPalette effectivePalette() const;
127
128 bool vertical() const;
129 void setVertical(bool vertical);
130
131 bool highlighted() const;
132 void setHighlighted(bool highlighted);
133
134 QQStyleKitStyle *explicitStyle() const;
135 void setExplicitStyle(QQStyleKitStyle *style);
136
137 QFont font() const;
138
139 QQStyleKitControlProperties *global() const;
140
141 QVariant readStyleProperty(PropertyStorageId key) const;
142 void writeStyleProperty(PropertyStorageId key, const QVariant &value);
143 void clearLocalStorage();
144
145 QQSK::State controlState() const;
146
147 void setControlTypeAndState(QQStyleKitExtendableControlType controlType, QQSK::State flags);
148
149 QObject *target() const;
150 void setTarget(QObject *target);
151
152 bool transitionsEnabled() const;
153 void setTransitionsEnabled(bool enabled);
154
155 static void resetReadersForStyle(const QQStyleKitStyle *style);
156
157 static QList<QQStyleKitReader *> s_allReaders;
158
159signals:
160 void controlTypeChanged();
161 void customTypeChanged();
162 void propertiesChanged();
163 void enabledChanged();
164 void focusedChanged();
165 void checkedChanged();
166 void hoveredChanged();
167 void pressedChanged();
168 void paletteChanged();
169 void verticalChanged();
170 void highlightedChanged();
171 void fontChanged();
172
173private slots:
174 void onPaletteChanged();
175
176protected:
177 void classBegin() override {}
178 void componentComplete() override { m_completed = true; };
179
180private:
181 void updateControl();
182 void populateLocalStorage();
183 bool dontEmitChangedSignals() const;
184
185 QQuickStateGroup *stateGroup();
186 QQmlComponent *createControlChangesComponent() const;
187 QQmlComponent *createDelegateChangesComponent(const QString &delegateName) const;
188 void instantiatePropertyChanges(QQmlComponent *comp);
189 void maybeTrackDelegates();
190
191 bool rebuildEffectivePalette();
192 bool rebuildEffectiveFont();
193
194private:
195 Q_DISABLE_COPY(QQStyleKitReader)
196
197 /* The reason we have a QQStyleKitExtendableControlType in addition to
198 * QQStyleKitReader::ControlType, is that we allow the style to define controls types
199 * in the style beyond the types we offer in Qt Quick Controls. The predefined controls
200 * (QQStyleKitReader::ControlType) have types that starts at 100000 (ControlType::Unspecified),
201 * and any number before that is available for use for defining custom controls. */
202 QQStyleKitExtendableControlType m_type = ControlType::Unspecified;
203
204 bool m_dontEmitChangedSignals: 1;
205 bool m_effectiveVariationsDirty: 1;
206 bool m_transitionsEnabled: 1;
207 bool m_completed: 1;
208
209 QPointer<QQuickPalette> m_palette;
210 QPalette m_effectivePalette;
211 QFont m_font;
212 bool m_fontDirty = true;
213 quint64 m_lastTextFontOverridesSignature = 0;
214 mutable QQStyleKitPropertyStorage m_storage;
215 AlternateState m_alternateState = AlternateState::Alternate1;
216 QQSK::State m_state = QQSK::StateFlag::Unspecified;
217 QQuickStateGroup *m_stateGroup = nullptr;
218 QQSK::Delegates m_trackedDelegates = QQSK::Delegate::NoDelegate;
219
220 QPointer<QObject> m_target;
221 QPointer<QQStyleKitStyle> m_explicitStyle;
222 QPointer<QQStyleKitReader> m_parentReader;
223 QList<QPointer<QQStyleKitVariation>> m_effectiveVariations;
224
225 QQStyleKitControlProperties m_global;
226
227 using PropertyChangesComponents = QMap<std::pair<Qt::totally_ordered_wrapper<QQmlEngine*>, QString>, QQmlComponent *>;
228 static PropertyChangesComponents s_propertyChangesComponents;
229
230 friend class QQStyleKitControlProperties;
231 friend class QQStyleKitPropertyResolver;
232 friend class QQStyleKitPropertyGroup;
233};
234
235QT_END_NAMESPACE
236
237#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.