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 MenuBar,
84 MenuBarItem,
85 MenuItem,
86 MenuSeparator,
87 Dialog,
88 Pane,
89 Page,
90 Frame,
91 Label,
92 GroupBox
93 };
94 Q_ENUM(ControlType)
95
96 enum class AlternateState {
97 Alternate1,
98 Alternate2
99 };
100 Q_ENUM(AlternateState)
101
102 QQStyleKitReader(QObject *parent = nullptr);
103 ~QQStyleKitReader();
104
105 QQStyleKitExtendableControlType controlType() const;
106 void setControlType(QQStyleKitExtendableControlType type);
107#ifdef QT_DEBUG
108 ControlType typeAsControlType() const;
109#endif
110
111 bool hovered() const;
112 void setHovered(bool hovered);
113
114 bool enabled() const;
115 void setEnabled(bool enabled);
116
117 bool focused() const;
118 void setFocused(bool focused);
119
120 bool checked() const;
121 void setChecked(bool checked);
122
123 bool pressed() const;
124 void setPressed(bool pressed);
125
126 QQuickPalette *palette() const;
127 void setPalette(QQuickPalette *palette);
128 QPalette effectivePalette() const;
129
130 bool vertical() const;
131 void setVertical(bool vertical);
132
133 bool highlighted() const;
134 void setHighlighted(bool highlighted);
135
136 QQStyleKitStyle *explicitStyle() const;
137 void setExplicitStyle(QQStyleKitStyle *style);
138
139 QFont font() const;
140
141 QQStyleKitControlProperties *global() const;
142
143 QVariant readStyleProperty(PropertyStorageId key) const;
144 void writeStyleProperty(PropertyStorageId key, const QVariant &value);
145 void clearLocalStorage();
146
147 QQSK::State controlState() const;
148
149 void setControlTypeAndState(QQStyleKitExtendableControlType controlType, QQSK::State flags);
150
151 QObject *target() const;
152 void setTarget(QObject *target);
153
154 // Called by componentComplete()
155 // Factored out so the widget style can call it
156 void setCompleted(bool completed);
157
158 bool transitionsEnabled() const;
159 void setTransitionsEnabled(bool enabled);
160
161 static void resetReadersForStyle(const QQStyleKitStyle *style);
162
163 static QList<QQStyleKitReader *> s_allReaders;
164
165signals:
166 void controlTypeChanged();
167 void customTypeChanged();
168 void propertiesChanged();
169 void enabledChanged();
170 void focusedChanged();
171 void checkedChanged();
172 void hoveredChanged();
173 void pressedChanged();
174 void paletteChanged();
175 void verticalChanged();
176 void highlightedChanged();
177 void fontChanged();
178
179private slots:
180 void onPaletteChanged();
181
182protected:
183 void classBegin() override {}
184 void componentComplete() override;
185
186private:
187 void updateControl();
188 void populateLocalStorage();
189 bool dontEmitChangedSignals() const;
190
191 QQuickStateGroup *stateGroup();
192 QQmlComponent *createControlChangesComponent() const;
193 QQmlComponent *createDelegateChangesComponent(const QString &delegateName) const;
194 void instantiatePropertyChanges(QQmlComponent *comp);
195 void maybeTrackDelegates();
196
197 bool rebuildEffectivePalette();
198 bool rebuildEffectiveFont();
199
200private:
201 Q_DISABLE_COPY(QQStyleKitReader)
202
203 /* The reason we have a QQStyleKitExtendableControlType in addition to
204 * QQStyleKitReader::ControlType, is that we allow the style to define controls types
205 * in the style beyond the types we offer in Qt Quick Controls. The predefined controls
206 * (QQStyleKitReader::ControlType) have types that starts at 100000 (ControlType::Unspecified),
207 * and any number before that is available for use for defining custom controls. */
208 QQStyleKitExtendableControlType m_type = ControlType::Unspecified;
209
210 bool m_dontEmitChangedSignals: 1;
211 bool m_effectiveVariationsDirty: 1;
212 bool m_transitionsEnabled: 1;
213 bool m_completed: 1;
214
215 QPointer<QQuickPalette> m_palette;
216 QPalette m_effectivePalette;
217 QFont m_font;
218 bool m_fontDirty = true;
219 quint64 m_lastTextFontOverridesSignature = 0;
220 mutable QQStyleKitPropertyStorage m_storage;
221 AlternateState m_alternateState = AlternateState::Alternate1;
222 QQSK::State m_state = QQSK::StateFlag::Unspecified;
223 QQuickStateGroup *m_stateGroup = nullptr;
224 QQSK::Delegates m_trackedDelegates = QQSK::Delegate::NoDelegate;
225
226 QPointer<QObject> m_target;
227 QPointer<QQStyleKitStyle> m_explicitStyle;
228 QPointer<QQStyleKitReader> m_parentReader;
229 QList<QPointer<QQStyleKitVariation>> m_effectiveVariations;
230
231 QQStyleKitControlProperties m_global;
232
233 using PropertyChangesComponents = QMap<std::pair<Qt::totally_ordered_wrapper<QQmlEngine*>, QString>, QQmlComponent *>;
234 static PropertyChangesComponents s_propertyChangesComponents;
235
236 friend class QQStyleKitControlProperties;
237 friend class QQStyleKitPropertyResolver;
238 friend class QQStyleKitPropertyGroup;
239};
240
241QT_END_NAMESPACE
242
243#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.