Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickstyleitem_p.h
Go to the documentation of this file.
1
// Copyright (C) 2020 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
QQUICKSTYLEITEM_P_H
6
#
define
QQUICKSTYLEITEM_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
<
private
/
qqc2qnativestyle_p
.
h
>
20
#
include
<
private
/
qqc2qstyle_p
.
h
>
21
#
include
<
private
/
qqc2qstyleoption_p
.
h
>
22
#
include
<
private
/
qquickcontrol_p
.
h
>
23
#
include
<
private
/
qquickitem_p
.
h
>
24
25
#
include
<
QtQml
/
qqml
.
h
>
26
#
include
<
QtQml
/
qqmlinfo
.
h
>
27
28
#
include
<
QtCore
/
qdebug
.
h
>
29
#
include
<
QtCore
/
qpointer
.
h
>
30
31
// Work-around for now, to avoid creator getting confused
32
// about missing macros. Should eventually be defined
33
// in qt declarative somewhere I assume.
34
#
ifndef
QML_NAMED_ELEMENT
35
#
define
QML_NAMED_ELEMENT
(
NAME
)
36
#
define
QML_UNCREATABLE
(
NAME
)
37
#
endif
38
39
#
ifdef
QT_DEBUG
40
#
define
qqc2Debug
(
)
if
(
m_debugFlags
.
testFlag
(
Debug
)
)
qDebug
(
)
<<
__FUNCTION__
<<
":"
41
#
define
qqc2Info
(
)
if
(
m_debugFlags
.
testFlag
(
Info
)
)
qDebug
(
)
<<
__FUNCTION__
<<
":"
42
#
define
qqc2InfoHeading
(
HEADING
)
if
(
m_debugFlags
.
testFlag
(
Info
)
)
qDebug
(
)
<<
"--------"
<<
HEADING
<<
"--------"
43
#
else
44
#
define
qqc2Debug
(
)
if
(
false
)
qDebug
(
)
45
#
define
qqc2Info
(
)
if
(
false
)
qDebug
(
)
46
#
define
qqc2InfoHeading
(
HEADING
)
if
(
false
)
qDebug
(
)
47
#
endif
48
49
QT_BEGIN_NAMESPACE
50
51
using
namespace
QQC2;
52
53
class
QQuickStyleMargins
54
{
55
Q_GADGET
56
57
Q_PROPERTY(
int
left READ left())
58
Q_PROPERTY
(
int
top
READ
top
())
59
Q_PROPERTY
(
int
right
READ
right
())
60
Q_PROPERTY
(
int
bottom
READ
bottom
())
61
62
QML_NAMED_ELEMENT
(stylemargins)
63
QML_UNCREATABLE
(
""
)
64
65
public
:
66
QQuickStyleMargins
() {}
67
QQuickStyleMargins
(
const
QQuickStyleMargins
&
other
) :
m_margins
(
other
.
m_margins
) {}
68
QQuickStyleMargins
(
const
QMargins
&
margins
) :
m_margins
(
margins
) {}
69
QQuickStyleMargins
(
const
QRect
&
outer
,
const
QRect
&
inner
)
70
{
71
const
int
left
=
inner
.
left
() -
outer
.
left
();
72
const
int
top
=
inner
.
top
() -
outer
.
top
();
73
const
int
right
=
outer
.
right
() -
inner
.
right
();
74
const
int
bottom
=
outer
.
bottom
() -
inner
.
bottom
();
75
m_margins
=
QMargins
(
left
,
top
,
right
,
bottom
);
76
}
77
78
inline
void
operator
=(
const
QQuickStyleMargins
&
other
) {
m_margins
=
other
.
m_margins
; }
79
inline
bool
operator
==(
const
QQuickStyleMargins
&
other
)
const
{
return
other
.
m_margins
==
m_margins
; }
80
inline
bool
operator
!=(
const
QQuickStyleMargins
&
other
)
const
{
return
other
.
m_margins
!=
m_margins
; }
81
82
inline
int
left
()
const
{
return
m_margins
.
left
(); }
83
inline
int
right
()
const
{
return
m_margins
.
right
(); }
84
inline
int
top
()
const
{
return
m_margins
.
top
(); }
85
inline
int
bottom
()
const
{
return
m_margins
.
bottom
(); }
86
87
QMargins
m_margins
;
88
};
89
90
QDebug
operator
<<(QDebug debug,
const
QQuickStyleMargins
&padding);
91
92
struct
StyleItemGeometry
93
{
94
/*
95
A QQuickStyleItem is responsible for drawing a control, or a part of it.
96
97
'minimumSize' should be the minimum possible size that the item can
98
have _without_ taking content size into consideration (and still render
99
correctly). This will also be the size of the image that the item is drawn
100
to, unless QQuickStyleItem::useNinePatchImage is set to false. In that
101
case, the size of the image will be set to the size of the item instead
102
(which is set from QML, and will typically be the same as the size of the control).
103
The default way to calculate minimumSize is to call style()->sizeFromContents()
104
with an empty content size. This is not always well supported by the legacy QStyle
105
implementation, which means that you might e.g get an empty size in return.
106
For those cases, the correct solution is to go into the specific platform style
107
and change it so that it returns a valid size also for this special case.
108
109
'implicitSize' should reflect the preferred size of the item, taking the
110
given content size (as set from QML) into account. But not all controls
111
have contents (slider), and for many controls, the content/label is instead
112
placed outside the item/background image (radiobutton). In both cases, the
113
size of the item will not include the content size, and implicitSize can
114
usually be set equal to minimumSize instead.
115
116
'contentRect' should be the free space where the contents can be placed. Note that
117
this rect doesn't need to have the same size as the contentSize provided as input
118
to the style item. Instead, QStyle can typically calculate a rect that is bigger, to
119
e.g center the contents inside the control.
120
121
'layoutRect' can be set to shift the position of the whole control so
122
that aligns correctly with the other controls. This is important for
123
controls that draws e.g shadows or focus rings. Such adornments should
124
be painted, but not be included when aligning the controls.
125
*/
126
127
QSize
minimumSize
;
128
QSize
implicitSize
;
129
QRect
contentRect
;
130
QRect
layoutRect
;
// If invalid, there are no layout margins!
131
QMargins
ninePatchMargins
;
132
qreal
focusFrameRadius
;
133
};
134
135
QDebug
operator
<<(QDebug debug,
const
StyleItemGeometry
&cg);
136
137
class
QQuickStyleItem
:
public
QQuickItem
138
{
139
Q_OBJECT
140
141
// Input
142
Q_PROPERTY(QQuickItem *control MEMBER m_control NOTIFY controlChanged)
143
Q_PROPERTY
(
qreal
contentWidth
READ
contentWidth
WRITE
setContentWidth
)
144
Q_PROPERTY
(
qreal
contentHeight
READ
contentHeight
WRITE
setContentHeight
)
145
Q_PROPERTY
(
bool
useNinePatchImage
MEMBER
m_useNinePatchImage
)
146
Q_PROPERTY
(
OverrideState
overrideState
MEMBER
m_overrideState
)
147
148
// Output
149
Q_PROPERTY
(
QQuickStyleMargins
contentPadding
READ
contentPadding
()
NOTIFY
contentPaddingChanged
)
150
Q_PROPERTY
(
QQuickStyleMargins
layoutMargins
READ
layoutMargins
()
NOTIFY
layoutMarginsChanged
)
151
Q_PROPERTY
(
QSize
minimumSize
READ
minimumSize
()
NOTIFY
minimumSizeChanged
)
152
Q_PROPERTY
(
int
transitionDuration
MEMBER
m_transitionDuration
CONSTANT
)
153
154
QML_NAMED_ELEMENT
(StyleItem)
155
QML_UNCREATABLE
(
"StyleItem is an abstract base class."
)
156
157
public
:
158
enum
DirtyFlag
{
159
Nothing
= 0,
160
Geometry
,
161
Image
,
162
Everything
= 255
163
};
164
Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
165
166
enum
OverrideState
{
167
None
= 0,
168
AlwaysHovered
,
169
NeverHovered
,
170
AlwaysSunken
171
};
172
Q_ENUM
(
OverrideState
)
173
174
175
#
ifdef
QT_DEBUG
176
enum
DebugFlag
{
177
NoDebug
= 0x000,
178
Debug
= 0x001,
179
Info
= 0x002,
180
ImageRect
= 0x004,
181
ContentRect
= 0x008,
182
LayoutRect
= 0x010,
183
Unscaled
= 0x020,
184
InputContentSize
= 0x040,
185
DontUseNinePatchImage
= 0x080,
186
NinePatchMargins
= 0x100,
187
SaveImage
= 0x200,
188
};
189
Q_DECLARE_FLAGS
(
DebugFlags
,
DebugFlag
)
190
Q_FLAG
(
DebugFlags
)
191
#
endif
192
193
explicit
QQuickStyleItem
(QQuickItem *parent =
nullptr
);
194
~
QQuickStyleItem
()
override
;
195
196
qreal
contentWidth
();
197
void
setContentWidth
(qreal contentWidth);
198
qreal
contentHeight
();
199
void
setContentHeight
(qreal contentHeight);
200
201
QQuickStyleMargins
contentPadding
()
const
;
202
QQuickStyleMargins
layoutMargins
()
const
;
203
QSize
minimumSize
()
const
;
204
QSize
imageSize
()
const
;
205
qreal
focusFrameRadius
()
const
;
206
207
Q_INVOKABLE
virtual
QFont
styleFont
(
QQuickItem
*
control
)
const
;
208
209
void
markGeometryDirty
();
210
void
markImageDirty
();
211
212
Q_SIGNALS
:
213
void
controlChanged
();
214
void
contentPaddingChanged
();
215
void
layoutMarginsChanged
();
216
void
fontChanged
();
217
void
minimumSizeChanged
();
218
219
protected
:
220
void
componentComplete
()
override
;
221
QSGNode
*
updatePaintNode
(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData)
override
;
222
void
geometryChange
(
const
QRectF &newGeometry,
const
QRectF &oldGeometry)
override
;
223
void
itemChange
(ItemChange change,
const
ItemChangeData &data)
override
;
224
void
updatePolish
()
override
;
225
226
virtual
void
connectToControl
()
const
;
227
virtual
void
paintEvent
(QPainter *painter)
const
= 0;
228
virtual
StyleItemGeometry
calculateGeometry
() = 0;
229
230
static
QStyle
::
State
controlSize
(QQuickItem *item);
231
void
initStyleOptionBase
(QStyleOption &styleOption)
const
;
232
233
inline
QSize
contentSize
()
const
{
return
QSize(qCeil(m_contentSize.width()), qCeil(m_contentSize.height())); }
234
inline
static
QStyle
*
style
() {
return
QQC2::style(); }
235
236
template
<
class
T>
inline
const
T*
control
()
const
{
237
#
ifdef
QT_DEBUG
238
if
(!
dynamic_cast
<T *>(m_control.data())) {
239
qmlWarning(
this
) <<
"control property is not of correct type"
;
240
Q_UNREACHABLE();
241
}
242
#
endif
243
return
static_cast
<T *>(m_control.data());
244
}
245
246
#
ifdef
QT_DEBUG
247
DebugFlags
m_debugFlags
=
NoDebug
;
248
#
endif
249
OverrideState
m_overrideState
=
None
;
250
251
private
:
252
bool
event
(QEvent *event)
override
;
253
inline
void
updateGeometry();
254
inline
void
paintControlToImage();
255
256
int
dprAlignedSize(
const
int
size)
const
;
257
258
#
ifdef
QT_DEBUG
259
void
addDebugInfo
();
260
#
endif
261
262
private
:
263
QPointer<QQuickItem> m_control;
264
QImage m_paintedImage;
265
StyleItemGeometry
m_styleItemGeometry;
266
QSizeF m_contentSize;
267
268
DirtyFlags m_dirty =
Everything
;
269
bool
m_useNinePatchImage =
true
;
270
bool
m_polishing =
false
;
271
mutable
QQuickWindow *m_connectedWindow =
nullptr
;
272
273
#
ifdef
Q_OS_MACOS
274
int
m_transitionDuration
= 150;
275
#
else
276
int
m_transitionDuration = 400;
277
#
endif
278
279
private
:
280
friend
class
QtQuickControls2MacOSStylePlugin
;
281
};
282
283
Q_DECLARE_OPERATORS_FOR_FLAGS(
QQuickStyleItem
::DirtyFlags)
284
285
#
ifdef
QT_DEBUG
286
Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickStyleItem::DebugFlags)
287
#
endif
288
289
QT_END_NAMESPACE
290
291
#
endif
// QQUICKSTYLEITEM_P_H
QQuickStyleItem
Definition
qquickstyleitem_p.h:138
QQuickStyleItem::connectToControl
virtual void connectToControl() const
Definition
qquickstyleitem.cpp:81
QQuickStyleItem::geometryChange
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
Definition
qquickstyleitem.cpp:221
QQuickStyleItem::layoutMarginsChanged
void layoutMarginsChanged()
QQuickStyleItem::fontChanged
void fontChanged()
QQuickStyleItem::focusFrameRadius
qreal focusFrameRadius() const
Definition
qquickstyleitem.cpp:540
QQuickStyleItem::calculateGeometry
virtual StyleItemGeometry calculateGeometry()=0
QQuickStyleItem::m_overrideState
OverrideState m_overrideState
Definition
qquickstyleitem_p.h:249
QQuickStyleItem::paintEvent
virtual void paintEvent(QPainter *painter) const =0
QQuickStyleItem::imageSize
QSize imageSize() const
Definition
qquickstyleitem.cpp:533
QQuickStyleItem::itemChange
void itemChange(ItemChange change, const ItemChangeData &data) override
Called when change occurs for this item.
Definition
qquickstyleitem.cpp:232
QQuickStyleItem::control
const T * control() const
Definition
qquickstyleitem_p.h:236
QQuickStyleItem::minimumSizeChanged
void minimumSizeChanged()
QQuickStyleItem::markGeometryDirty
void markGeometryDirty()
Definition
qquickstyleitem.cpp:99
QQuickStyleItem::markImageDirty
void markImageDirty()
Definition
qquickstyleitem.cpp:92
QQuickStyleItem::contentWidth
qreal contentWidth()
QQuickStyleItem::contentSize
QSize contentSize() const
Definition
qquickstyleitem_p.h:233
QQuickStyleItem::updatePolish
void updatePolish() override
This function should perform any layout as required for this item.
Definition
qquickstyleitem.cpp:397
QQuickStyleItem::setContentHeight
void setContentHeight(qreal contentHeight)
Definition
qquickstyleitem.cpp:495
QQuickStyleItem::contentPadding
QQuickStyleMargins contentPadding() const
Definition
qquickstyleitem.cpp:504
QQuickStyleItem::~QQuickStyleItem
~QQuickStyleItem() override
Definition
qquickstyleitem.cpp:77
QQuickStyleItem::layoutMargins
QQuickStyleMargins layoutMargins() const
Definition
qquickstyleitem.cpp:510
QQuickStyleItem::contentPaddingChanged
void contentPaddingChanged()
QQuickStyleItem::minimumSize
QSize minimumSize() const
Definition
qquickstyleitem.cpp:526
QQuickStyleItem::controlSize
static QStyle::State controlSize(QQuickItem *item)
Definition
qquickstyleitem.cpp:164
QQuickStyleItem::setContentWidth
void setContentWidth(qreal contentWidth)
Definition
qquickstyleitem.cpp:481
QQuickStyleItem::OverrideState
OverrideState
Definition
qquickstyleitem_p.h:166
QQuickStyleItem::None
@ None
Definition
qquickstyleitem_p.h:167
QQuickStyleItem::AlwaysHovered
@ AlwaysHovered
Definition
qquickstyleitem_p.h:168
QQuickStyleItem::NeverHovered
@ NeverHovered
Definition
qquickstyleitem_p.h:169
QQuickStyleItem::AlwaysSunken
@ AlwaysSunken
Definition
qquickstyleitem_p.h:170
QQuickStyleItem::contentHeight
qreal contentHeight()
QQuickStyleItem::initStyleOptionBase
void initStyleOptionBase(QStyleOption &styleOption) const
Definition
qquickstyleitem.cpp:180
QQuickStyleItem::QQuickStyleItem
QQuickStyleItem(QQuickItem *parent=nullptr)
Definition
qquickstyleitem.cpp:71
QQuickStyleItem::style
static QStyle * style()
Definition
qquickstyleitem_p.h:234
QQuickStyleItem::updatePaintNode
QSGNode * updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
Definition
qquickstyleitem.cpp:106
QQuickStyleItem::componentComplete
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
Definition
qquickstyleitem.cpp:464
QQuickStyleItem::event
bool event(QEvent *event) override
\reimp
Definition
qquickstyleitem.cpp:255
QQuickStyleMargins
Definition
qquickstyleitem_p.h:54
QtQuickControls2MacOSStylePlugin
Definition
qtquickcontrols2macosstyleplugin.cpp:16
QML_UNCREATABLE
#define QML_UNCREATABLE(REASON)
Definition
qqmlintegration.h:69
QML_NAMED_ELEMENT
#define QML_NAMED_ELEMENT(NAME)
Definition
qqmlintegration.h:66
operator<<
QDebug operator<<(QDebug debug, const StyleItemGeometry &cg)
Definition
qquickstyleitem.cpp:37
effectiveWindow
static QWindow * effectiveWindow(QQuickWindow *window)
Definition
qquickstyleitem.cpp:174
qqc2Info
#define qqc2Info()
Definition
qquickstyleitem_p.h:45
operator<<
QDebug operator<<(QDebug debug, const QQuickStyleMargins &padding)
Definition
qquickstyleitem.cpp:24
qqc2InfoHeading
#define qqc2InfoHeading(HEADING)
Definition
qquickstyleitem_p.h:46
StyleItemGeometry
Definition
qquickstyleitem_p.h:93
StyleItemGeometry::contentRect
QRect contentRect
Definition
qquickstyleitem_p.h:129
StyleItemGeometry::minimumSize
QSize minimumSize
Definition
qquickstyleitem_p.h:127
StyleItemGeometry::focusFrameRadius
qreal focusFrameRadius
Definition
qquickstyleitem_p.h:132
StyleItemGeometry::implicitSize
QSize implicitSize
Definition
qquickstyleitem_p.h:128
StyleItemGeometry::layoutRect
QRect layoutRect
Definition
qquickstyleitem_p.h:130
StyleItemGeometry::ninePatchMargins
QMargins ninePatchMargins
Definition
qquickstyleitem_p.h:131
qtdeclarative
src
quickcontrols
quicknativestyle
items
qquickstyleitem_p.h
Generated on
for Qt by
1.18.0