diff options
Diffstat (limited to 'src/quicktemplates2/qquickswipedelegate.cpp')
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate.cpp | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index d4688867..2f7e7382 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,37 @@ 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::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); @@ -633,12 +666,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; @@ -820,6 +858,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() @@ -827,13 +886,14 @@ 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() */ /*! \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 @@ -859,6 +919,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. @@ -916,7 +981,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 { @@ -978,7 +1043,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()); } |