aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-22 17:13:03 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-25 14:36:49 +0000
commite33443d9b8de1917d8d3b85f185bbb75b78dc448 (patch)
treeea3c80200476d61dc5601564ab858eb4eb1683c6 /src
parentd705558a28e013aea904214deb8f35c708b61ac3 (diff)
Add SwipeDelegate::swipe.open()
This allows nice tricks, such as opening the swipe on click to expose more details for clicked delegates. [ChangeLog][Controls][SwipeDelegate] Added swipe.open(side) method that can be used to programmatically open the side item on the specified side, which can be either SwipeDelegate.Left or SwipeDelegate.Right. Change-Id: I64000e41ef62e04bf11a3819e03353c3ae4690cb Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickswipe_p.h3
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp40
-rw-r--r--src/quicktemplates2/qquickswipedelegate_p.h4
3 files changed, 44 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