diff options
-rw-r--r-- | src/imports/controls/SwipeDelegate.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml | 37 | ||||
-rw-r--r-- | src/imports/controls/material/SwipeDelegate.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/universal/SwipeDelegate.qml | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipe_p.h | 8 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate.cpp | 53 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_swipedelegate.qml | 2 |
7 files changed, 76 insertions, 30 deletions
diff --git a/src/imports/controls/SwipeDelegate.qml b/src/imports/controls/SwipeDelegate.qml index 6249e2ca..3c8b62df 100644 --- a/src/imports/controls/SwipeDelegate.qml +++ b/src/imports/controls/SwipeDelegate.qml @@ -52,7 +52,7 @@ T.SwipeDelegate { padding: 12 spacing: 12 - swipe.rebound: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } contentItem: Text { leftPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml new file mode 100644 index 00000000..a5e81ab7 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +//! [1] +SwipeDelegate { + swipe.transition: Transition { + SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } + } +} +//! [1] diff --git a/src/imports/controls/material/SwipeDelegate.qml b/src/imports/controls/material/SwipeDelegate.qml index 3561b32d..053680b4 100644 --- a/src/imports/controls/material/SwipeDelegate.qml +++ b/src/imports/controls/material/SwipeDelegate.qml @@ -54,7 +54,7 @@ T.SwipeDelegate { bottomPadding: 8 spacing: 16 - swipe.rebound: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } contentItem: Text { leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width + control.spacing : 0) : 0 diff --git a/src/imports/controls/universal/SwipeDelegate.qml b/src/imports/controls/universal/SwipeDelegate.qml index 41a5a372..f1ecbc2b 100644 --- a/src/imports/controls/universal/SwipeDelegate.qml +++ b/src/imports/controls/universal/SwipeDelegate.qml @@ -54,7 +54,7 @@ T.SwipeDelegate { topPadding: padding - 1 bottomPadding: padding + 1 - swipe.rebound: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } contentItem: Text { leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 diff --git a/src/quicktemplates2/qquickswipe_p.h b/src/quicktemplates2/qquickswipe_p.h index 8a02cb93..2037ca68 100644 --- a/src/quicktemplates2/qquickswipe_p.h +++ b/src/quicktemplates2/qquickswipe_p.h @@ -71,7 +71,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipe : public QObject Q_PROPERTY(QQuickItem *leftItem READ leftItem NOTIFY leftItemChanged FINAL) Q_PROPERTY(QQuickItem *behindItem READ behindItem NOTIFY behindItemChanged FINAL) Q_PROPERTY(QQuickItem *rightItem READ rightItem NOTIFY rightItemChanged FINAL) - Q_PROPERTY(QQuickTransition *rebound READ rebound WRITE setRebound NOTIFY reboundChanged FINAL) // REVISION 2 + Q_PROPERTY(QQuickTransition *transition READ transition WRITE setTransition NOTIFY transitionChanged FINAL) // REVISION 2 public: explicit QQuickSwipe(QQuickSwipeDelegate *control); @@ -103,8 +103,8 @@ public: QQuickItem *rightItem() const; void setRightItem(QQuickItem *item); - QQuickTransition *rebound() const; - void setRebound(QQuickTransition *rebound); + QQuickTransition *transition() const; + void setTransition(QQuickTransition *transition); Q_REVISION(2) Q_INVOKABLE void open(QQuickSwipeDelegate::Side side); Q_REVISION(1) Q_INVOKABLE void close(); @@ -122,7 +122,7 @@ Q_SIGNALS: void leftItemChanged(); void behindItemChanged(); void rightItemChanged(); - /*Q_REVISION(2)*/ void reboundChanged(); + /*Q_REVISION(2)*/ void transitionChanged(); private: Q_DISABLE_COPY(QQuickSwipe) diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index 10be2ac2..9d49c433 100644 --- a/src/quicktemplates2/qquickswipedelegate.cpp +++ b/src/quicktemplates2/qquickswipedelegate.cpp @@ -121,7 +121,7 @@ class QQuickSwipeTransitionManager : public QQuickTransitionManager public: QQuickSwipeTransitionManager(QQuickSwipe *swipe); - void transition(QQuickTransition *rebound, qreal position); + void transition(QQuickTransition *transition, qreal position); protected: void finished() override; @@ -148,7 +148,7 @@ public: leftItem(nullptr), behindItem(nullptr), rightItem(nullptr), - rebound(nullptr), + transition(nullptr), transitionManager(nullptr) { } @@ -172,7 +172,7 @@ public: bool hasDelegates() const; bool isTransitioning() const; - void transition(qreal position); + void beginTransition(qreal position); void finishTransition(); QQuickSwipeDelegate *control; @@ -192,7 +192,7 @@ public: QQuickItem *leftItem; QQuickItem *behindItem; QQuickItem *rightItem; - QQuickTransition *rebound; + QQuickTransition *transition; QScopedPointer<QQuickSwipeTransitionManager> transitionManager; }; @@ -201,12 +201,12 @@ QQuickSwipeTransitionManager::QQuickSwipeTransitionManager(QQuickSwipe *swipe) { } -void QQuickSwipeTransitionManager::transition(QQuickTransition *rebound, qreal position) +void QQuickSwipeTransitionManager::transition(QQuickTransition *transition, qreal position) { - qmlExecuteDeferred(rebound); + qmlExecuteDeferred(transition); QQmlProperty defaultTarget(m_swipe, QLatin1String("position")); - QQmlListProperty<QQuickAbstractAnimation> animations = rebound->animations(); + QQmlListProperty<QQuickAbstractAnimation> animations = transition->animations(); const int count = animations.count(&animations); for (int i = 0; i < count; ++i) { QQuickAbstractAnimation *anim = animations.at(&animations, i); @@ -215,7 +215,7 @@ void QQuickSwipeTransitionManager::transition(QQuickTransition *rebound, qreal p QList<QQuickStateAction> actions; actions << QQuickStateAction(m_swipe, QLatin1String("position"), position); - QQuickTransitionManager::transition(actions, rebound, m_swipe); + QQuickTransitionManager::transition(actions, transition, m_swipe); } void QQuickSwipeTransitionManager::finished() @@ -415,10 +415,10 @@ bool QQuickSwipePrivate::isTransitioning() const return transitionManager && transitionManager->isRunning(); } -void QQuickSwipePrivate::transition(qreal newPosition) +void QQuickSwipePrivate::beginTransition(qreal newPosition) { Q_Q(QQuickSwipe); - if (!rebound) { + if (!transition) { q->setPosition(newPosition); finishTransition(); return; @@ -427,7 +427,7 @@ void QQuickSwipePrivate::transition(qreal newPosition) if (!transitionManager) transitionManager.reset(new QQuickSwipeTransitionManager(q)); - transitionManager->transition(rebound, newPosition); + transitionManager->transition(transition, newPosition); } void QQuickSwipePrivate::finishTransition() @@ -674,20 +674,20 @@ void QQuickSwipe::setEnabled(bool enabled) emit enabledChanged(); } -QQuickTransition *QQuickSwipe::rebound() const +QQuickTransition *QQuickSwipe::transition() const { Q_D(const QQuickSwipe); - return d->rebound; + return d->transition; } -void QQuickSwipe::setRebound(QQuickTransition *rebound) +void QQuickSwipe::setTransition(QQuickTransition *transition) { Q_D(QQuickSwipe); - if (rebound == d->rebound) + if (transition == d->transition) return; - d->rebound = rebound; - emit reboundChanged(); + d->transition = transition; + emit transitionChanged(); } void QQuickSwipe::open(QQuickSwipeDelegate::Side side) @@ -701,7 +701,7 @@ void QQuickSwipe::open(QQuickSwipeDelegate::Side side) || (!d->right && !d->behind && side == QQuickSwipeDelegate::Right)) return; - d->transition(side); + d->beginTransition(side); d->wasComplete = true; d->velocityCalculator.reset(); d->positionBeforePress = d->position; @@ -713,7 +713,7 @@ void QQuickSwipe::close() if (qFuzzyIsNull(d->position)) return; - d->transition(0.0); + d->beginTransition(0.0); d->wasComplete = false; d->positionBeforePress = 0.0; d->velocityCalculator.reset(); @@ -898,14 +898,14 @@ bool QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(QQuickItem *item, QMous const qreal swipeVelocity = swipePrivate->velocityCalculator.velocity().x(); if (swipePrivate->position > 0.5 || (swipePrivate->position > 0.0 && swipeVelocity > exposeVelocityThreshold)) { - swipePrivate->transition(1.0); + swipePrivate->beginTransition(1.0); swipePrivate->wasComplete = true; } else if (swipePrivate->position < -0.5 || (swipePrivate->position < 0.0 && swipeVelocity < -exposeVelocityThreshold)) { - swipePrivate->transition(-1.0); + swipePrivate->beginTransition(-1.0); swipePrivate->wasComplete = true; } else if (!swipePrivate->isTransitioning()) { - swipePrivate->transition(0.0); + swipePrivate->beginTransition(0.0); swipePrivate->wasComplete = false; } @@ -1042,6 +1042,7 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) : \qmlproperty Item QtQuick.Controls::SwipeDelegate::swipe.leftItem \qmlproperty Item QtQuick.Controls::SwipeDelegate::swipe.behindItem \qmlproperty Item QtQuick.Controls::SwipeDelegate::swipe.rightItem + \qmlproperty Transition QtQuick.Controls::SwipeDelegate::swipe.transition \table \header @@ -1112,6 +1113,14 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) : If \c right has not been set, or the position hasn't changed since creation of the SwipeDelegate, this property will be \c null. + \row + \li transition + \li This property holds the transition that is applied when a swipe is released, + or \l swipe.open() or \l swipe.close() is called. + + \snippet qtquickcontrols2-swipedelegate-transition.qml 1 + + This property was added in Qt Quick Controls 2.2. \endtable \sa {Control::}{contentItem}, {Control::}{background}, swipe.open(), swipe.close() diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 85db883f..727f24e5 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1521,7 +1521,7 @@ TestCase { width: 150 swipe.left: greenLeftComponent swipe.right: redRightComponent - swipe.rebound: null + swipe.transition: null property alias behavior: xBehavior property alias animation: numberAnimation |