aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-11-21 11:52:53 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-25 14:36:47 +0000
commitd705558a28e013aea904214deb8f35c708b61ac3 (patch)
tree14d5a71088827523ce183a8c88b30a37c179352f /src
parent22769ac6a7667bf1d2d5b5e6421a15e4f6aadce1 (diff)
SwipeDelegate: Add swipe.enabled property
[ChangeLog][Controls][SwipeDelegate] Added swipe.enabled property to allow disabling of swiping. Task-number: QTBUG-57192 Change-Id: I733336690368ea3fb56a144a335a37e60a02f1b9 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quicktemplates2/qquickswipe_p.h5
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp35
3 files changed, 40 insertions, 1 deletions
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index 57e8f88e..76cce2d3 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -227,6 +227,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickDial, 2>(uri, 2, 2, "Dial");
qmlRegisterType<QQuickRangeSlider, 2>(uri, 2, 2, "RangeSlider");
qmlRegisterType<QQuickSlider, 2>(uri, 2, 2, "Slider");
+ qmlRegisterType<QQuickSwipeDelegate, 2>(uri, 2, 2, "SwipeDelegate");
qmlRegisterType<QQuickTumbler, 2>(uri, 2, 2, "Tumbler");
}
diff --git a/src/quicktemplates2/qquickswipe_p.h b/src/quicktemplates2/qquickswipe_p.h
index c1a28819..76472c67 100644
--- a/src/quicktemplates2/qquickswipe_p.h
+++ b/src/quicktemplates2/qquickswipe_p.h
@@ -63,6 +63,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipe : public QObject
Q_OBJECT
Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL)
Q_PROPERTY(bool complete READ isComplete NOTIFY completeChanged FINAL)
+ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL /*REVISION 2*/)
Q_PROPERTY(QQmlComponent *left READ left WRITE setLeft NOTIFY leftChanged FINAL)
Q_PROPERTY(QQmlComponent *behind READ behind WRITE setBehind NOTIFY behindChanged FINAL)
Q_PROPERTY(QQmlComponent *right READ right WRITE setRight NOTIFY rightChanged FINAL)
@@ -79,6 +80,9 @@ public:
bool isComplete() const;
void setComplete(bool complete);
+ bool isEnabled() const;
+ void setEnabled(bool enabled);
+
QQmlComponent *left() const;
void setLeft(QQmlComponent *left);
@@ -102,6 +106,7 @@ public:
Q_SIGNALS:
void positionChanged();
void completeChanged();
+ /*Q_REVISION(2)*/ void enabledChanged();
/*Q_REVISION(1)*/ void completed();
void leftChanged();
void behindChanged();
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 5430a4de..e1830a9f 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -124,6 +124,7 @@ public:
position(0),
wasComplete(false),
complete(false),
+ enabled(true),
left(nullptr),
behind(nullptr),
right(nullptr),
@@ -160,6 +161,7 @@ public:
// before the last press event.
bool wasComplete;
bool complete;
+ bool enabled;
QQuickVelocityCalculator velocityCalculator;
QQmlComponent *left;
QQmlComponent *behind;
@@ -574,6 +576,22 @@ void QQuickSwipe::setComplete(bool complete)
emit completed();
}
+bool QQuickSwipe::isEnabled() const
+{
+ Q_D(const QQuickSwipe);
+ return d->enabled;
+}
+
+void QQuickSwipe::setEnabled(bool enabled)
+{
+ Q_D(QQuickSwipe);
+ if (enabled == d->enabled)
+ return;
+
+ d->enabled = enabled;
+ emit enabledChanged();
+}
+
void QQuickSwipe::close()
{
Q_D(QQuickSwipe);
@@ -633,12 +651,17 @@ bool QQuickSwipeDelegatePrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEv
stopPressAndHold();
}
+ // The delegate can still be pressed when swipe.enabled is false,
+ // but the mouse moving shouldn't have any effect on swipe.position.
+ QQuickSwipePrivate *swipePrivate = QQuickSwipePrivate::get(&swipe);
+ if (!swipePrivate->enabled)
+ return false;
+
// Protect against division by zero.
if (width == 0)
return false;
// Don't bother reacting to events if we don't have any delegates.
- QQuickSwipePrivate *swipePrivate = QQuickSwipePrivate::get(&swipe);
if (!swipePrivate->left && !swipePrivate->right && !swipePrivate->behind)
return false;
@@ -819,6 +842,7 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) :
\qmlpropertygroup QtQuick.Controls::SwipeDelegate::swipe
\qmlproperty real QtQuick.Controls::SwipeDelegate::swipe.position
\qmlproperty bool QtQuick.Controls::SwipeDelegate::swipe.complete
+ \qmlproperty bool QtQuick.Controls::SwipeDelegate::swipe.enabled
\qmlproperty Component QtQuick.Controls::SwipeDelegate::swipe.left
\qmlproperty Component QtQuick.Controls::SwipeDelegate::swipe.behind
\qmlproperty Component QtQuick.Controls::SwipeDelegate::swipe.right
@@ -844,6 +868,11 @@ QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) :
When complete is \c true, any interactive items declared in \c left,
\c right, or \c behind will receive mouse events.
\row
+ \li enabled
+ \li This property determines whether or not the control can be swiped.
+
+ This property was added in QtQuick.Controls 2.2.
+ \row
\li left
\li This property holds the left delegate.
@@ -963,7 +992,11 @@ void QQuickSwipeDelegate::mousePressEvent(QMouseEvent *event)
{
Q_D(QQuickSwipeDelegate);
QQuickItemDelegate::mousePressEvent(event);
+
QQuickSwipePrivate *swipePrivate = QQuickSwipePrivate::get(&d->swipe);
+ if (!swipePrivate->enabled)
+ return;
+
swipePrivate->positionBeforePress = swipePrivate->position;
swipePrivate->velocityCalculator.startMeasuring(event->pos(), event->timestamp());
}