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
qqstylekitglobal_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 QQSTYLEKITGLOBAL_P_H
6#define QQSTYLEKITGLOBAL_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
22
23class QQSK: public QObject
24{
25 Q_OBJECT
26
27public:
28 enum class Delegate {
29 NoDelegate = 0x0000,
30 Control = 0x0001,
31 Background = 0x0002,
32 Handle = 0x0004,
33 HandleFirst = 0x0008,
34 HandleSecond = 0x0010,
35 Indicator = 0x0020,
36 IndicatorForeground = 0x0040,
37 IndicatorFirst = 0x0080,
38 IndicatorFirstForeground = 0x0100,
39 IndicatorSecond = 0x0200,
40 IndicatorSecondForeground = 0x0400,
41 // Note: for now, "control.text" is not treated as a separate delegate, but
42 // as an integrated part of "control". Hence, there is no "Text" value in this enum.
43 };
44 Q_DECLARE_FLAGS(Delegates, Delegate)
45 Q_FLAG(Delegate)
46
47 enum class PropertyGroup {
48 Control,
49 Background,
50 Foreground,
51 Border,
52 Handle,
53 Image,
54 Indicator,
55 Shadow,
56 Text,
57 PATH_ID_GROUP_COUNT,
58
59 /* Sub types, like states, are a part of a propertys storage ID, not its Path ID.
60 * They appear in the group path, but are handled differently. */
61 DelegateSubtype0,
62 DelegateSubtype1,
63 DelegateSubtype2,
64
65 /* Read options are not a part of either the Path ID nor the Storage ID. They
66 * just offer a convenient API for providing read options when reading a property.
67 * The Global flag is used to signal that a property should be read directly from
68 * the global style, circumventing the local StyleKitReader cache. */
69 GlobalFlag,
70
71 Unspecified
72 };
73 Q_ENUM(PropertyGroup)
74
75 enum class PropertyPathFlag : quint8 {
76 NoFlags = 0x0,
77 DelegateSubtype0 = 0x1,
78 DelegateSubtype1 = 0x2,
79 DelegateSubtype2 = 0x4,
80 Global = 0x8
81 };
82 Q_DECLARE_FLAGS(PropertyPathFlags, PropertyPathFlag)
83 Q_FLAG(PropertyPathFlag)
84
85 enum class Property {
86 NoProperty,
87 BottomLeftRadius,
88 BottomMargin,
89 BottomPadding,
90 BottomRightRadius,
91 Clip,
92 Color,
93 Data,
94 Delegate,
95 FillMode,
96 FillWidth,
97 FillHeight,
98 Gradient,
99 HOffset,
100 Image,
101 ImplicitWidth,
102 ImplicitHeight,
103 LeftMargin,
104 LeftPadding,
105 Margins,
106 MinimumWidth,
107 MinimumHeight,
108 Opacity,
109 Padding,
110 Radius,
111 RightMargin,
112 RightPadding,
113 Rotation,
114 Scale,
115 Source,
116 Spacing,
117 TopLeftRadius,
118 TopMargin,
119 TopPadding,
120 TopRightRadius,
121 Transition,
122 Variations,
123 Visible,
124 VOffset,
125 Width,
126 Blur,
127 Alignment,
128 Bold,
129 Italic,
130 PointSize,
131 COUNT
132 };
133 Q_ENUM(Property)
134
135 enum class StateFlag {
136 Unspecified = 0x000,
137 Normal = 0x001,
138 Pressed = 0x002,
139 Hovered = 0x004,
140 Highlighted = 0x008,
141 Focused = 0x010,
142 Checked = 0x020,
143 Vertical = 0x040,
144 Disabled = 0x080,
145 MAX_STATE = 0x100,
146 };
147 Q_DECLARE_FLAGS(State, StateFlag)
148 Q_FLAG(State)
149
150 enum class Subclass {
151 QQStyleKitState,
152 QQStyleKitReader,
153 };
154 Q_ENUM(Subclass)
155
156public:
157 template <typename T, typename Owner, typename... Args>
158 static inline T *lazyCreate(T *const &ptr, const Owner *self, Args&&... args)
159 {
160 if (!ptr) {
161 auto *mutableSelf = const_cast<Owner *>(self);
162 auto *&mutablePtr = const_cast<T *&>(ptr);
163 mutablePtr = new T(std::forward<Args>(args)..., mutableSelf);
164 }
165 return ptr;
166 }
167};
168
169Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::State)
170Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::Delegates)
171Q_DECLARE_OPERATORS_FOR_FLAGS(QQSK::PropertyPathFlags)
172
173using PropertyPathId_t = quint32;
174using PropertyStorageId = quint32;
175using QQStyleKitExtendableControlType = quint32;
176using QQStyleKitPropertyStorage = QHash<PropertyStorageId, QVariant>;
177
178constexpr PropertyPathId_t maxPropertyStorageSpaceSize = std::numeric_limits<PropertyPathId_t>::max();
179constexpr PropertyPathId_t nestedGroupCount = PropertyPathId_t(QQSK::PropertyGroup::PATH_ID_GROUP_COUNT);
180constexpr PropertyPathId_t maxStateCombinationCount = PropertyPathId_t(QQSK::StateFlag::MAX_STATE);
181constexpr PropertyPathId_t stateStorageSpaceSize = maxPropertyStorageSpaceSize / maxStateCombinationCount;
182constexpr PropertyPathId_t subtypeCount = PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype2) - PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype0) + 1;
183constexpr PropertyPathId_t nestedGroupsStartSize = maxPropertyStorageSpaceSize / (maxStateCombinationCount * subtypeCount);
184constexpr PropertyPathId_t subtypeStorageSpaceSize = maxPropertyStorageSpaceSize / (subtypeCount * maxStateCombinationCount);
185
190
193
194public:
199 Q_ENUM(Flag)
200
205
206 inline QQSK::Property property() const { return m_property; }
208 {
209 /* The path ID is the property's identifier when its group path is taken
210 * into account. Each property inside QQStyleKitControlProperties has a unique
211 * path ID. For example, both 'background.color' and 'indicator.color' use the
212 * same QQSK::Property (Color), but they still have different path IDs. */
213 return m_groupStart + PropertyPathId_t(m_property);
214 }
215 inline PropertyStorageId storageId(QQSK::State state) const
216 {
217 /* To compute the fully qualified property ID used as a key in a storage map
218 * (QMap) that holds its value, we need to prefix the path ID with the state ID,
219 * since the same path can have different values in different states.
220 * Because StateFlag::Normal == 1, we subtract 1 so that the address space for
221 * properties in the Normal state starts at 0. */
222 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
223 const PropertyPathId_t stateIndex = PropertyPathId_t(state) - 1;
224 const PropertyPathId_t stateStart = stateIndex * stateStorageSpaceSize;
225 return stateStart + pathId();
226 }
227
228private:
229 QQSK::Property m_property;
230 PropertyPathId_t m_groupStart;
231};
232
233QT_END_NAMESPACE
234
235#endif // QQSTYLEKITGLOBAL_P_H
QQSK::Property property() const
PropertyStorageId storageId(QQSK::State state) const
PropertyPathId_t pathId() const
QQStyleKitDelegateProperties * delegateStyle() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setDelegateStyle(QQStyleKitDelegateProperties *delegateProperties)
QQStyleKitDelegateProperties * first() const
QQStyleKitDelegateProperties * second() const
QQStyleKitDelegateProperties * foreground() const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitDelegateProperties * foreground() const
QQStyleKitIndicatorProperties * down() const
QQStyleKitIndicatorProperties * up() const
QQStyleKitIndicatorProperties * second() const
QQStyleKitIndicatorProperties * first() const
bool setStyleProperty(QQSK::Property property, T value)
QQStyleKitPropertyGroupSpace m_groupSpace
void emitChangedForAllStylePropertiesRecursive(EmitFlags emitFlags)
T styleProperty(QQSK::Property property, const T &defaultValue) const
T styleProperty(QQSK::Property property, QQSK::Property alternative=QQSK::Property::NoProperty) const
T * lazyCreateGroup(T *const &ptr, QQSK::PropertyGroup group) const
QQSK::PropertyPathFlags pathFlags() const
void handleStylePropertyChanged(void(SUBCLASS::*changedSignal)())
PropertyPathId propertyPathId(QQSK::Property property, PropertyPathId::Flag flag) const
void handleStylePropertiesChanged(CHANGED_SIGNALS... changedSignals)
bool isDefined(QQSK::Property property) const
QQStyleKitControlProperties * controlProperties() const
void setBottomPadding(qreal bottomPadding)
void setAlignment(Qt::Alignment alignment)
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitTextProperties * first() const
QQStyleKitTextProperties * second() const
Combined button and popup list for selecting options.
constexpr PropertyPathId_t nestedGroupCount
constexpr PropertyPathId_t nestedGroupsStartSize
constexpr PropertyPathId_t maxStateCombinationCount
constexpr PropertyPathId_t subtypeStorageSpaceSize
constexpr PropertyPathId_t stateStorageSpaceSize
constexpr PropertyPathId_t subtypeCount
constexpr PropertyPathId_t maxPropertyStorageSpaceSize