7#include <QtQuick/private/qquickrectangle_p.h>
8#include <QtQuick/private/qquickimplicitsizeitem_p_p.h>
9#include <QtQuickControls2Impl/private/qquickcolorimage_p.h>
20 return m_delegateProperties;
25 if (m_delegateProperties == delegateProperties)
28 if (m_delegateProperties)
29 disconnect(m_delegateProperties,
nullptr,
this,
nullptr);
31 m_delegateProperties = delegateProperties;
33 if (!qmlEngine(
this)) {
34 qmlWarning(
this) <<
"Unable to draw delegate: no QQmlEngine found";
39 maybeCreateGradient();
43 connect(m_delegateProperties, &QQStyleKitDelegateProperties::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
44 connect(m_delegateProperties, &QQStyleKitDelegateProperties::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
46 emit delegatePropertiesChanged();
51 if (!m_delegateProperties)
55
56
57
58
59
60 const qreal impWidthInStyle = m_delegateProperties->implicitWidth();
61 const qreal impHeightInStyle = m_delegateProperties->implicitHeight();
62 setImplicitWidth(impWidthInStyle > 0 || !m_imageOverlay ? impWidthInStyle : m_imageOverlay->implicitWidth());
63 setImplicitHeight(impHeightInStyle > 0 || !m_imageOverlay ? impHeightInStyle : m_imageOverlay->implicitHeight());
70 if (!m_delegateProperties)
72 if (m_delegateProperties->color().alpha() == 0) {
73 connect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
78 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::colorChanged,
81 QQmlEngine *engine = qmlEngine(
this);
83 static QQmlComponent *component =
nullptr;
84 if (!component || component->engine() != engine) {
86 component =
new QQmlComponent(engine);
87 const QString qmlCode = QString::fromUtf8(R"(
88 import QtQuick
89 Rectangle {
90 z: -3
91 width: parent.width
92 height: parent.height
93 visible: delegateProperties.visible
94 color: delegateProperties.color
95 topLeftRadius: delegateProperties.topLeftRadius
96 topRightRadius: delegateProperties.topRightRadius
97 bottomLeftRadius: delegateProperties.bottomLeftRadius
98 bottomRightRadius: delegateProperties.bottomRightRadius
99 border.width: delegateProperties.border.width
100 border.color: delegateProperties.border.color
101 }
102 )");
103 component->setData(qmlCode.toUtf8(), QUrl());
104 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
107 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
108 m_colorOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
109 Q_ASSERT(m_colorOverlay);
110 m_colorOverlay->setParent(
this);
111 m_colorOverlay->setParentItem(
this);
112 component->completeCreate();
118
119
120
121
122 if (m_gradientOverlay)
124 if (!m_delegateProperties)
126 if (!m_delegateProperties->gradient()) {
127 connect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
132 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::gradientChanged,
135 QQmlEngine *engine = qmlEngine(
this);
137 static QQmlComponent *component =
nullptr;
138 if (!component || component->engine() != engine) {
140 component =
new QQmlComponent(engine);
141 const QString qmlCode = QString::fromUtf8(R"(
142 import QtQuick
143 Rectangle {
144 z: -2
145 width: parent.width
146 height: parent.height
147 visible: delegateProperties.visible
148 color: "transparent"
149 gradient: delegateProperties.gradient
150 topLeftRadius: delegateProperties.topLeftRadius
151 topRightRadius: delegateProperties.topRightRadius
152 bottomLeftRadius: delegateProperties.bottomLeftRadius
153 bottomRightRadius: delegateProperties.bottomRightRadius
154 border.width: delegateProperties.border.width
155 border.color: delegateProperties.border.color
156 }
157 )");
158 component->setData(qmlCode.toUtf8(), QUrl());
159 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
162 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
163 m_gradientOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
164 Q_ASSERT(m_gradientOverlay);
165 m_gradientOverlay->setParent(
this);
166 m_gradientOverlay->setParentItem(
this);
167 component->completeCreate();
174 if (!m_delegateProperties)
176 if (m_delegateProperties->image()->source().isEmpty()
177 || m_delegateProperties->image()->color().alpha() == 0) {
178 connect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
185 disconnect(m_delegateProperties->image(), &QQStyleKitImageProperties::sourceChanged,
190 QQmlEngine *engine = qmlEngine(
this);
192 static QQmlComponent *component =
nullptr;
193 if (!component || component->engine() != engine) {
195 component =
new QQmlComponent(engine);
196 const QString qmlCode = QString::fromUtf8(R"(
197 import QtQuick.Controls.impl
198 ColorImage {
199 z: -1
200 width: parent.width
201 height: parent.height
202 visible: delegateProperties.visible
203 color: delegateProperties.image.color
204 source: delegateProperties.image.source
205 fillMode: delegateProperties.image.fillMode
206 }
207 )");
208 component->setData(qmlCode.toUtf8(), QUrl());
209 Q_ASSERT_X(!component->isError(),
__FUNCTION__, component->errorString().toUtf8().constData());
212 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
213 m_imageOverlay = qobject_cast<QQuickItem*>(component->beginCreate(ctx));
214 m_imageOverlay->setParent(
this);
215 m_imageOverlay->setParentItem(
this);
216 component->completeCreate();
218 updateImplicitSize();
219 connect(m_imageOverlay, &QQuickItem::implicitWidthChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
220 connect(m_imageOverlay, &QQuickItem::implicitHeightChanged,
this, &
QQStyleKitDelegate::updateImplicitSize);
225#include "moc_qqstylekitdelegate_p.cpp"
QQStyleKitDelegateProperties * delegateProperties() const
void setDelegateProperties(QQStyleKitDelegateProperties *delegateProperties)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Combined button and popup list for selecting options.