aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-01 13:23:47 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-02 13:07:30 +0000
commitdac19e5054c354752f4da8e1ec33cccde16a699b (patch)
tree7a1b9c4eeca971ae75b66c20086e9cd2606f110d
parentd00c6d93ce1974e27bb49c57ae87156260501577 (diff)
QQuickDrawer: fix velocity calculation
Use the vertical velocity for top and bottom edges, and invert the speed for right and bottom edges. Change-Id: I362dda23f0a2cda60ad7cd52e7373d0707feea83 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp18
-rw-r--r--tests/auto/drawer/tst_drawer.cpp3
2 files changed, 20 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp
index b5bebd9b..d11a8bdf 100644
--- a/src/quicktemplates2/qquickdrawer.cpp
+++ b/src/quicktemplates2/qquickdrawer.cpp
@@ -285,7 +285,23 @@ bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent
if (wasGrabbed) {
const QPointF releasePoint = event->windowPos();
velocityCalculator.stopMeasuring(releasePoint, event->timestamp());
- const qreal velocity = velocityCalculator.velocity().x();
+
+ 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();
diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp
index 0507d01e..0b334387 100644
--- a/tests/auto/drawer/tst_drawer.cpp
+++ b/tests/auto/drawer/tst_drawer.cpp
@@ -98,7 +98,10 @@ void tst_Drawer::position()
QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from);
QTest::mouseMove(window, to);
QCOMPARE(drawer->position(), position);
+
+ // moved half-way open at almost infinite speed => snap to open
QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to);
+ QTRY_COMPARE(drawer->position(), 1.0);
}
void tst_Drawer::dragMargin_data()