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
qstylekitstyle_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QSTYLEKITSTYLE_P_H
6#define QSTYLEKITSTYLE_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 <QtCore/qset.h>
20#include <QtWidgets/private/qtwidgetsglobal_p.h>
21#include <QtWidgets/qcommonstyle.h>
22#include <QtWidgets/private/qcommonstyle_p.h>
23#include <QtQml/qqmlengine.h>
24#include "qstylekitstyle.h"
25#include <QtLabsStyleKit/private/qqstylekitreader_p.h>
26
28
29class QQStyleKitDelegateProperties;
31class QQStyleKitImageProperties;
34class QQStyleKitReader;
35class QQStyleKitStyle;
37{
38 Q_DECLARE_PUBLIC(QStyleKitStyle)
39
40 // Stores all the metrics needed to draw and size a control.
41 // Cached per-control type and state so that we don't have to do multiple
42 // lookups on the reader for each property when drawing
43 struct ControlMetrics
44 {
55 int spacing;
56 };
57 // Key for the metrics cache
58 struct MetricsCacheKey
59 {
60 QQStyleKitReader::ControlType type;
61 QQSK::State state;
62
63 friend bool operator==(MetricsCacheKey lhs, MetricsCacheKey rhs) noexcept
64 { return lhs.type == rhs.type && lhs.state == rhs.state; }
65 friend size_t qHash(MetricsCacheKey key, size_t seed = 0) noexcept
66 { return qHashMulti(seed, key.type, key.state); }
67 };
68
69 // Stores the resolved properties for a control in a specific state.
70 // Used by painters to read properties when drawing.
71 // The reader stays internal and we expose only the property accessors
72 // to avoid mutating the reader and reconfigure resolution mid-paint.
73 struct QQStyleKitResolved
74 {
75 const QQStyleKitReader *reader = nullptr;
76 const ControlMetrics *metrics = nullptr;
77 const QWidget *widget = nullptr;
78
79 bool isValid() const { return reader && metrics; }
80 const QQStyleKitTextProperties *text() const;
81 const QQStyleKitDelegateProperties *background() const;
82 const QQStyleKitHandleProperties *handle() const;
83 const QQStyleKitIndicatorWithSubTypes *indicator() const;
84 QFont font() const;
85 };
86 // Stores the resolved properties for layout purposes.
87 // Accessors read static values via the shared reader (transitions disabled),
88 // so layout never depends on animation state.
89 struct QQStyleKitLayoutResolved
90 {
91 const ControlMetrics *metrics = nullptr;
92 const QQStyleKitControlProperties *staticProps = nullptr;
93 QFont staticFont;
94
95 bool isValid() const { return metrics; }
96 const QQStyleKitTextProperties *text() const;
97 const QQStyleKitDelegateProperties *background() const;
98 const QQStyleKitHandleProperties *handle() const;
99 const QQStyleKitIndicatorWithSubTypes *indicator() const;
100 QFont font() const { return staticFont; }
101 };
102
103 // Copied from qstylesheetstyle_p.h
104 template <typename T>
105 struct Tampered {
106 T oldWidgetValue;
107 decltype(std::declval<T>().resolveMask()) resolveMask;
108
109 // only call this function on an rvalue *this (it mangles oldWidgetValue)
110 T reverted(T current) && {
111 oldWidgetValue.setResolveMask(oldWidgetValue.resolveMask() & resolveMask);
112 current.setResolveMask(current.resolveMask() & ~resolveMask);
113 current.resolve(oldWidgetValue);
114 current.setResolveMask(current.resolveMask() | oldWidgetValue.resolveMask());
115 return current;
116 }
117 };
118
119private:
120 QStyleKitStylePrivate();
121
122 bool loadStyle();
123 void updateStyle();
124
125 QQStyleKitStyle *ensureDefaultStyle();
126 QQStyleKitStyle *effectiveStyle() const;
127
128 void unsetStyleFont(QWidget *widget);
129 void setStyleFont(QWidget *widget, const QFont &styleFont);
130 void refreshStyleFont(QWidget *widget);
131
132 void unsetStylePalette(QWidget *widget);
133 void setStylePalette(QWidget *widget, const QPalette &stylePalette) const;
134 void refreshStylePalette(QWidget *widget);
135
136 QQStyleKitReader *readerForWidget(const QWidget *widget) const;
137 void cleanupWidgetReader(const QWidget *widget) const;
138
139 QQStyleKitReader *readerForItemViewItem(const QWidget *widget, quint64 itemKey) const;
140 void cleanupItemViewItemReaders(const QWidget *widget) const;
141 static quint64 itemViewItemKeyForOption(const QStyleOption *opt);
142
143 QQStyleKitReader *ensureSharedReader() const;
144
145 QQSK::State resolvedStateFor(QQStyleKitReader::ControlType type, QStyle::State state) const;
146
147 QQStyleKitResolved resolve(const QWidget *w, QQStyleKitReader::ControlType type, QStyle::State state) const;
148 QQStyleKitResolved resolveItemViewItem(const QWidget *w, const QStyleOption *opt,
149 QQStyleKitReader::ControlType type, QStyle::State state) const;
150
151 QQStyleKitLayoutResolved resolveLayout(QQStyleKitReader::ControlType type,
152 QStyle::State state) const;
153
154 const ControlMetrics &metricsFor(QQStyleKitReader::ControlType type, QQSK::State state) const;
155 void clearMetricsCache();
156
157 ControlMetrics metricsForReader(QQStyleKitReader *reader) const;
158
159 void drawControlIndicator(const QQStyleKitDelegateProperties *indicator, const QRectF &rect, QPainter *p) const;
160 void drawControlText(const QQStyleKitTextProperties *textProps, const QFont &font,
161 const QRect &rect, const QString &text, uint textFlags,
162 QPainter *p,
163 Qt::Alignment defaultAlignment = Qt::AlignHCenter | Qt::AlignVCenter) const;
164 void drawStyledItemRect(const QQStyleKitDelegateProperties *, const QRectF &rect, QPainter *p) const;
165 void drawStyledItemImage(const QQStyleKitImageProperties *image, const QRectF &rect,
166 qreal opacity, QPainter *p) const;
167
168 QRect getAlignedRectInContainer(const QRect &container, const QSize &indicatorSize,
169 uint alignment, const QMargins &padding,
170 const QMargins &indicatorMargins) const;
171
172 QQmlEngine *qmlEngine = nullptr;
173 QQStyleKitStyle *style = nullptr;
174 QQStyleKitStyle *defaultStyle = nullptr;
175 // Reader for static metric reads
176 mutable QQStyleKitReader *sharedReader = nullptr;
177 // Per-widget readers
178 // Separate per-widget readers are used in order to support transitions,
179 // as each reader provides interpolated property values during these transitions.
180 mutable QHash<const QWidget *, QQStyleKitReader *> widgetReaders;
181 // Per-item readers for item-view items
183 // Cache of resolved metrics per control type and state
184 mutable QHash<MetricsCacheKey, ControlMetrics> metricsCache;
187 // Widgets whose viewport autoFillBackground we disabled in polish(); restored in unpolish()
188 QSet<const QWidget *> autoFillDisabledWidgets;
189 QString stylePath;
190};
191
192QT_END_NAMESPACE
193
194#endif // QSTYLEKITSTYLE_P_H
\inmodule QtLabsStyleKit
Combined button and popup list for selecting options.
static qreal resolvedImplicitWidth(const QQStyleKitDelegateProperties *element, qreal availableW)
static QWidget * managedViewport(QWidget *widget)
static QMargins elementMargins(const QQStyleKitDelegateProperties *element)
static uint resolvedAlignment(uint raw, Qt::Alignment hDefault, Qt::Alignment vDefault)
static bool isSelfPaintingWidget(const QWidget *widget)
static qreal resolvedImplicitHeight(const QQStyleKitDelegateProperties *element, qreal avilableH)
static QUrl urlFromStylePath(const QString &filePath)
static const QWidget * containerWidget(const QWidget *w)