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");
170 if (component->isLoading()) {
171 QObject::connect(component, &QQmlComponent::statusChanged, component,
172 [
this](QQmlComponent::Status status) {
173 if (status == QQmlComponent::Ready)
174 load(component->engine()->handle(), view);
175 else if (status == QQmlComponent::Error)
176 QQuickStackViewPrivate::get(view)->warn(component->errorString().trimmed());
181 QQmlContext *context = component->creationContext();
183 context = qmlContext(parent);
185 QQuickStackIncubator incubator(
this);
186 component->create(incubator, context);
187 if (component->isError())
188 QQuickStackViewPrivate::get(parent)->warn(component->errorString().trimmed());
190 initialize(v4,
nullptr);
198 item = qmlobject_cast<QQuickItem *>(object);
200 QQmlEngine::setObjectOwnership(item, QQmlEngine::CppOwnership);
201 item->setParent(view);
202 initialize(v4, requiredProperties);
212 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
213 if (!(widthValid = p->widthValid()))
214 item->setWidth(view->width());
215 if (!(heightValid = p->heightValid()))
216 item->setHeight(view->height());
217 item->setParentItem(view);
219 if (!properties.isUndefined()) {
220 QV4::Scope scope(v4);
221 Q_ASSERT(scope.engine);
222 QV4::ScopedValue ipv(scope, properties.value());
223 QV4::Scoped<QV4::QmlContext> qmlContext(scope, qmlCallingContext.value());
224 QV4::ScopedValue qmlObject(scope, QV4::QObjectWrapper::wrap(scope.engine, item));
225 QQmlComponentPrivate::setInitialProperties(
226 scope.engine, qmlContext, qmlObject, ipv, requiredProperties, item,
227 component ? QQmlComponentPrivate::get(component)->creator() :
nullptr);
231 if (requiredProperties && !requiredProperties->empty()) {
233 for (
const auto &property: *requiredProperties) {
234 error += QLatin1String(
"Property %1 was marked as required but not set.\n")
235 .arg(property.propertyName);
237 QQuickStackViewPrivate::get(view)->warn(error);
240 p->addItemChangeListener(
this, QQuickItemPrivate::Destroyed);
252#if QT_CONFIG(quick_viewtransitions)
253 QQuickStackViewAttached *attached = attachedStackObject(
this);
255 emit attached->indexChanged();
265#if QT_CONFIG(quick_viewtransitions)
266 QQuickStackViewAttached *attached = attachedStackObject(
this);
268 emit attached->viewChanged();
278#if QT_CONFIG(quick_viewtransitions)
279 QQuickStackViewAttached *attached = attachedStackObject(
this);
284 case QQuickStackView::Inactive:
285 emit attached->deactivated();
287 case QQuickStackView::Deactivating:
288 emit attached->deactivating();
290 case QQuickStackView::Activating:
291 emit attached->activating();
293 case QQuickStackView::Active:
294 emit attached->activated();
301 emit attached->statusChanged();
307#if QT_CONFIG(quick_viewtransitions)
308 QQuickStackViewAttached *attached = attachedStackObject(
this);
311#if QT_CONFIG(quick_viewtransitions)
312 || (attached && QQuickStackViewAttachedPrivate::get(attached)->explicitVisible)
317 item->setVisible(visible);
320#if QT_CONFIG(quick_viewtransitions)
321void QQuickStackElement::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type,
bool asTarget)
324 transitioner->transitionNextReposition(
this, type, asTarget);
327bool QQuickStackElement::prepareTransition(QQuickItemViewTransitioner *transitioner,
const QRectF &viewBounds)
331 QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors;
333 if (anchors && (anchors->fill() || anchors->centerIn()))
334 qmlWarning(item) <<
"StackView has detected conflicting anchors. Transitions may not execute properly.";
338 nextTransitionToSet =
true;
339 nextTransitionFromSet =
true;
340 nextTransitionFrom += QPointF(1, 1);
341 return QQuickItemViewTransitionableItem::prepareTransition(transitioner, index, viewBounds);
346void QQuickStackElement::startTransition(QQuickItemViewTransitioner *transitioner, QQuickStackView::Status status)
350 QQuickItemViewTransitionableItem::startTransition(transitioner, index);
353void QQuickStackElement::completeTransition(QQuickTransition *quickTransition)
355 QQuickItemViewTransitionableItem::completeTransition(quickTransition);
361#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,...
Combined button and popup list for selecting options.