From 880381d92c12f32c8d8f7680454bd68d36187258 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 20 Dec 2015 11:15:55 +0100 Subject: Drawer: tweak thresholds & offsets This makes the drawer behave much better. Use increased threshold only for dragging, not for presses (steals too large area from the side). When closing by dragging from the outside of the drawer, set the offset so that the drawer starts moving when the finger reaches the drawer, not before. Change-Id: Ibb8bf8f67f490e0706b6230080907bb185bd25bc Reviewed-by: J-P Nurmi --- src/templates/qquickdrawer.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/templates') diff --git a/src/templates/qquickdrawer.cpp b/src/templates/qquickdrawer.cpp index c2c2c3bb..e1979903 100644 --- a/src/templates/qquickdrawer.cpp +++ b/src/templates/qquickdrawer.cpp @@ -134,13 +134,8 @@ void QQuickDrawerPrivate::updateContent() } } -static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event) +static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int threshold = -1) { - // Flickable uses a hard-coded threshold of 15 for flicking, and - // QStyleHints::startDragDistance for dragging. Drawer uses a bit - // larger threshold to avoid being too eager to steal touch (QTBUG-50045) - int threshold = qMax(20, QGuiApplication::styleHints()->startDragDistance() + 5); - return QQuickWindowPrivate::dragOverThreshold(d, axis, event, threshold); } @@ -148,6 +143,7 @@ bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *e { Q_Q(QQuickDrawer); pressPoint = q->mapFromItem(item, event->pos()); + offset = 0; if (qFuzzyIsNull(position)) { // only accept pressing at drag margins when fully closed @@ -165,10 +161,8 @@ bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *e event->setAccepted(!dragOverThreshold(q->height() - event->y(), Qt::YAxis, event)); break; } - offset = 0; } else { event->accept(); - offset = q->positionAt(pressPoint) - position; } return item == q; @@ -180,17 +174,22 @@ bool QQuickDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *ev QPointF movePoint = q->mapFromItem(item, event->pos()); if (!q->keepMouseGrab()) { + // Flickable uses a hard-coded threshold of 15 for flicking, and + // QStyleHints::startDragDistance for dragging. Drawer uses a bit + // larger threshold to avoid being too eager to steal touch (QTBUG-50045) + int threshold = qMax(20, QGuiApplication::styleHints()->startDragDistance() + 5); bool overThreshold = false; if (edge == Qt::LeftEdge || edge == Qt::RightEdge) - overThreshold = dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event); + overThreshold = dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event, threshold); else - overThreshold = dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event); + overThreshold = dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); if (window && overThreshold) { QQuickItem *grabber = q->window()->mouseGrabberItem(); if (!grabber || !grabber->keepMouseGrab()) { q->grabMouse(); q->setKeepMouseGrab(overThreshold); + offset = qMin(0.0, q->positionAt(movePoint) - position); } } } -- cgit v1.2.3