aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickswipedelegate.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-10-04 11:21:46 +0200
committerMitch Curtis <mitch.curtis@qt.io>2016-11-23 10:48:32 +0000
commit9812a9cc1e71b0a3d8f25c0db2457f8673e53054 (patch)
tree0a7df0e367508a64728d5994b7500c7f3f08ad06 /src/quicktemplates2/qquickswipedelegate.cpp
parent2202d79b39ff90eed19fb8106f79d4604e47acfd (diff)
SwipeDelegate: don't emit clicked when released outside
If there are no delegates and hence the mouse hasn't been grabbed, we should clear the pressed state when the mouse is dragged outside the control. We can do so by falling back to the event handling of the base class (QQuickItemDelegate) when we have no delegates. This also ensures that the canceled() signal is emitted. A similar thing is done for controls with delegates, except that only the vertical position of the mouse is checked, as we still want to initiate swipes horizontally. Change-Id: I7738f5b9e8e8b6ce4a733008fa4ff73596e854ea Task-number: QTBUG-56312 Task-number: QTBUG-57285 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickswipedelegate.cpp')
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 3dec1f2e..0eac7fe1 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -35,6 +35,7 @@
****************************************************************************/
#include "qquickswipedelegate_p.h"
+#include "qquickswipedelegate_p_p.h"
#include "qquickcontrol_p_p.h"
#include "qquickitemdelegate_p_p.h"
#include "qquickvelocitycalculator_p_p.h"
@@ -142,6 +143,8 @@ public:
void warnAboutMixingDelegates();
void warnAboutSettingDelegatesWhileVisible();
+ bool hasDelegates() const;
+
QQuickSwipeDelegate *control;
// Same range as position, but is set before press events so that we can
// keep track of which direction the user must swipe when using left and right delegates.
@@ -342,6 +345,11 @@ void QQuickSwipePrivate::warnAboutSettingDelegatesWhileVisible()
qmlInfo(control) << "left/right/behind properties may only be set when swipe.position is 0";
}
+bool QQuickSwipePrivate::hasDelegates() const
+{
+ return left || right || behind;
+}
+
QQuickSwipe::QQuickSwipe(QQuickSwipeDelegate *control) :
QObject(*(new QQuickSwipePrivate(control)))
{
@@ -376,6 +384,8 @@ void QQuickSwipe::setLeft(QQmlComponent *left)
d->leftItem = nullptr;
}
+ d->control->setFiltersChildMouseEvents(d->hasDelegates());
+
emit leftChanged();
}
@@ -408,6 +418,8 @@ void QQuickSwipe::setBehind(QQmlComponent *behind)
d->behindItem = nullptr;
}
+ d->control->setFiltersChildMouseEvents(d->hasDelegates());
+
emit behindChanged();
}
@@ -440,6 +452,8 @@ void QQuickSwipe::setRight(QQmlComponent *right)
d->rightItem = nullptr;
}
+ d->control->setFiltersChildMouseEvents(d->hasDelegates());
+
emit rightChanged();
}
@@ -552,24 +566,10 @@ void QQuickSwipe::setComplete(bool complete)
emit completeChanged();
}
-class QQuickSwipeDelegatePrivate : public QQuickItemDelegatePrivate
+QQuickSwipeDelegatePrivate::QQuickSwipeDelegatePrivate(QQuickSwipeDelegate *control) :
+ swipe(control)
{
- Q_DECLARE_PUBLIC(QQuickSwipeDelegate)
-
-public:
- QQuickSwipeDelegatePrivate(QQuickSwipeDelegate *control) :
- swipe(control)
- {
- }
-
- bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event);
- bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event);
- bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event);
-
- void resizeContent() override;
-
- QQuickSwipe swipe;
-};
+}
bool QQuickSwipeDelegatePrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *event)
{
@@ -673,6 +673,13 @@ bool QQuickSwipeDelegatePrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEv
swipe.setPosition(position);
}
+ } else {
+ // The swipe wasn't initiated.
+ if (event->pos().y() < 0 || event->pos().y() > height) {
+ // The mouse went outside the vertical bounds of the control, so
+ // we should no longer consider it pressed.
+ q->setPressed(false);
+ }
}
event->accept();
@@ -748,7 +755,6 @@ void QQuickSwipeDelegatePrivate::resizeContent()
QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) :
QQuickItemDelegate(*(new QQuickSwipeDelegatePrivate(this)), parent)
{
- setFiltersChildMouseEvents(true);
}
/*!
@@ -885,14 +891,17 @@ void QQuickSwipeDelegate::mousePressEvent(QMouseEvent *event)
void QQuickSwipeDelegate::mouseMoveEvent(QMouseEvent *event)
{
Q_D(QQuickSwipeDelegate);
- d->handleMouseMoveEvent(this, event);
+ if (filtersChildMouseEvents())
+ d->handleMouseMoveEvent(this, event);
+ else
+ QQuickItemDelegate::mouseMoveEvent(event);
}
void QQuickSwipeDelegate::mouseReleaseEvent(QMouseEvent *event)
{
Q_D(QQuickSwipeDelegate);
- QQuickItemDelegate::mouseReleaseEvent(event);
- d->handleMouseReleaseEvent(this, event);
+ if (!filtersChildMouseEvents() || !d->handleMouseReleaseEvent(this, event))
+ QQuickItemDelegate::mouseReleaseEvent(event);
}
void QQuickSwipeDelegate::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)