aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickstackview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickstackview.cpp')
-rw-r--r--src/quicktemplates2/qquickstackview.cpp145
1 files changed, 124 insertions, 21 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index df9ab74f..d16d7b16 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -314,12 +314,7 @@ QQuickStackView::~QQuickStackView()
QQuickStackAttached *QQuickStackView::qmlAttachedProperties(QObject *object)
{
- QQuickItem *item = qobject_cast<QQuickItem *>(object);
- if (!item) {
- qmlInfo(object) << "StackView must be attached to an Item";
- return nullptr;
- }
- return new QQuickStackAttached(item);
+ return new QQuickStackAttached(object);
}
/*!
@@ -463,8 +458,11 @@ QQuickItem *QQuickStackView::find(const QJSValue &callback, LoadBehavior behavio
An \a operation can be optionally specified as the last argument. Supported
operations:
- \value StackView.Transition An operation with transitions.
+ \value StackView.Transition An operation with default transitions (default).
\value StackView.Immediate An immediate operation without transitions.
+ \value StackView.PushTransition An operation with push transitions (since QtQuick.Controls 2.1).
+ \value StackView.ReplaceTransition An operation with replace transitions (since QtQuick.Controls 2.1).
+ \value StackView.PopTransition An operation with pop transitions (since QtQuick.Controls 2.1).
\sa initialItem, {Pushing Items}
*/
@@ -480,7 +478,7 @@ void QQuickStackView::push(QQmlV4Function *args)
QV4::ExecutionEngine *v4 = args->v4engine();
QV4::Scope scope(v4);
- Operation operation = d->elements.isEmpty() ? Immediate : Transition;
+ Operation operation = d->elements.isEmpty() ? Immediate : PushTransition;
QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
if (lastArg->isInt32())
operation = static_cast<Operation>(lastArg->toInt32());
@@ -499,7 +497,9 @@ void QQuickStackView::push(QQmlV4Function *args)
if (d->pushElements(elements)) {
emit depthChanged();
QQuickStackElement *enter = d->elements.top();
- d->pushTransition(enter, exit, boundingRect(), operation == Immediate);
+ d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this),
+ QQuickStackTransition::pushExit(operation, exit, this),
+ operation == Immediate);
d->setCurrentItem(enter->item);
}
@@ -524,8 +524,11 @@ void QQuickStackView::push(QQmlV4Function *args)
An \a operation can be optionally specified as the last argument. Supported
operations:
- \value StackView.Transition An operation with transitions.
+ \value StackView.Transition An operation with default transitions (default).
\value StackView.Immediate An immediate operation without transitions.
+ \value StackView.PushTransition An operation with push transitions (since QtQuick.Controls 2.1).
+ \value StackView.ReplaceTransition An operation with replace transitions (since QtQuick.Controls 2.1).
+ \value StackView.PopTransition An operation with pop transitions (since QtQuick.Controls 2.1).
Examples:
\code
@@ -571,7 +574,7 @@ void QQuickStackView::pop(QQmlV4Function *args)
}
}
- Operation operation = Transition;
+ Operation operation = PopTransition;
if (argc > 0) {
QV4::ScopedValue lastArg(scope, (*args)[argc - 1]);
if (lastArg->isInt32())
@@ -581,10 +584,14 @@ void QQuickStackView::pop(QQmlV4Function *args)
QQuickItem *previousItem = nullptr;
if (d->popElements(enter)) {
- if (exit)
+ if (exit) {
+ exit->removal = true;
previousItem = exit->item;
+ }
emit depthChanged();
- d->popTransition(enter, exit, boundingRect(), operation == Immediate);
+ d->startTransition(QQuickStackTransition::popExit(operation, exit, this),
+ QQuickStackTransition::popEnter(operation, enter, this),
+ operation == Immediate);
d->setCurrentItem(enter->item);
}
@@ -647,8 +654,39 @@ void QQuickStackView::pop(QQmlV4Function *args)
An \a operation can be optionally specified as the last argument. Supported
operations:
- \value StackView.Transition An operation with transitions.
+ \value StackView.Transition An operation with default transitions (default).
\value StackView.Immediate An immediate operation without transitions.
+ \value StackView.PushTransition An operation with push transitions (since QtQuick.Controls 2.1).
+ \value StackView.ReplaceTransition An operation with replace transitions (since QtQuick.Controls 2.1).
+ \value StackView.PopTransition An operation with pop transitions (since QtQuick.Controls 2.1).
+
+ The following example illustrates the use of push and pop transitions with replace().
+
+ \code
+ StackView {
+ id: stackView
+
+ initialItem: Component {
+ id: page
+
+ Page {
+ Row {
+ spacing: 20
+ anchors.centerIn: parent
+
+ Button {
+ text: "<"
+ onClicked: stackView.replace(page, StackView.PopTransition)
+ }
+ Button {
+ text: ">"
+ onClicked: stackView.replace(page, StackView.PushTransition)
+ }
+ }
+ }
+ }
+ }
+ \endcode
\sa push(), {Replacing Items}
*/
@@ -664,7 +702,7 @@ void QQuickStackView::replace(QQmlV4Function *args)
QV4::ExecutionEngine *v4 = args->v4engine();
QV4::Scope scope(v4);
- Operation operation = d->elements.isEmpty() ? Immediate : Transition;
+ Operation operation = d->elements.isEmpty() ? Immediate : ReplaceTransition;
QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
if (lastArg->isInt32())
operation = static_cast<Operation>(lastArg->toInt32());
@@ -691,8 +729,12 @@ void QQuickStackView::replace(QQmlV4Function *args)
if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) {
if (depth != d->elements.count())
emit depthChanged();
+ if (exit)
+ exit->removal = true;
QQuickStackElement *enter = d->elements.top();
- d->replaceTransition(enter, exit, boundingRect(), operation == Immediate);
+ d->startTransition(QQuickStackTransition::replaceExit(operation, exit, this),
+ QQuickStackTransition::replaceEnter(operation, enter, this),
+ operation == Immediate);
d->setCurrentItem(enter->item);
}
@@ -978,19 +1020,25 @@ void QQuickStackAttachedPrivate::itemParentChanged(QQuickItem *item, QQuickItem
emit q->statusChanged();
}
-QQuickStackAttached::QQuickStackAttached(QQuickItem *parent) :
+QQuickStackAttached::QQuickStackAttached(QObject *parent) :
QObject(*(new QQuickStackAttachedPrivate), parent)
{
Q_D(QQuickStackAttached);
- QQuickItemPrivate::get(parent)->addItemChangeListener(d, QQuickItemPrivate::Parent);
- d->itemParentChanged(parent, parent->parentItem());
+ QQuickItem *item = qobject_cast<QQuickItem *>(parent);
+ if (item) {
+ QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent);
+ d->itemParentChanged(item, item->parentItem());
+ } else if (parent) {
+ qmlInfo(parent) << "StackView must be attached to an Item";
+ }
}
QQuickStackAttached::~QQuickStackAttached()
{
Q_D(QQuickStackAttached);
- QQuickItem *parentItem = static_cast<QQuickItem *>(parent());
- QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
+ QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
+ if (parentItem)
+ QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
}
/*!
@@ -1038,4 +1086,59 @@ QQuickStackView::Status QQuickStackAttached::status() const
return d->element ? d->element->status : QQuickStackView::Inactive;
}
+/*!
+ \qmlattachedsignal QtQuick.Controls::StackView::activated()
+ \since QtQuick.Controls 2.1
+
+ This attached signal is emitted when the item it's attached to is activated in the stack.
+
+ \sa status
+*/
+
+/*!
+ \qmlattachedsignal QtQuick.Controls::StackView::deactivated()
+ \since QtQuick.Controls 2.1
+
+ This attached signal is emitted when the item it's attached to is deactivated in the stack.
+
+ \sa status
+*/
+
+/*!
+ \qmlattachedsignal QtQuick.Controls::StackView::activating()
+ \since QtQuick.Controls 2.1
+
+ This attached signal is emitted when the item it's attached to is in the process of being
+ activated in the stack.
+
+ \sa status
+*/
+
+/*!
+ \qmlattachedsignal QtQuick.Controls::StackView::deactivating()
+ \since QtQuick.Controls 2.1
+
+ This attached signal is emitted when the item it's attached to is in the process of being
+ dectivated in the stack.
+
+ \sa status
+*/
+
+/*!
+ \qmlattachedsignal QtQuick.Controls::StackView::removed()
+ \since QtQuick.Controls 2.1
+
+ This attached signal is emitted when the item it's attached to has been
+ removed from the stack. It can be used to safely destroy an Item that was
+ pushed onto the stack, for example:
+
+ \code
+ Item {
+ StackView.onRemoved: destroy() // Will be destroyed sometime after this call.
+ }
+ \endcode
+
+ \sa status
+*/
+
QT_END_NAMESPACE