4#include <QtQuick/private/qquickitem_p.h>
7#include "../qqstylekitcontrolproperties_p.h"
11QQmlComponent* QQStyleKitDelegateContainer::s_defaultDelegateComponent =
nullptr;
24 if (m_delegateInstance)
25 disconnect(m_delegateInstance,
nullptr,
this,
nullptr);
30 return m_delegateProperties;
35 if (m_delegateProperties == delegateProperties)
38 if (m_delegateProperties) {
40
41
42
43 qmlWarning(
this) <<
"Changing delegateStyle on StyleKitContainer is not supported.";
47 m_delegateProperties = delegateProperties;
48 emit delegateStyleChanged();
58 if (m_control == control)
61 emit quickControlChanged();
66 return m_delegateInstance;
71 return m_delegateComponent == s_defaultDelegateComponent;
76 qreal implicitWidth = 0;
77 qreal implicitHeight = 0;
79 if (m_delegateInstance) {
81
82 implicitWidth = m_delegateInstance->implicitWidth();
83 implicitHeight = m_delegateInstance->implicitHeight();
84 }
else if (m_delegateProperties) {
86
87
88 implicitWidth = qMax(m_delegateProperties->minimumWidth(), m_delegateProperties->implicitWidth());
89 implicitHeight = m_delegateProperties->implicitHeight();
92 setImplicitWidth(implicitWidth);
93 setImplicitHeight(implicitHeight);
98 if (m_delegateInstance)
100 if (!m_delegateProperties)
103 if (!m_delegateProperties->visible()) {
104 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
109 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
114 if (QQmlComponent *delegateComponent = m_delegateProperties->delegate()) {
115 m_delegateComponent = delegateComponent;
117 if (!s_defaultDelegateComponent || s_defaultDelegateComponent->engine() != qmlEngine(
this)) {
118 delete s_defaultDelegateComponent;
119 QQmlEngine *engine = qmlEngine(
this);
120 s_defaultDelegateComponent =
new QQmlComponent(engine);
121 const QString qmlCode = QString::fromUtf8(R"(
122 import QtQuick
123 import Qt.labs.StyleKit
124 StyledItem {
125 width: parent.width
126 height: parent.height
127 }
128 )");
129 s_defaultDelegateComponent->setData(qmlCode.toUtf8(), QUrl());
130 Q_ASSERT_X(!s_defaultDelegateComponent->isError(),
__FUNCTION__,
131 s_defaultDelegateComponent->errorString().toUtf8().constData());
133 m_delegateComponent = s_defaultDelegateComponent;
136 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
137 m_delegateInstance = qobject_cast<QQuickItem*>(m_delegateComponent->beginCreate(ctx));
138 Q_ASSERT(m_delegateInstance);
139 m_delegateInstance->setParent(
this);
140 m_delegateInstance->setParentItem(
this);
141 m_delegateInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
142 m_delegateInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
143 m_delegateComponent->completeCreate();
145 updateImplicitSize();
150 emit usingDefaultDelegateChanged();
155 if (m_shadowInstance)
157 if (!m_delegateProperties)
160 if (!m_delegateProperties->visible()) {
161 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
165 if (!m_delegateProperties->shadow()->visible()) {
166 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
170 if (m_delegateProperties->shadow()->color().alpha() == 0) {
171 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
175 if (m_delegateProperties->shadow()->opacity() == 0) {
176 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
181 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
183 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
185 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
187 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
190 if (QQmlComponent *shadowComponent = m_delegateProperties->shadow()->delegate()) {
191 m_shadowComponent = shadowComponent;
193 if (!s_defaultShadowComponent || s_defaultShadowComponent->engine() != qmlEngine(
this)) {
194 delete s_defaultShadowComponent;
195 QQmlEngine *engine = qmlEngine(
this);
196 s_defaultShadowComponent =
new QQmlComponent(engine);
197 const QString qmlCode = QString::fromUtf8(R"(
198 import Qt.labs.StyleKit.impl
199 Shadow {}
200 )");
201 s_defaultShadowComponent->setData(qmlCode.toUtf8(), QUrl());
202 Q_ASSERT_X(!s_defaultShadowComponent->isError(),
__FUNCTION__,
203 s_defaultShadowComponent->errorString().toUtf8().constData());
205 m_shadowComponent = s_defaultShadowComponent;
208 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
209 m_shadowInstance = qobject_cast<QQuickItem*>(m_shadowComponent->beginCreate(ctx));
210 Q_ASSERT(m_shadowInstance);
211 m_shadowInstance->setParent(
this);
212 m_shadowInstance->setParentItem(
this);
213 m_shadowInstance->setZ(-1);
214 m_shadowInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
215 m_shadowInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
216 m_shadowComponent->completeCreate();
221 QQuickItem::componentComplete();
222 Q_ASSERT(m_delegateProperties);
225 maybeCreateDelegate();
226 connect(m_delegateProperties, &QQStyleKitDelegateProperties::delegateChanged,
this, [
this]{
227 if (!m_delegateInstance) {
228 maybeCreateDelegate();
230 const QQmlComponent *newDelegateComp = m_delegateProperties->delegate();
231 if (m_delegateComponent == newDelegateComp)
233 if (!newDelegateComp && m_delegateComponent == s_defaultDelegateComponent) {
235
239 delete m_delegateInstance;
240 maybeCreateDelegate();
241 emit delegateInstanceChanged();
246 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::delegateChanged,
this, [
this]{
247 if (!m_shadowInstance) {
250 const QQmlComponent *newShadowComp = m_delegateProperties->shadow()->delegate();
251 if (m_shadowComponent == newShadowComp)
253 if (!newShadowComp && m_shadowComponent == s_defaultShadowComponent) {
255
259 delete m_shadowInstance;
264 updateImplicitSize();
269#include "moc_qqstylekitdelegatecontainer_p.cpp"
QQStyleKitDelegateProperties * delegateStyle() const
~QQStyleKitDelegateContainer() override
bool usingDefaultDelegate() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QObject * quickControl() const
void setQuickControl(QObject *control)
void setDelegateStyle(QQStyleKitDelegateProperties *delegateProperties)
QQuickItem * delegateInstance() const
Combined button and popup list for selecting options.