7#include <QtQuick/private/qquickrectangle_p.h>
8#include <QtQuick/private/qquickimplicitsizeitem_p_p.h>
9#include <QtQuickControls2Impl/private/qquickcolorimage_p.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
74 return m_delegateProperties;
79 if (m_delegateProperties == delegateStyle)
82 if (m_delegateProperties)
83 disconnect(m_delegateProperties,
nullptr,
this,
nullptr);
85 m_delegateProperties = delegateStyle;
87 if (!qmlEngine(
this)) {
88 qmlWarning(
this) <<
"Unable to draw delegate: no QQmlEngine found";
93 maybeCreateGradient();
97 connect(m_delegateProperties, &QQStyleKitDelegateProperties::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
98 connect(m_delegateProperties, &QQStyleKitDelegateProperties::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
100 emit delegateStyleChanged();
105 if (!m_delegateProperties)
109
110
111
112
113
114 const qreal impWidthInStyle = qMax(m_delegateProperties->minimumWidth(), m_delegateProperties->implicitWidth());
115 const qreal impHeightInStyle = m_delegateProperties->implicitHeight();
116 setImplicitWidth(impWidthInStyle > 0 || !m_imageOverlay ? impWidthInStyle : m_imageOverlay->implicitWidth());
117 setImplicitHeight(impHeightInStyle > 0 || !m_imageOverlay ? impHeightInStyle : m_imageOverlay->implicitHeight());
124 if (!m_delegateProperties)
126 if (m_delegateProperties->color().alpha() == 0
127 && (m_delegateProperties->border()->color().alpha() == 0
128 || m_delegateProperties->border()->width() == 0)) {
130 connect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
134 connect(m_delegateProperties->border(), &QQStyleKitBorderProperties::widthChanged,
139 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
143 disconnect(m_delegateProperties->border(), &QQStyleKitBorderProperties::widthChanged,
146 QQmlEngine *engine = qmlEngine(
this);
148 static QQmlComponent *component =
nullptr;
149 if (!component || component->engine() != engine) {
151 component =
new QQmlComponent(engine);
152 const QString qmlCode = QString::fromUtf8(R"(
153 import QtQuick
154 Rectangle {
155 z: -3
156 width: parent.width
157 height: parent.height
158 color: delegateStyle.color
159 opacity: delegateStyle.opacity
160 topLeftRadius: delegateStyle.topLeftRadius
161 topRightRadius: delegateStyle.topRightRadius
162 bottomLeftRadius: delegateStyle.bottomLeftRadius
163 bottomRightRadius: delegateStyle.bottomRightRadius
164 border.width: delegateStyle.border.width
165 border.color: delegateStyle.border.color
166 }
167 )");
168 component->setData(qmlCode.toUtf8(), QUrl());
169 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
172 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
173 m_colorOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
174 Q_ASSERT(m_colorOverlay);
175 m_colorOverlay->setParent(
this);
176 m_colorOverlay->setParentItem(
this);
177 component->completeCreate();
183
184
185
186
187 if (m_gradientOverlay)
189 if (!m_delegateProperties)
191 if (!m_delegateProperties->gradient()) {
192 connect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
197 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
200 QQmlEngine *engine = qmlEngine(
this);
202 static QQmlComponent *component =
nullptr;
203 if (!component || component->engine() != engine) {
205 component =
new QQmlComponent(engine);
206 const QString qmlCode = QString::fromUtf8(R"(
207 import QtQuick
208 Rectangle {
209 z: -2
210 width: parent.width
211 height: parent.height
212 color: "transparent"
213 gradient: delegateStyle.gradient
214 topLeftRadius: delegateStyle.topLeftRadius
215 topRightRadius: delegateStyle.topRightRadius
216 bottomLeftRadius: delegateStyle.bottomLeftRadius
217 bottomRightRadius: delegateStyle.bottomRightRadius
218 border.width: delegateStyle.border.width
219 border.color: delegateStyle.border.color
220 }
221 )");
222 component->setData(qmlCode.toUtf8(), QUrl());
223 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
226 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
227 m_gradientOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
228 Q_ASSERT(m_gradientOverlay);
229 m_gradientOverlay->setParent(
this);
230 m_gradientOverlay->setParentItem(
this);
231 component->completeCreate();
238 if (!m_delegateProperties)
240 if (m_delegateProperties->image()->source().isEmpty()
241 || m_delegateProperties->image()->color().alpha() == 0) {
242 connect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
249 disconnect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
254 QQmlEngine *engine = qmlEngine(
this);
256 static QQmlComponent *component =
nullptr;
257 if (!component || component->engine() != engine) {
259 component =
new QQmlComponent(engine);
260 const QString qmlCode = QString::fromUtf8(R"(
261 import QtQuick.Controls.impl
262 ColorImage {
263 z: -1
264 width: parent.width
265 height: parent.height
266 color: delegateStyle.image.color
267 source: delegateStyle.image.source
268 fillMode: delegateStyle.image.fillMode
269 }
270 )");
271 component->setData(qmlCode.toUtf8(), QUrl());
272 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
275 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
276 m_imageOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
277 m_imageOverlay->setParent(
this);
278 m_imageOverlay->setParentItem(
this);
279 component->completeCreate();
281 updateImplicitSize();
282 connect(m_imageOverlay, &QQuickItem::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
283 connect(m_imageOverlay, &QQuickItem::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
288#include "moc_qqstylekitdelegate_p.cpp"
void setDelegateStyle(QQStyleKitDelegateProperties *delegateStyle)
QQStyleKitDelegateProperties * delegateStyle() const
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Combined button and popup list for selecting options.