diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-07-11 10:54:31 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-07-13 20:12:02 +0000 |
commit | 546544b347be496a484101b1b7c05e3c6bdbc9e9 (patch) | |
tree | 7bd807eeaa235ba14b64d164702326aba0549b9d | |
parent | aa823b2961f90a3fa459a220b3eab51c227b110a (diff) |
SwipeDelegate: add swipe.close()
This allows users to close the swipe after an action has been
triggered, for example.
[ChangeLog][SwipeDelegate] Added swipe.close() for setting
swipe.position to 0.
Change-Id: Ib12a6592ac1ba46baafd88a41ea8f297599c7bbc
Task-number: QTBUG-54651
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r-- | src/imports/templates/qtquicktemplates2plugin.cpp | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate.cpp | 16 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate_p.h | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_swipedelegate.qml | 29 |
4 files changed, 47 insertions, 1 deletions
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 1e5c3aad..7f50f22d 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -183,6 +183,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) qmlRegisterType<QQuickSlider, 1>(uri, 2, 1, "Slider"); qmlRegisterType<QQuickSpinBox, 1>(uri, 2, 1, "SpinBox"); qmlRegisterType<QQuickStackView, 1>(uri, 2, 1, "StackView"); + qmlRegisterType<QQuickSwipeDelegate, 1>(uri, 2, 1, "SwipeDelegate"); qmlRegisterType<QQuickSwipeView, 1>(uri, 2, 1, "SwipeView"); qmlRegisterType<QQuickTextArea, 1>(uri, 2, 1, "TextArea"); qmlRegisterType<QQuickTextField, 1>(uri, 2, 1, "TextField"); diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index 1edc5018..a9f6ac08 100644 --- a/src/quicktemplates2/qquickswipedelegate.cpp +++ b/src/quicktemplates2/qquickswipedelegate.cpp @@ -522,6 +522,12 @@ void QQuickSwipe::setComplete(bool complete) emit completeChanged(); } +void QQuickSwipe::close() +{ + setPosition(0); + setComplete(false); +} + class QQuickSwipeDelegatePrivate : public QQuickItemDelegatePrivate { Q_DECLARE_PUBLIC(QQuickSwipeDelegate) @@ -711,10 +717,11 @@ 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 + \qmlmethod void QtQuick.Controls::SwipeDelegate::swipe.close() \table \header - \li Property + \li Property/Method \li Description \row \li position @@ -770,6 +777,13 @@ 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 close() + \li This method sets the \c position of the swipe to \c 0. Any animations + defined for the \l {Item::}{x} position of \l {Control::}{contentItem} + and \l {Control::}{background} will be triggered. + + This method was added in QtQuick.Controls 2.1. \endtable \sa {Control::}{contentItem}, {Control::}{background} diff --git a/src/quicktemplates2/qquickswipedelegate_p.h b/src/quicktemplates2/qquickswipedelegate_p.h index b2bea3eb..afd195ea 100644 --- a/src/quicktemplates2/qquickswipedelegate_p.h +++ b/src/quicktemplates2/qquickswipedelegate_p.h @@ -123,6 +123,8 @@ public: QQuickItem *rightItem() const; void setRightItem(QQuickItem *item); + Q_REVISION(1) Q_INVOKABLE void close(); + Q_SIGNALS: void positionChanged(); void completeChanged(); diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index ead697d6..29dc9397 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -910,4 +910,33 @@ TestCase { control.destroy(); } + + Component { + id: closeSwipeDelegateComponent + + SwipeDelegate { + text: "SwipeDelegate" + width: 150 + + onClicked: close() + + swipe.right: Item { + width: parent.width + height: parent.height + } + } + } + + function test_close() { + var control = swipeDelegateComponent.createObject(testCase); + verify(control); + + swipe(control, 0.0, -1.0); + compare(control.swipe.rightItem.visible, true); + // Should animate, so it shouldn't change right away. + compare(control.swipe.rightItem.x, 0); + tryCompare(control.swipe.rightItem, "x", control.background.x + control.background.width); + + control.destroy(); + } } |