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 setImplicitWidth(m_delegateInstance ? m_delegateInstance->implicitWidth() : 0);
77 setImplicitHeight(m_delegateInstance ? m_delegateInstance->implicitHeight() : 0);
82 if (m_delegateInstance)
84 if (!m_delegateProperties)
87 if (!m_delegateProperties->visible()) {
88 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
93 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
98 if (QQmlComponent *delegateComponent = m_delegateProperties->delegate()) {
99 m_delegateComponent = delegateComponent;
101 if (!s_defaultDelegateComponent || s_defaultDelegateComponent->engine() != qmlEngine(
this)) {
102 delete s_defaultDelegateComponent;
103 QQmlEngine *engine = qmlEngine(
this);
104 s_defaultDelegateComponent =
new QQmlComponent(engine);
105 const QString qmlCode = QString::fromUtf8(R"(
106 import QtQuick
107 import Qt.labs.StyleKit
108 StyledItem {
109 width: parent.width
110 height: parent.height
111 }
112 )");
113 s_defaultDelegateComponent->setData(qmlCode.toUtf8(), QUrl());
114 Q_ASSERT_X(!s_defaultDelegateComponent->isError(),
__FUNCTION__,
115 s_defaultDelegateComponent->errorString().toUtf8().constData());
117 m_delegateComponent = s_defaultDelegateComponent;
120 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
121 m_delegateInstance = qobject_cast<QQuickItem*>(m_delegateComponent->beginCreate(ctx));
122 Q_ASSERT(m_delegateInstance);
123 m_delegateInstance->setParent(
this);
124 m_delegateInstance->setParentItem(
this);
125 m_delegateInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
126 m_delegateInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
127 m_delegateComponent->completeCreate();
129 updateImplicitSize();
134 emit usingDefaultDelegateChanged();
139 if (m_shadowInstance)
141 if (!m_delegateProperties)
144 if (!m_delegateProperties->visible()) {
145 connect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
149 if (!m_delegateProperties->shadow()->visible()) {
150 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
154 if (m_delegateProperties->shadow()->color().alpha() == 0) {
155 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
159 if (m_delegateProperties->shadow()->opacity() == 0) {
160 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
165 disconnect(m_delegateProperties, &QQStyleKitDelegateProperties::visibleChanged,
167 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::visibleChanged,
169 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::colorChanged,
171 disconnect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::opacityChanged,
174 if (QQmlComponent *shadowComponent = m_delegateProperties->shadow()->delegate()) {
175 m_shadowComponent = shadowComponent;
177 if (!s_defaultShadowComponent || s_defaultShadowComponent->engine() != qmlEngine(
this)) {
178 delete s_defaultShadowComponent;
179 QQmlEngine *engine = qmlEngine(
this);
180 s_defaultShadowComponent =
new QQmlComponent(engine);
181 const QString qmlCode = QString::fromUtf8(R"(
182 import Qt.labs.StyleKit.impl
183 Shadow {}
184 )");
185 s_defaultShadowComponent->setData(qmlCode.toUtf8(), QUrl());
186 Q_ASSERT_X(!s_defaultShadowComponent->isError(),
__FUNCTION__,
187 s_defaultShadowComponent->errorString().toUtf8().constData());
189 m_shadowComponent = s_defaultShadowComponent;
192 QQmlContext *ctx = QQmlEngine::contextForObject(
this);
193 m_shadowInstance = qobject_cast<QQuickItem*>(m_shadowComponent->beginCreate(ctx));
194 Q_ASSERT(m_shadowInstance);
195 m_shadowInstance->setParent(
this);
196 m_shadowInstance->setParentItem(
this);
197 m_shadowInstance->setZ(-1);
198 m_shadowInstance->setProperty(
"control", QVariant::fromValue(m_control.get()));
199 m_shadowInstance->setProperty(
"delegateStyle", QVariant::fromValue(m_delegateProperties.get()));
200 m_shadowComponent->completeCreate();
205 QQuickItem::componentComplete();
206 Q_ASSERT(m_delegateProperties);
209 maybeCreateDelegate();
210 connect(m_delegateProperties, &QQStyleKitDelegateProperties::delegateChanged,
this, [
this]{
211 if (!m_delegateInstance) {
212 maybeCreateDelegate();
214 const QQmlComponent *newDelegateComp = m_delegateProperties->delegate();
215 if (m_delegateComponent == newDelegateComp)
217 if (!newDelegateComp && m_delegateComponent == s_defaultDelegateComponent) {
219
223 delete m_delegateInstance;
224 maybeCreateDelegate();
225 emit delegateInstanceChanged();
230 connect(m_delegateProperties->shadow(), &QQStyleKitShadowProperties::delegateChanged,
this, [
this]{
231 if (!m_shadowInstance) {
234 const QQmlComponent *newShadowComp = m_delegateProperties->shadow()->delegate();
235 if (m_shadowComponent == newShadowComp)
237 if (!newShadowComp && m_shadowComponent == s_defaultShadowComponent) {
239
243 delete m_shadowInstance;
251#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.