From 4c22c0cec688655e77ecbf8829b1477d12a3c10b Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 10 Mar 2015 11:59:23 +1000 Subject: Allow Flickable's grab to be stolen if dragging over bounds. This allows a parent item to intercept a drag gesture in one direction when the flickable has reached it's limit in that direction without disabling the drag over bounds for drag gestures in the opposite direction. Change-Id: I6ac60113f150dbb8da42d9b5593325b04be166f5 Reviewed-by: Martin Jones --- .../quick/qquickflickable/tst_qquickflickable.cpp | 51 ++++++++++++++++------ 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'tests/auto/quick/qquickflickable') diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 5c96cc151e..7d08c3c81e 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -1427,17 +1427,30 @@ void tst_qquickflickable::nestedStopAtBounds_data() { QTest::addColumn("transpose"); QTest::addColumn("invert"); - - QTest::newRow("left") << false << false; - QTest::newRow("right") << false << true; - QTest::newRow("top") << true << false; - QTest::newRow("bottom") << true << true; + QTest::addColumn("boundsBehavior"); + QTest::addColumn("margin"); + + QTest::newRow("left,stop") << false << false << int(QQuickFlickable::StopAtBounds) << qreal(0); + QTest::newRow("right,stop") << false << true << int(QQuickFlickable::StopAtBounds) << qreal(0); + QTest::newRow("top,stop") << true << false << int(QQuickFlickable::StopAtBounds) << qreal(0); + QTest::newRow("bottom,stop") << true << true << int(QQuickFlickable::StopAtBounds) << qreal(0); + QTest::newRow("left,over") << false << false << int(QQuickFlickable::DragOverBounds) << qreal(0); + QTest::newRow("right,over") << false << true << int(QQuickFlickable::DragOverBounds) << qreal(0); + QTest::newRow("top,over") << true << false << int(QQuickFlickable::DragOverBounds) << qreal(0); + QTest::newRow("bottom,over") << true << true << int(QQuickFlickable::DragOverBounds) << qreal(0); + + QTest::newRow("left,stop,margin") << false << false << int(QQuickFlickable::StopAtBounds) << qreal(20); + QTest::newRow("right,stop,margin") << false << true << int(QQuickFlickable::StopAtBounds) << qreal(20); + QTest::newRow("top,stop,margin") << true << false << int(QQuickFlickable::StopAtBounds) << qreal(20); + QTest::newRow("bottom,stop,margin") << true << true << int(QQuickFlickable::StopAtBounds) << qreal(20); } void tst_qquickflickable::nestedStopAtBounds() { QFETCH(bool, transpose); QFETCH(bool, invert); + QFETCH(int, boundsBehavior); + QFETCH(qreal, margin); QQuickView view; view.setSource(testFileUrl("nestedStopAtBounds.qml")); @@ -1455,8 +1468,20 @@ void tst_qquickflickable::nestedStopAtBounds() QQuickFlickable *inner = outer->findChild("innerFlickable"); QVERIFY(inner); inner->setFlickableDirection(transpose ? QQuickFlickable::VerticalFlick : QQuickFlickable::HorizontalFlick); - inner->setContentX(invert ? 0 : 100); - inner->setContentY(invert ? 0 : 100); + inner->setBoundsBehavior(QQuickFlickable::BoundsBehavior(boundsBehavior)); + + invert ? inner->setRightMargin(margin) : inner->setLeftMargin(margin); + invert ? inner->setBottomMargin(margin) : inner->setTopMargin(margin); + + inner->setContentX(invert ? -margin : 100 - margin); + inner->setContentY(invert ? -margin : 100 - margin); + inner->setContentWidth(400 - margin); + inner->setContentHeight(400 - margin); + + QCOMPARE(inner->isAtXBeginning(), invert); + QCOMPARE(inner->isAtXEnd(), !invert); + QCOMPARE(inner->isAtYBeginning(), invert); + QCOMPARE(inner->isAtYEnd(), !invert); const int threshold = qApp->styleHints()->startDragDistance(); @@ -1495,10 +1520,10 @@ void tst_qquickflickable::nestedStopAtBounds() QTRY_VERIFY(!outer->isMoving()); axis = 200; - inner->setContentX(0); - inner->setContentY(0); - inner->setContentWidth(inner->width()); - inner->setContentHeight(inner->height()); + inner->setContentX(-margin); + inner->setContentY(-margin); + inner->setContentWidth(inner->width() - margin); + inner->setContentHeight(inner->height() - margin); // Drag inner with equal size and contentSize QTest::mousePress(&view, Qt::LeftButton, 0, position); @@ -1512,8 +1537,8 @@ void tst_qquickflickable::nestedStopAtBounds() QTest::mouseRelease(&view, Qt::LeftButton, 0, position); axis = 200; - inner->setContentX(0); - inner->setContentY(0); + inner->setContentX(-margin); + inner->setContentY(-margin); inner->setContentWidth(inner->width() - 100); inner->setContentHeight(inner->height() - 100); -- cgit v1.2.3