aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickswipe_p.h3
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp40
-rw-r--r--src/quicktemplates2/qquickswipedelegate_p.h4
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml62
4 files changed, 106 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickswipe_p.h b/src/quicktemplates2/qquickswipe_p.h
index 76472c67..30f49eb5 100644
--- a/src/quicktemplates2/qquickswipe_p.h
+++ b/src/quicktemplates2/qquickswipe_p.h
@@ -50,12 +50,12 @@
#include <QtCore/qobject.h>
#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h>
+#include <QtQuickTemplates2/private/qquickswipedelegate_p.h>
QT_BEGIN_NAMESPACE
class QQmlComponent;
class QQuickItem;
-class QQuickSwipeDelegate;
class QQuickSwipePrivate;
class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipe : public QObject
@@ -101,6 +101,7 @@ public:
QQuickItem *rightItem() const;
void setRightItem(QQuickItem *item);
+ Q_REVISION(2) Q_INVOKABLE void open(QQuickSwipeDelegate::Side side);
Q_REVISION(1) Q_INVOKABLE void close();
Q_SIGNALS:
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index e1830a9f..e660cfa2 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -592,6 +592,21 @@ void QQuickSwipe::setEnabled(bool enabled)
emit enabledChanged();
}
+void QQuickSwipe::open(QQuickSwipeDelegate::Side side)
+{
+ Q_D(QQuickSwipe);
+ if ((side != QQuickSwipeDelegate::Left && side != QQuickSwipeDelegate::Right)
+ || (!d->left && !d->behind && side == QQuickSwipeDelegate::Left)
+ || (!d->right && !d->behind && side == QQuickSwipeDelegate::Right))
+ return;
+
+ setPosition(side);
+ setComplete(true);
+ d->wasComplete = true;
+ d->velocityCalculator.reset();
+ d->positionBeforePress = d->position;
+}
+
void QQuickSwipe::close()
{
Q_D(QQuickSwipe);
@@ -828,6 +843,27 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) :
}
/*!
+ \since QtQuick.Controls 2.2
+ \qmlmethod void QtQuick.Controls::SwipeDelegate::swipe.open(enumeration side)
+
+ This method sets the \c position of the swipe so that it opens
+ from the specified \a side.
+
+ Available values:
+ \value SwipeDelegate.Left The \c position is set to \c 1, which makes the swipe open
+ from the left. Either \c swipe.left or \c swipe.behind must
+ have been specified; otherwise the call is ignored.
+ \value SwipeDelegate.Right The \c position is set to \c -1, which makes the swipe open
+ from the right. Either \c swipe.right or \c swipe.behind must
+ have been specified; otherwise the call is ignored.
+
+ Any animations defined for the \l {Item::}{x} position of \l {Control::}{contentItem}
+ and \l {Control::}{background} will be triggered.
+
+ \sa swipe, swipe.close()
+*/
+
+/*!
\since QtQuick.Controls 2.1
\qmlmethod void QtQuick.Controls::SwipeDelegate::swipe.close()
@@ -835,7 +871,7 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) :
defined for the \l {Item::}{x} position of \l {Control::}{contentItem}
and \l {Control::}{background} will be triggered.
- \sa swipe
+ \sa swipe, swipe.open()
*/
/*!
@@ -930,7 +966,7 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) :
This signal was added in QtQuick.Controls 2.1.
\endtable
- \sa {Control::}{contentItem}, {Control::}{background}, swipe.close()
+ \sa {Control::}{contentItem}, {Control::}{background}, swipe.open(), swipe.close()
*/
QQuickSwipe *QQuickSwipeDelegate::swipe() const
{
diff --git a/src/quicktemplates2/qquickswipedelegate_p.h b/src/quicktemplates2/qquickswipedelegate_p.h
index 16aa9837..5bb6f4c0 100644
--- a/src/quicktemplates2/qquickswipedelegate_p.h
+++ b/src/quicktemplates2/qquickswipedelegate_p.h
@@ -67,6 +67,9 @@ public:
QQuickSwipe *swipe() const;
+ enum Side { Left = 1, Right = -1 };
+ Q_ENUM(Side)
+
static QQuickSwipeDelegateAttached *qmlAttachedProperties(QObject *object);
protected:
@@ -112,5 +115,6 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickSwipeDelegate)
QML_DECLARE_TYPEINFO(QQuickSwipeDelegate, QML_HAS_ATTACHED_PROPERTIES)
+Q_DECLARE_METATYPE(QQuickSwipeDelegate::Side)
#endif // QQUICKSWIPEDELEGATE_P_H
diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml
index c2e99df1..47aba3d5 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -1450,4 +1450,66 @@ TestCase {
control.destroy();
}
+
+ function test_side() {
+ compare(SwipeDelegate.Left, 1.0);
+ compare(SwipeDelegate.Right, -1.0);
+ }
+
+ function test_open_side_data() {
+ return [
+ { tag: "left", side: SwipeDelegate.Left, position: 1, complete: true, left: greenLeftComponent, right: null, behind: null },
+ { tag: "right", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: redRightComponent, behind: null },
+ { tag: "behind,left", side: SwipeDelegate.Left, position: 1, complete: true, left: null, right: null, behind: greenLeftComponent },
+ { tag: "behind,right", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: null, behind: redRightComponent },
+ { tag: "left,behind", side: SwipeDelegate.Left, position: 1, complete: true, left: null, right: null, behind: greenLeftComponent },
+ { tag: "right,behind", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: null, behind: redRightComponent },
+ { tag: "left,null", side: SwipeDelegate.Left, position: 0, complete: false, left: null, right: null, behind: null },
+ { tag: "right,null", side: SwipeDelegate.Right, position: 0, complete: false, left: null, right: null, behind: null },
+ { tag: "invalid", side: 0, position: 0, complete: false, left: greenLeftComponent, right: null, behind: null }
+ ]
+ }
+
+ function test_open_side(data) {
+ var control = emptySwipeDelegateComponent.createObject(testCase, {"swipe.left": data.left, "swipe.right": data.right, "swipe.behind": data.behind});
+ verify(control);
+
+ control.swipe.open(data.side);
+ compare(control.swipe.position, data.position);
+ compare(control.swipe.complete, data.complete);
+
+ control.destroy();
+ }
+
+ Component {
+ id: openSwipeDelegateComponent
+
+ SwipeDelegate {
+ text: "SwipeDelegate"
+ width: 150
+
+ onClicked: swipe.open(SwipeDelegate.Right)
+
+ swipe.right: Item {
+ width: parent.width
+ height: parent.height
+ }
+ }
+ }
+
+ function test_open() {
+ var control = openSwipeDelegateComponent.createObject(testCase);
+ verify(control);
+
+ mouseClick(control);
+ compare(control.swipe.position, SwipeDelegate.Right);
+ tryCompare(control.background, "x", -control.background.width);
+
+ // Swiping after opening should work as normal.
+ swipe(control, SwipeDelegate.Right, 0.0);
+ compare(control.swipe.position, 0.0);
+ tryCompare(control.background, "x", 0);
+
+ control.destroy();
+ }
}