diff options
Diffstat (limited to 'src/quicktemplates2/qquickdrawer.cpp')
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index e2e6c84e..bb68320d 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -283,8 +283,25 @@ bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent bool wasGrabbed = popupItem->keepMouseGrab(); if (wasGrabbed) { - velocityCalculator.stopMeasuring(event->pos(), event->timestamp()); - const qreal velocity = velocityCalculator.velocity().x(); + const QPointF releasePoint = event->windowPos(); + velocityCalculator.stopMeasuring(releasePoint, event->timestamp()); + + qreal velocity = 0; + if (edge == Qt::LeftEdge || edge == Qt::RightEdge) + velocity = velocityCalculator.velocity().x(); + else + velocity = velocityCalculator.velocity().y(); + + // the velocity is calculated so that swipes from left to right + // and top to bottom have positive velocity, and swipes from right + // to left and bottom to top have negative velocity. + // + // - top/left edge: positive velocity opens, negative velocity closes + // - bottom/right edge: negative velocity opens, positive velocity closes + // + // => invert the velocity for bottom and right edges, for the threshold comparison below + if (edge == Qt::RightEdge || edge == Qt::BottomEdge) + velocity = -velocity; if (position > 0.7 || velocity > openCloseVelocityThreshold) { transitionManager.transitionEnter(); @@ -293,25 +310,25 @@ bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent } else { switch (edge) { case Qt::LeftEdge: - if (event->x() - pressPoint.x() > 0) + if (releasePoint.x() - pressPoint.x() > 0) transitionManager.transitionEnter(); else transitionManager.transitionExit(); break; case Qt::RightEdge: - if (event->x() - pressPoint.x() < 0) + if (releasePoint.x() - pressPoint.x() < 0) transitionManager.transitionEnter(); else transitionManager.transitionExit(); break; case Qt::TopEdge: - if (event->y() - pressPoint.y() > 0) + if (releasePoint.y() - pressPoint.y() > 0) transitionManager.transitionEnter(); else transitionManager.transitionExit(); break; case Qt::BottomEdge: - if (event->y() - pressPoint.y() < 0) + if (releasePoint.y() - pressPoint.y() < 0) transitionManager.transitionEnter(); else transitionManager.transitionExit(); |