diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-12-20 11:15:55 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-12-20 10:52:52 +0000 |
commit | 880381d92c12f32c8d8f7680454bd68d36187258 (patch) | |
tree | 4bb1a22a374b7461f9b3ecf9ca1a0054be391fee /src | |
parent | 98e1d85d7fcf7bb601518be6956f5473b79b6819 (diff) |
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 <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/templates/qquickdrawer.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
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<qreal>(0.0, q->positionAt(movePoint) - position); } } } |