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
qqstylekitcontrolproperties_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 QQSTYLEKITCONTROLPROPERTIES_P_H
6#define QQSTYLEKITCONTROLPROPERTIES_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 <QtGui/QColor>
21#include <QtQuick/private/qquickrectangle_p.h>
22#include <QtQuick/private/qquickimage_p.h>
23#include <QtQuick/private/qquicktransition_p.h>
24#include <QtQuick/private/qquicktext_p.h>
25
28#include <QtLabsStyleKit/qtlabsstylekitexports.h>
29
31
32using namespace Qt::StringLiterals;
33
34class QQStyleKitStyle;
39class QQStyleKitDelegateProperties;
40
42{
44
45public:
46 enum class EmitFlag {
49 };
50 Q_DECLARE_FLAGS(EmitFlags, EmitFlag)
52
54
55 PropertyPathId propertyPathId(QQSK::Property property, PropertyPathId::Flag flag) const;
56 QString pathToString() const;
57
58 template<typename T>
59 inline T styleProperty(
60 QQSK::Property property,
61 QQSK::Property alternative = QQSK::Property::NoProperty) const
62 {
63 return qvariant_cast<T>(QQStyleKitPropertyResolver::readStyleProperty(this, property, alternative));
64 }
65
66 template<typename T>
67 inline T styleProperty(QQSK::Property property, const T &defaultValue) const
68 {
69 const QVariant value = QQStyleKitPropertyResolver::readStyleProperty(this, property);
70 return value.isValid() ? qvariant_cast<T>(value) : defaultValue;
71 }
72
73 template<typename T>
74 inline bool setStyleProperty(QQSK::Property property, T value)
75 {
76 // This function will return true if the new value differes from the old one
77 return QQStyleKitPropertyResolver::writeStyleProperty(this, property, QVariant::fromValue(value));
78 }
79
80 inline bool isDefined(QQSK::Property property) const
81 {
82 return QQStyleKitPropertyResolver::readStyleProperty(this, property).isValid();
83 }
84
85 template<typename SUBCLASS>
86 inline void handleStylePropertyChanged(void (SUBCLASS::*changedSignal)());
87
88 template <typename SUBCLASS, typename... CHANGED_SIGNALS>
89 inline void handleStylePropertiesChanged(CHANGED_SIGNALS... changedSignals);
90
91 template <typename T>
92 T *lazyCreateGroup(T *const &ptr, QQSK::PropertyGroup group) const;
93
94 inline bool isControlProperties() const
95 {
96 /* Only QQStyleKitControlProperties (as opposed to the nested delegates) have properties
97 * with an ID at the bottom of the available space. The exception is the global flag, which
98 * inherits the groupSpace from the control. */
99 return m_groupSpace.start == 0 && m_pathFlags != QQSK::PropertyPathFlag::Global;
100 }
101
103 inline QQSK::PropertyPathFlags pathFlags() const { return m_pathFlags; }
104 void emitChangedForAllStylePropertiesRecursive(EmitFlags emitFlags);
105
106protected:
109
110private:
111 bool shouldEmitLocally();
112 bool shouldEmitGlobally();
113
114 static QHash<PropertyPathId_t, QString> s_pathStrings;
115};
116
117// ************* QQStyleKitImageProperties ****************
118
120{
121 Q_OBJECT
122 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged FINAL)
125 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
127
128public:
130
131 template <typename... CHANGED_SIGNALS>
132 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
133
134 QUrl source() const;
135 void setSource(const QUrl &source);
136
137 QColor color() const;
138 void setColor(const QColor &color);
139
141 void setFillMode(QQuickImage::FillMode fillMode);
142
143signals:
147};
148
149// ************* QQStyleKitBorderProperties ****************
150
152{
153 Q_OBJECT
154 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL)
156 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
158
159public:
161
162 template <typename... CHANGED_SIGNALS>
163 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
164
165 qreal width() const;
166 void setWidth(qreal width);
167
168 QColor color() const;
169 void setColor(const QColor &color);
170
171signals:
174};
175
176// ************* QQStyleKitShadowProperties ****************
177
178class Q_LABSSTYLEKIT_EXPORT QQStyleKitShadowProperties : public QQStyleKitPropertyGroup
179{
180 Q_OBJECT
181 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
182 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
183 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
184 Q_PROPERTY(qreal verticalOffset READ verticalOffset WRITE setVerticalOffset NOTIFY verticalOffsetChanged FINAL)
185 Q_PROPERTY(qreal horizontalOffset READ horizontalOffset WRITE setHorizontalOffset NOTIFY horizontalOffsetChanged FINAL)
186 Q_PROPERTY(qreal blur READ blur WRITE setBlur NOTIFY blurChanged FINAL)
187 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL)
188 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
189 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
190 QML_NAMED_ELEMENT(ShadowStyle)
191
192public:
193 QQStyleKitShadowProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent = nullptr);
194
195 template <typename... CHANGED_SIGNALS>
196 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
197
198 QColor color() const;
199 void setColor(QColor color);
200
201 qreal opacity() const;
202 void setOpacity(qreal opacity);
203
204 qreal scale() const;
205 void setScale(qreal scale);
206
207 qreal verticalOffset() const;
208 void setVerticalOffset(qreal verticalOffset);
209
210 qreal horizontalOffset() const;
211 void setHorizontalOffset(qreal horizontalOffset);
212
213 qreal blur() const;
214 void setBlur(qreal blur);
215
216 bool visible() const;
217 void setVisible(bool visible);
218
219 QQmlComponent *delegate() const;
220 void setDelegate(QQmlComponent *delegate);
221
222signals:
223 void colorChanged();
224 void opacityChanged();
225 void scaleChanged();
226 void verticalOffsetChanged();
227 void horizontalOffsetChanged();
228 void blurChanged();
229 void visibleChanged();
230 void delegateChanged();
231};
232
233// ************* QQStyleKitDelegateProperties ****************
234
235class Q_LABSSTYLEKIT_EXPORT QQStyleKitDelegateProperties : public QQStyleKitPropertyGroup
236{
237 Q_OBJECT
238 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged FINAL)
239 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged FINAL)
240 Q_PROPERTY(qreal minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged FINAL)
241 Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged FINAL)
242 Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged FINAL)
243 Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged FINAL)
244 Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged FINAL)
245 Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged FINAL)
246 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
247 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
248 Q_PROPERTY(qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius NOTIFY topLeftRadiusChanged FINAL)
249 Q_PROPERTY(qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY topRightRadiusChanged FINAL)
250 Q_PROPERTY(qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius NOTIFY bottomLeftRadiusChanged FINAL)
251 Q_PROPERTY(qreal bottomRightRadius READ bottomRightRadius WRITE setBottomRightRadius NOTIFY bottomRightRadiusChanged FINAL)
252 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
253 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged FINAL)
254 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
255 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
256 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL)
257 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged FINAL)
258 Q_PROPERTY(QQuickGradient *gradient READ gradient WRITE setGradient NOTIFY gradientChanged FINAL)
259 Q_PROPERTY(QQStyleKitImageProperties *image READ image NOTIFY imageChanged FINAL)
260 Q_PROPERTY(QQStyleKitBorderProperties *border READ border NOTIFY borderChanged FINAL)
261 Q_PROPERTY(QQStyleKitShadowProperties *shadow READ shadow NOTIFY shadowChanged FINAL)
262 Q_PROPERTY(QObject *data READ data WRITE setData NOTIFY dataChanged FINAL)
263 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
264 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
265 QML_NAMED_ELEMENT(DelegateStyle)
266
267public:
268 QQStyleKitDelegateProperties(QQSK::PropertyGroup group, QQStyleKitControlProperties *parent = nullptr);
269
270 template <typename... CHANGED_SIGNALS>
271 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
272
273 qreal radius() const;
274 void setRadius(qreal radius);
275
276 qreal topLeftRadius() const;
277 void setTopLeftRadius(qreal radius);
278
279 qreal topRightRadius() const;
280 void setTopRightRadius(qreal radius);
281
282 qreal bottomLeftRadius() const;
283 void setBottomLeftRadius(qreal radius);
284
285 qreal bottomRightRadius() const;
286 void setBottomRightRadius(qreal radius);
287
288 qreal scale() const;
289 void setScale(qreal scale);
290
291 qreal rotation() const;
292 void setRotation(qreal rotation);
293
294 qreal implicitWidth() const;
295 void setImplicitWidth(qreal width);
296
297 qreal implicitHeight() const;
298 void setImplicitHeight(qreal height);
299
300 qreal minimumWidth() const;
301 void setMinimumWidth(qreal width);
302
303 qreal margins() const;
304 void setMargins(qreal margins);
305
306 qreal leftMargin() const;
307 void setLeftMargin(qreal margin);
308
309 qreal rightMargin() const;
310 void setRightMargin(qreal margin);
311
312 qreal topMargin() const;
313 void setTopMargin(qreal margin);
314
315 qreal bottomMargin() const;
316 void setBottomMargin(qreal margin);
317
318 Qt::Alignment alignment() const;
319 void setAlignment(Qt::Alignment alignment);
320
321 qreal opacity() const;
322 void setOpacity(qreal opacity);
323
324 QColor color() const;
325 void setColor(const QColor &color);
326
327 bool visible() const;
328 void setVisible(bool visible);
329
330 bool clip() const;
331 void setClip(bool clip);
332
333 QQuickGradient *gradient() const;
334 void setGradient(QQuickGradient *gradient);
335
336 QObject *data() const;
337 void setData(QObject *data);
338
339 QQmlComponent *delegate() const;
340 void setDelegate(QQmlComponent *delegate);
341
342 QQStyleKitImageProperties *image() const;
343 QQStyleKitBorderProperties *border() const;
344 QQStyleKitShadowProperties *shadow() const;
345
346signals:
347 void colorChanged();
348 void radiusChanged();
349 void topLeftRadiusChanged();
350 void topRightRadiusChanged();
351 void bottomLeftRadiusChanged();
352 void bottomRightRadiusChanged();
353 void scaleChanged();
354 void rotationChanged();
355 void visibleChanged();
356 void clipChanged();
357 void borderChanged();
358 void shadowChanged();
359 void imageChanged();
360 void gradientChanged();
361 void colorImageChanged();
362 void implicitWidthChanged();
363 void implicitHeightChanged();
364 void minimumWidthChanged();
365 void marginsChanged();
366 void leftMarginChanged();
367 void rightMarginChanged();
368 void topMarginChanged();
369 void bottomMarginChanged();
370 void alignmentChanged();
371 void opacityChanged();
372 void dataChanged();
373 void delegateChanged();
374
375private:
376 QPointer<QQuickGradient> m_gradient;
377 QQStyleKitBorderProperties *m_border = nullptr;
378 QQStyleKitShadowProperties *m_shadow = nullptr;
379 QQStyleKitImageProperties *m_image = nullptr;
380};
381
382// ************* QQStyleKitHandleProperties ****************
383
385{
386 Q_OBJECT
387 Q_PROPERTY(QQStyleKitDelegateProperties *first READ first NOTIFY firstChanged FINAL)
389 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
391
392public:
394 QQStyleKitDelegateProperties *first() const;
395 QQStyleKitDelegateProperties *second() const;
396
397signals:
400
401private:
402 QQStyleKitDelegateProperties *m_first = nullptr;
403 QQStyleKitDelegateProperties *m_second = nullptr;
404
405 friend class QQStyleKitReader;
407};
408
409// ************* QQStyleKitIndicatorProperties ****************
410
412{
413 Q_OBJECT
414 Q_PROPERTY(QQStyleKitDelegateProperties *foreground READ foreground NOTIFY foregroundChanged FINAL)
415 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
417
418public:
420
421 template <typename... CHANGED_SIGNALS>
422 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
423
424 QQStyleKitDelegateProperties *foreground() const;
425
426signals:
428
429private:
430 QQStyleKitDelegateProperties *m_foreground = nullptr;
431
432 friend class QQStyleKitReader;
434};
435
436// ************* QQStyleKitIndicatorWithSubTypes ****************
437
439{
440 Q_OBJECT
441 Q_PROPERTY(QQStyleKitDelegateProperties *foreground READ foreground NOTIFY foregroundChanged FINAL)
444 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
446
447public:
449
450 template <typename... CHANGED_SIGNALS>
451 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
452
453 QQStyleKitDelegateProperties *foreground() const;
456
457signals:
459 void upChanged();
461
462private:
463 QQStyleKitDelegateProperties *m_foreground = nullptr;
464 QQStyleKitIndicatorProperties *m_up = nullptr;
465 QQStyleKitIndicatorProperties *m_down = nullptr;
466
467 friend class QQStyleKitReader;
469};
470
471// ************* QQStyleKitTextProperties ****************
472
474{
475 Q_OBJECT
476 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
486
487 QML_UNCREATABLE("This component can only be instantiated by StyleKit")
489
490public:
492
493 template <typename... CHANGED_SIGNALS>
494 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
495
496 QColor color() const;
497 void setColor(const QColor &color);
498
499 Qt::Alignment alignment() const;
500 void setAlignment(Qt::Alignment alignment);
501
502 bool bold() const;
503 void setBold(bool bold);
504
505 bool italic() const;
506 void setItalic(bool italic);
507
508 qreal pointSize() const;
509 void setPointSize(qreal pointSize);
510
511 qreal padding() const;
512 void setPadding(qreal padding);
513
514 qreal leftPadding() const;
515 void setLeftPadding(qreal leftPadding);
516
517 qreal rightPadding() const;
518 void setRightPadding(qreal rightPadding);
519
520 qreal topPadding() const;
521 void setTopPadding(qreal topPadding);
522
523 qreal bottomPadding() const;
524 void setBottomPadding(qreal bottomPadding);
525
526signals:
537};
538
539/************* QQStyleKitControlProperties ****************
540 * QQStyleKitControlProperties (and all other subclasses of QQStyleKitPropertyGroup),
541 * is just an empty interface declaring the properties available for styling and reading.
542 * It contains as little data as possible since it will be instantiated a lot. E.g a style
543 * will instantiate them for every style.button, style.slider, etc defined, the same for a
544 * theme, and also each instance of a StyleKitReader. Those are all subclasses of this
545 * class. Each subclass will determine if the properties can be written to (as opposed to
546 * only be read), and if so, offer a storage for storing those values. That storage is typically
547 * a map that stores _only_ the properties that are written to, and nothing else.
548 */
550{
551 Q_OBJECT
552 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
563 // This type is merged with ControlState, from a QML API point of view
565
566public:
568
569 void emitChangedForAllStyleProperties(EmitFlags emitFlags);;
570 template <typename... CHANGED_SIGNALS>
571 void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const;
573 std::function<void (QQStyleKitDelegateProperties *, QQSK::Delegate, const QString &)> f);
574
575 QQStyleKitStyle *style() const;
576 QQSK::Subclass subclass() const;
579
580 qreal spacing() const;
581 void setSpacing(qreal spacing);
582
583 qreal padding() const;
584 void setPadding(qreal padding);
585
586 qreal leftPadding() const;
587 void setLeftPadding(qreal leftPadding);
588
589 qreal rightPadding() const;
590 void setRightPadding(qreal rightPadding);
591
592 qreal topPadding() const;
593 void setTopPadding(qreal topPadding);
594
595 qreal bottomPadding() const;
596 void setBottomPadding(qreal bottomPadding);
597
599 void setTransition(QQuickTransition *transition);
600
602
603 QQStyleKitDelegateProperties *background() const;
606
607signals:
619
620private:
622
624 QQStyleKitHandleProperties *m_handle = nullptr;
625 QQStyleKitIndicatorWithSubTypes *m_indicator = nullptr;
626 QQStyleKitTextProperties *m_text = nullptr;
627
629 friend class QQStyleKitReader;
630};
631
632QT_END_NAMESPACE
633
634#endif // QQSTYLEKITCONTROLPROPERTIES_P_H
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitTextProperties * text() const
QQStyleKitIndicatorWithSubTypes * indicator() const
void setTransition(QQuickTransition *transition)
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
QQStyleKitDelegateProperties * background() const
QQStyleKitReader * asQQStyleKitReader() const
void emitChangedForAllStyleProperties(EmitFlags emitFlags)
QQStyleKitHandleProperties * handle() const
QQStyleKitControlState * asQQStyleKitState() const
void forEachUsedDelegate(std::function< void(QQStyleKitDelegateProperties *, QQSK::Delegate, const QString &)> f)
QQStyleKitDelegateProperties * delegateStyle() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setDelegateStyle(QQStyleKitDelegateProperties *delegateProperties)
QQStyleKitDelegateProperties * first() const
QQStyleKitDelegateProperties * second() const
QQuickImage::FillMode fillMode() const
void emitGlobally(QQStyleKitExtendableControlType controlType, CHANGED_SIGNALS... changedSignals) const
void setFillMode(QQuickImage::FillMode fillMode)
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
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
Combined button and popup list for selecting options.