aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-09-25 21:30:59 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-23 15:34:00 +0000
commite1bf1e9a03066a9029132e476794d3f16abcd6ff (patch)
treee2714d3b5267014500dfe293a0616c22e803476b
parent2bbe54908b7ccfef8448b2db586be2c3a25bbcb6 (diff)
StackView: add dedicated replace transitions
Change-Id: I614d11bb566c96166ebf8bc0d2f5d4286d823a5f Reviewed-by: Kai Uwe Broulik <kde@privat.broulik.de> Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/imports/controls/StackView.qml12
-rw-r--r--src/imports/controls/doc/src/qtlabscontrols-customize.qdoc10
-rw-r--r--src/templates/qquickstackview.cpp62
-rw-r--r--src/templates/qquickstackview_p.cpp22
-rw-r--r--src/templates/qquickstackview_p.h10
-rw-r--r--tests/auto/controls/data/tst_stackview.qml15
6 files changed, 114 insertions, 17 deletions
diff --git a/src/imports/controls/StackView.qml b/src/imports/controls/StackView.qml
index 1288f8a4..1748d964 100644
--- a/src/imports/controls/StackView.qml
+++ b/src/imports/controls/StackView.qml
@@ -64,4 +64,16 @@ T.StackView {
NumberAnimation { property: "x"; from: 0; to: -root.width; duration: 400; easing.type: Easing.OutCubic }
}
//! [pushExit]
+
+ //! [replaceEnter]
+ replaceEnter: Transition {
+ NumberAnimation { property: "x"; from: root.width; to: 0; duration: 400; easing.type: Easing.OutCubic }
+ }
+ //! [replaceEnter]
+
+ //! [replaceExit]
+ replaceExit: Transition {
+ NumberAnimation { property: "x"; from: 0; to: -root.width; duration: 400; easing.type: Easing.OutCubic }
+ }
+ //! [replaceExit]
}
diff --git a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
index c4124191..2036d803 100644
--- a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
+++ b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc
@@ -340,7 +340,7 @@
StackView can have a visual \l {Control::background}{background}
item, and it allows customizing the transitions that are used for
- push and pop operations.
+ push, pop, and replace operations.
\section3 Push enter
@@ -358,6 +358,14 @@
\snippet StackView.qml popExit
+ \section3 Replace enter
+
+ \snippet StackView.qml replaceEnter
+
+ \section3 Replace exit
+
+ \snippet StackView.qml replaceExit
+
\section1 Customizing SwipeView
diff --git a/src/templates/qquickstackview.cpp b/src/templates/qquickstackview.cpp
index 33f21c95..075830a4 100644
--- a/src/templates/qquickstackview.cpp
+++ b/src/templates/qquickstackview.cpp
@@ -207,12 +207,12 @@ QT_BEGIN_NAMESPACE
to entering and exiting items. These animations define how the entering item
should animate in, and the exiting item should animate out. The animations
can be customized by assigning different \l{Transition}s for the
- \l pushEnter, \l pushExit, \l popEnter, and \l popExit properties of
- StackView.
+ \l pushEnter, \l pushExit, \l popEnter, \l popExit, \l replaceEnter, and
+ \l replaceExit properties of StackView.
- \note The pop and push transition animations affect each others'
- transitional behavior. So customizing the animation for one and leaving
- the other may give unexpected results.
+ \note The transition animations affect each others' transitional behavior.
+ Customizing the animation for one and leaving the other may give unexpected
+ results.
The following snippet defines a simple fade transition for push and pop
operations:
@@ -794,6 +794,58 @@ void QQuickStackView::setPushExit(QQuickTransition *exit)
}
}
+/*!
+ \qmlproperty Transition Qt.labs.controls::StackView::replaceEnter
+
+ This property holds the transition that is applied to the item that
+ enters the stack when another item is replaced by it.
+
+ \sa {Customizing StackView}
+*/
+QQuickTransition *QQuickStackView::replaceEnter() const
+{
+ Q_D(const QQuickStackView);
+ if (d->transitioner)
+ return d->transitioner->moveTransition;
+ return Q_NULLPTR;
+}
+
+void QQuickStackView::setReplaceEnter(QQuickTransition *enter)
+{
+ Q_D(QQuickStackView);
+ d->ensureTransitioner();
+ if (d->transitioner->moveTransition != enter) {
+ d->transitioner->moveTransition = enter;
+ emit replaceEnterChanged();
+ }
+}
+
+/*!
+ \qmlproperty Transition Qt.labs.controls::StackView::replaceExit
+
+ This property holds the transition that is applied to the item that
+ exits the stack when it is replaced by another item.
+
+ \sa {Customizing StackView}
+*/
+QQuickTransition *QQuickStackView::replaceExit() const
+{
+ Q_D(const QQuickStackView);
+ if (d->transitioner)
+ return d->transitioner->moveDisplacedTransition;
+ return Q_NULLPTR;
+}
+
+void QQuickStackView::setReplaceExit(QQuickTransition *exit)
+{
+ Q_D(QQuickStackView);
+ d->ensureTransitioner();
+ if (d->transitioner->moveDisplacedTransition != exit) {
+ d->transitioner->moveDisplacedTransition = exit;
+ emit replaceExitChanged();
+ }
+}
+
void QQuickStackView::componentComplete()
{
QQuickControl::componentComplete();
diff --git a/src/templates/qquickstackview_p.cpp b/src/templates/qquickstackview_p.cpp
index a66e7d21..9ee0bdb3 100644
--- a/src/templates/qquickstackview_p.cpp
+++ b/src/templates/qquickstackview_p.cpp
@@ -461,28 +461,28 @@ void QQuickStackViewPrivate::replaceTransition(QQuickStackElement *enter, QQuick
{
ensureTransitioner();
- if (enter) {
- enter->setStatus(QQuickStackView::Activating);
- enter->transitionNextReposition(transitioner, QQuickItemViewTransitioner::AddTransition, true);
- }
if (exit) {
exit->removal = true;
exit->setStatus(QQuickStackView::Deactivating);
- exit->transitionNextReposition(transitioner, QQuickItemViewTransitioner::AddTransition, false);
+ exit->transitionNextReposition(transitioner, QQuickItemViewTransitioner::MoveTransition, false);
}
-
if (enter) {
- if (immediate || !enter->prepareTransition(transitioner, viewBounds))
- completeTransition(enter, transitioner->addTransition);
- else
- enter->startTransition(transitioner);
+ enter->setStatus(QQuickStackView::Activating);
+ enter->transitionNextReposition(transitioner, QQuickItemViewTransitioner::MoveTransition, true);
}
+
if (exit) {
if (immediate || !exit->prepareTransition(transitioner, QRectF()))
- completeTransition(exit, transitioner->addDisplacedTransition);
+ completeTransition(exit, transitioner->moveDisplacedTransition);
else
exit->startTransition(transitioner);
}
+ if (enter) {
+ if (immediate || !enter->prepareTransition(transitioner, viewBounds))
+ completeTransition(enter, transitioner->moveTransition);
+ else
+ enter->startTransition(transitioner);
+ }
if (!immediate)
setBusy(true);
diff --git a/src/templates/qquickstackview_p.h b/src/templates/qquickstackview_p.h
index 7f989faf..e3121bf9 100644
--- a/src/templates/qquickstackview_p.h
+++ b/src/templates/qquickstackview_p.h
@@ -69,6 +69,8 @@ class Q_LABSTEMPLATES_EXPORT QQuickStackView : public QQuickControl
Q_PROPERTY(QQuickTransition *popExit READ popExit WRITE setPopExit NOTIFY popExitChanged FINAL)
Q_PROPERTY(QQuickTransition *pushEnter READ pushEnter WRITE setPushEnter NOTIFY pushEnterChanged FINAL)
Q_PROPERTY(QQuickTransition *pushExit READ pushExit WRITE setPushExit NOTIFY pushExitChanged FINAL)
+ Q_PROPERTY(QQuickTransition *replaceEnter READ replaceEnter WRITE setReplaceEnter NOTIFY replaceEnterChanged FINAL)
+ Q_PROPERTY(QQuickTransition *replaceExit READ replaceExit WRITE setReplaceExit NOTIFY replaceExitChanged FINAL)
public:
explicit QQuickStackView(QQuickItem *parent = Q_NULLPTR);
@@ -103,6 +105,12 @@ public:
QQuickTransition *pushExit() const;
void setPushExit(QQuickTransition *exit);
+ QQuickTransition *replaceEnter() const;
+ void setReplaceEnter(QQuickTransition *enter);
+
+ QQuickTransition *replaceExit() const;
+ void setReplaceExit(QQuickTransition *exit);
+
enum LoadBehavior {
DontLoad,
ForceLoad
@@ -133,6 +141,8 @@ Q_SIGNALS:
void popExitChanged();
void pushEnterChanged();
void pushExitChanged();
+ void replaceEnterChanged();
+ void replaceExitChanged();
protected:
void componentComplete() Q_DECL_OVERRIDE;
diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml
index 3dc6d0c9..22d4cfe3 100644
--- a/tests/auto/controls/data/tst_stackview.qml
+++ b/tests/auto/controls/data/tst_stackview.qml
@@ -451,6 +451,8 @@ TestCase {
property int popExitRuns
property int pushEnterRuns
property int pushExitRuns
+ property int replaceEnterRuns
+ property int replaceExitRuns
popEnter: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++popEnterRuns
@@ -467,6 +469,14 @@ TestCase {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++pushExitRuns
}
+ replaceEnter: Transition {
+ PauseAnimation { duration: 1 }
+ onRunningChanged: if (!running) ++replaceEnterRuns
+ }
+ replaceExit: Transition {
+ PauseAnimation { duration: 1 }
+ onRunningChanged: if (!running) ++replaceExitRuns
+ }
}
}
@@ -484,6 +494,11 @@ TestCase {
compare(control.pushEnterRuns, 1)
compare(control.pushExitRuns, 1)
+ control.replace(component)
+ tryCompare(control, "busy", false)
+ compare(control.replaceEnterRuns, 1)
+ compare(control.replaceExitRuns, 1)
+
control.pop()
tryCompare(control, "busy", false)
compare(control.popEnterRuns, 1)