9#include <QtQml/qqmlinfo.h>
10#include <QtQml/qqmlengine.h>
11#include <QtQml/qqmlcomponent.h>
12#include <QtQml/qqmlincubator.h>
13#include <QtQml/private/qv4qobjectwrapper_p.h>
14#include <QtQml/private/qqmlcomponent_p.h>
15#include <QtQml/private/qqmlengine_p.h>
16#include <QtQml/private/qqmlincubator_p.h>
20#if QT_CONFIG(quick_viewtransitions)
21static QQuickStackViewAttached *attachedStackObject(QQuickStackElement *element)
23 QQuickStackViewAttached *attached = qobject_cast<QQuickStackViewAttached *>(qmlAttachedPropertiesObject<QQuickStackView>(element->item,
false));
25 QQuickStackViewAttachedPrivate::get(attached)->element = element;
42 auto privIncubator = QQmlIncubatorPrivate::get(
this);
43 if (QQmlEnginePrivate *enginePriv = privIncubator->enginePriv) {
44 element->incubate(enginePriv->v4Engine.get(), object,
45 privIncubator->requiredProperties());
54#if QT_CONFIG(quick_viewtransitions)
55 : QQuickItemViewTransitionableItem(
nullptr)
62#if QT_CONFIG(quick_viewtransitions)
64 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Destroyed);
70#if QT_CONFIG(quick_viewtransitions)
71 QQuickStackViewAttached *attached = attachedStackObject(
this);
74 item->setParentItem(
nullptr);
83 if (item->parentItem() != originalParent) {
84 item->setParentItem(originalParent);
87 QQuickStackViewAttachedPrivate::get(attached)->itemParentChanged(item,
nullptr);
93 emit attached->removed();
98 QQmlEngine *engine,
const QString &str, QQuickStackView *view, QString *error)
101 if (!url.isValid()) {
102 *error = QStringLiteral(
"invalid url: ") + str;
106 if (url.isRelative())
107 url = qmlContext(view)->resolvedUrl(url);
110 element->component =
new QQmlComponent(engine, url, view);
118 QQmlComponent *component = qobject_cast<QQmlComponent *>(object);
119 QQuickItem *item = qobject_cast<QQuickItem *>(object);
120 if (!component && !item) {
121 *error = QQmlMetaType::prettyTypeName(object) + QStringLiteral(
" is not supported. Must be Item or Component.");
125 QQuickStackElement *element =
new QQuickStackElement;
126 element->component = qobject_cast<QQmlComponent *>(object);
127#if QT_CONFIG(quick_viewtransitions)
128 element->item = qobject_cast<QQuickItem *>(object);
130 element->originalParent = element->item->parentItem();
136 QQmlEngine *engine, QQuickStackView *view, QQuickStackViewArg arg)
138 QQuickStackElement *element =
new QQuickStackElement;
139#if QT_CONFIG(quick_viewtransitions)
140 element->item = arg.mItem;
142 element->originalParent = element->item->parentItem();
144 Q_ASSERT(!arg.mComponent);
145 Q_ASSERT(!arg.mUrl.isValid());
148 if (arg.mComponent) {
149 element->component = arg.mComponent;
151 Q_ASSERT(!arg.mUrl.isValid());
152 }
else if (arg.mUrl.isValid()) {
153 element->component =
new QQmlComponent(engine, arg.mUrl, view);
154 element->ownComponent =
true;
156 qFatal(
"No Item, Component or URL set on arg passed to fromStrictArg");
167 if (component->isLoading()) {
168 QObject::connect(component, &QQmlComponent::statusChanged, [
this](QQmlComponent::Status status) {
169 if (status == QQmlComponent::Ready)
170 load(component->engine()->handle(), view);
171 else if (status == QQmlComponent::Error)
172 QQuickStackViewPrivate::get(view)->warn(component->errorString().trimmed());
177 QQmlContext *context = component->creationContext();
179 context = qmlContext(parent);
181 QQuickStackIncubator incubator(
this);
182 component->create(incubator, context);
183 if (component->isError())
184 QQuickStackViewPrivate::get(parent)->warn(component->errorString().trimmed());
186 initialize(v4,
nullptr);
194 item = qmlobject_cast<QQuickItem *>(object);
196 QQmlEngine::setObjectOwnership(item, QQmlEngine::CppOwnership);
197 item->setParent(view);
198 initialize(v4, requiredProperties);
208 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
209 if (!(widthValid = p->widthValid()))
210 item->setWidth(view->width());
211 if (!(heightValid = p->heightValid()))
212 item->setHeight(view->height());
213 item->setParentItem(view);
215 if (!properties.isUndefined()) {
216 QV4::Scope scope(v4);
217 Q_ASSERT(scope.engine);
218 QV4::ScopedValue ipv(scope, properties.value());
219 QV4::Scoped<QV4::QmlContext> qmlContext(scope, qmlCallingContext.value());
220 QV4::ScopedValue qmlObject(scope, QV4::QObjectWrapper::wrap(scope.engine, item));
221 QQmlComponentPrivate::setInitialProperties(
222 scope.engine, qmlContext, qmlObject, ipv, requiredProperties, item,
223 component ? QQmlComponentPrivate::get(component)->creator() :
nullptr);
227 if (requiredProperties && !requiredProperties->empty()) {
229 for (
const auto &property: *requiredProperties) {
230 error += QLatin1String(
"Property %1 was marked as required but not set.\n")
231 .arg(property.propertyName);
233 QQuickStackViewPrivate::get(view)->warn(error);
236 p->addItemChangeListener(
this, QQuickItemPrivate::Destroyed);
248#if QT_CONFIG(quick_viewtransitions)
249 QQuickStackViewAttached *attached = attachedStackObject(
this);
251 emit attached->indexChanged();
261#if QT_CONFIG(quick_viewtransitions)
262 QQuickStackViewAttached *attached = attachedStackObject(
this);
264 emit attached->viewChanged();
274#if QT_CONFIG(quick_viewtransitions)
275 QQuickStackViewAttached *attached = attachedStackObject(
this);
280 case QQuickStackView::Inactive:
281 emit attached->deactivated();
283 case QQuickStackView::Deactivating:
284 emit attached->deactivating();
286 case QQuickStackView::Activating:
287 emit attached->activating();
289 case QQuickStackView::Active:
290 emit attached->activated();
297 emit attached->statusChanged();
303#if QT_CONFIG(quick_viewtransitions)
304 QQuickStackViewAttached *attached = attachedStackObject(
this);
307#if QT_CONFIG(quick_viewtransitions)
308 || (attached && QQuickStackViewAttachedPrivate::get(attached)->explicitVisible)
313 item->setVisible(visible);
316#if QT_CONFIG(quick_viewtransitions)
317void QQuickStackElement::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type,
bool asTarget)
320 transitioner->transitionNextReposition(
this, type, asTarget);
323bool QQuickStackElement::prepareTransition(QQuickItemViewTransitioner *transitioner,
const QRectF &viewBounds)
327 QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors;
329 if (anchors && (anchors->fill() || anchors->centerIn()))
330 qmlWarning(item) <<
"StackView has detected conflicting anchors. Transitions may not execute properly.";
334 nextTransitionToSet =
true;
335 nextTransitionFromSet =
true;
336 nextTransitionFrom += QPointF(1, 1);
337 return QQuickItemViewTransitionableItem::prepareTransition(transitioner, index, viewBounds);
342void QQuickStackElement::startTransition(QQuickItemViewTransitioner *transitioner, QQuickStackView::Status status)
346 QQuickItemViewTransitionableItem::startTransition(transitioner, index);
349void QQuickStackElement::completeTransition(QQuickTransition *quickTransition)
351 QQuickItemViewTransitionableItem::completeTransition(quickTransition);
357#if QT_CONFIG(quick_viewtransitions)
QQmlComponent * component
void itemDestroyed(QQuickItem *item) override
void initialize(QV4::ExecutionEngine *v4, RequiredProperties *requiredProperties)
void setVisible(bool visible)
void setStatus(QQuickStackView::Status status)
void incubate(QV4::ExecutionEngine *v4, QObject *object, RequiredProperties *requiredProperties)
QQuickStackIncubator(QQuickStackElement *element)
void setInitialState(QObject *object) override
Called after the object is first created, but before complex property bindings are evaluated and,...