diff options
author | Liang Qi <liang.qi@qt.io> | 2016-10-18 08:33:26 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-10-18 08:33:26 +0200 |
commit | f04c2c40fd7ee91e5cbff2ca4df0fdc30dfbbcd5 (patch) | |
tree | 4e96d097987deb8d4d1a963e911dcbd1641a8502 /tests/auto/quick | |
parent | 0da811cdfebdae1d96c99fe681e6a776e73d2f7f (diff) | |
parent | e76ed6a2655894bd671ee7397a15f2e57cfc8d33 (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
src/qml/jsruntime/qv4variantobject.cpp
src/qml/types/qquickworkerscript.cpp
src/quick/scenegraph/util/qsgdefaultpainternode_p.h
tools/qmljs/qmljs.cpp
Change-Id: I876242714ec8c046238d8fd673a5ace2455b2b59
Diffstat (limited to 'tests/auto/quick')
11 files changed, 507 insertions, 52 deletions
diff --git a/tests/auto/quick/geometry/tst_geometry.cpp b/tests/auto/quick/geometry/tst_geometry.cpp index 470ce3bd91..904f85c4c6 100644 --- a/tests/auto/quick/geometry/tst_geometry.cpp +++ b/tests/auto/quick/geometry/tst_geometry.cpp @@ -126,9 +126,9 @@ void GeometryTest::testCustomGeometry() }; static QSGGeometry::Attribute attributes[] = { - QSGGeometry::Attribute::create(0, 2, QSGGeometry::TypeFloat, false), - QSGGeometry::Attribute::create(1, 4, QSGGeometry::TypeUnsignedByte, false), - QSGGeometry::Attribute::create(2, 4, QSGGeometry::TypeFloat, false) + QSGGeometry::Attribute::create(0, 2, QSGGeometry::FloatType, false), + QSGGeometry::Attribute::create(1, 4, QSGGeometry::UnsignedByteType, false), + QSGGeometry::Attribute::create(2, 4, QSGGeometry::FloatType, false) }; static QSGGeometry::AttributeSet set = { 4, 6 * sizeof(float) + 4 * sizeof(unsigned char), attributes }; diff --git a/tests/auto/quick/qquickflickable/data/keepGrab.qml b/tests/auto/quick/qquickflickable/data/keepGrab.qml new file mode 100644 index 0000000000..32546658d0 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/keepGrab.qml @@ -0,0 +1,22 @@ +import QtQuick 2.3 + +Flickable { + id: flickable + width: 400 + height: 400 + contentWidth: 800 + contentHeight: 800 + + Rectangle { + x: 200 + y: 200 + width: 400 + height: 400 + color: "green" + MouseArea { + id: ma + objectName: "ma" + anchors.fill: parent + } + } +} diff --git a/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml b/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml index 59318e5b95..81187f3c2f 100644 --- a/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml +++ b/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml @@ -32,6 +32,10 @@ Flickable { anchors.margins: 100 color: "blue" } + MouseArea { + anchors.fill: parent + objectName: "mouseArea" + } } } } diff --git a/tests/auto/quick/qquickflickable/data/wheel.qml b/tests/auto/quick/qquickflickable/data/wheel.qml index 2928bbcd72..2be543cdde 100644 --- a/tests/auto/quick/qquickflickable/data/wheel.qml +++ b/tests/auto/quick/qquickflickable/data/wheel.qml @@ -8,9 +8,14 @@ Rectangle { Flickable { id: flick objectName: "flick" + property bool ended: false + property int movementsAfterEnd: 0 anchors.fill: parent contentWidth: 800 contentHeight: 800 + onContentXChanged: if (ended) ++movementsAfterEnd + onContentYChanged: if (ended) ++movementsAfterEnd + onMovementEnded: ended = true Rectangle { width: flick.contentWidth diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index a03e3b8170..b774481592 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -33,6 +33,7 @@ #include <QtQuick/qquickview.h> #include <private/qquickflickable_p.h> #include <private/qquickflickable_p_p.h> +#include <private/qquickmousearea_p.h> #include <private/qquicktransition_p.h> #include <private/qqmlvaluetype_p.h> #include <math.h> @@ -69,6 +70,7 @@ private slots: void returnToBounds(); void returnToBounds_data(); void wheel(); + void trackpad(); void movingAndFlicking(); void movingAndFlicking_data(); void movingAndDragging(); @@ -92,6 +94,7 @@ private slots: void contentSize(); void ratios_smallContent(); void contentXYNotTruncatedToInt(); + void keepGrab(); private: void flickWithTouch(QQuickWindow *window, QTouchDevice *touchDevice, const QPoint &from, const QPoint &to); @@ -487,8 +490,20 @@ void tst_qquickflickable::nestedPressDelay() // QTRY_VERIFY() has 5sec timeout, so will timeout well within 10sec. QTRY_VERIFY(outer->property("pressed").toBool()); + QTest::mouseMove(window.data(), QPoint(130, 150)); + QTest::mouseMove(window.data(), QPoint(110, 150)); + QTest::mouseMove(window.data(), QPoint(90, 150)); + + QVERIFY(!outer->property("moving").toBool()); + QVERIFY(!outer->property("dragging").toBool()); + QVERIFY(inner->property("moving").toBool()); + QVERIFY(inner->property("dragging").toBool()); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + QVERIFY(!inner->property("dragging").toBool()); + QTRY_VERIFY(!inner->property("moving").toBool()); + // Dragging inner Flickable should work moveAndPress(window.data(), QPoint(80, 150)); // the MouseArea is not pressed immediately @@ -500,10 +515,15 @@ void tst_qquickflickable::nestedPressDelay() QTest::mouseMove(window.data(), QPoint(20, 150)); QVERIFY(inner->property("moving").toBool()); + QVERIFY(inner->property("dragging").toBool()); QVERIFY(!outer->property("moving").toBool()); + QVERIFY(!outer->property("dragging").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(20, 150)); + QVERIFY(!inner->property("dragging").toBool()); + QTRY_VERIFY(!inner->property("moving").toBool()); + // Dragging the MouseArea in the inner Flickable should move the inner Flickable moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately @@ -513,11 +533,15 @@ void tst_qquickflickable::nestedPressDelay() QTest::mouseMove(window.data(), QPoint(110, 150)); QTest::mouseMove(window.data(), QPoint(90, 150)); - QVERIFY(!outer->property("moving").toBool()); + QVERIFY(!outer->property("dragging").toBool()); QVERIFY(inner->property("moving").toBool()); + QVERIFY(inner->property("dragging").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(90, 150)); + + QVERIFY(!inner->property("dragging").toBool()); + QTRY_VERIFY(!inner->property("moving").toBool()); } void tst_qquickflickable::filterReplayedPress() @@ -720,7 +744,10 @@ void tst_qquickflickable::wheel() QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flick"); QVERIFY(flick != 0); + QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flick); + QSignalSpy moveEndSpy(flick, SIGNAL(movementEnded())); + // test a vertical flick { QPoint pos(200, 200); QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(), QPoint(0,-120), -120, Qt::Vertical, Qt::NoButton, Qt::NoModifier); @@ -731,9 +758,19 @@ void tst_qquickflickable::wheel() QTRY_VERIFY(flick->contentY() > 0); QCOMPARE(flick->contentX(), qreal(0)); - flick->setContentY(0); + QTRY_COMPARE(moveEndSpy.count(), 1); + QCOMPARE(fp->velocityTimeline.isActive(), false); + QCOMPARE(fp->timeline.isActive(), false); + QTest::qWait(50); // make sure that onContentYChanged won't sneak in again + QCOMPARE(flick->property("movementsAfterEnd").value<int>(), 0); // QTBUG-55886 + + // get ready to test horizontal flick + flick->setContentY(0); // which triggers movementEnded again + flick->setProperty("movementsAfterEnd", 0); + flick->setProperty("ended", false); QCOMPARE(flick->contentY(), qreal(0)); + // test a horizontal flick { QPoint pos(200, 200); QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(), QPoint(-120,0), -120, Qt::Horizontal, Qt::NoButton, Qt::NoModifier); @@ -744,6 +781,55 @@ void tst_qquickflickable::wheel() QTRY_VERIFY(flick->contentX() > 0); QCOMPARE(flick->contentY(), qreal(0)); + QTRY_COMPARE(moveEndSpy.count(), 2); + QCOMPARE(fp->velocityTimeline.isActive(), false); + QCOMPARE(fp->timeline.isActive(), false); + QTest::qWait(50); // make sure that onContentXChanged won't sneak in again + QCOMPARE(flick->property("movementsAfterEnd").value<int>(), 0); // QTBUG-55886 +} + +void tst_qquickflickable::trackpad() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("wheel.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QVERIFY(window->rootObject() != 0); + + QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flick"); + QVERIFY(flick != 0); + QSignalSpy moveEndSpy(flick, SIGNAL(movementEnded())); + QPoint pos(200, 200); + + { + QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(0,-100), QPoint(0,-120), -120, Qt::Vertical, Qt::NoButton, Qt::NoModifier, Qt::ScrollBegin); + event.setAccepted(false); + QGuiApplication::sendEvent(window.data(), &event); + } + + QTRY_VERIFY(flick->contentY() > 0); + QCOMPARE(flick->contentX(), qreal(0)); + + flick->setContentY(0); + QCOMPARE(flick->contentY(), qreal(0)); + + { + QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(-100,0), QPoint(-120,0), -120, Qt::Horizontal, Qt::NoButton, Qt::NoModifier, Qt::ScrollUpdate); + event.setAccepted(false); + QGuiApplication::sendEvent(window.data(), &event); + } + + QTRY_VERIFY(flick->contentX() > 0); + QCOMPARE(flick->contentY(), qreal(0)); + + { + QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(0,0), QPoint(0,0), 0, Qt::Horizontal, Qt::NoButton, Qt::NoModifier, Qt::ScrollEnd); + event.setAccepted(false); + QGuiApplication::sendEvent(window.data(), &event); + } + + QTRY_COMPARE(moveEndSpy.count(), 1); // QTBUG-55871 + QCOMPARE(flick->property("movementsAfterEnd").value<int>(), 0); // QTBUG-55886 } void tst_qquickflickable::movingAndFlicking_data() @@ -1475,20 +1561,26 @@ void tst_qquickflickable::nestedStopAtBounds_data() QTest::addColumn<bool>("invert"); QTest::addColumn<int>("boundsBehavior"); QTest::addColumn<qreal>("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); + QTest::addColumn<bool>("innerFiltering"); + QTest::addColumn<int>("pressDelay"); + QTest::addColumn<bool>("waitForPressDelay"); + + QTest::newRow("left,stop") << false << false << int(QQuickFlickable::StopAtBounds) << qreal(0) << false << 0 << false; + QTest::newRow("right,stop") << false << true << int(QQuickFlickable::StopAtBounds) << qreal(0) << false << 0 << false; + QTest::newRow("top,stop") << true << false << int(QQuickFlickable::StopAtBounds) << qreal(0) << false << 0 << false; + QTest::newRow("bottom,stop") << true << true << int(QQuickFlickable::StopAtBounds) << qreal(0) << false << 0 << false; + QTest::newRow("left,over") << false << false << int(QQuickFlickable::DragOverBounds) << qreal(0) << false << 0 << false; + QTest::newRow("right,over") << false << true << int(QQuickFlickable::DragOverBounds) << qreal(0) << false << 0 << false; + QTest::newRow("top,over") << true << false << int(QQuickFlickable::DragOverBounds) << qreal(0) << false << 0 << false; + QTest::newRow("bottom,over") << true << true << int(QQuickFlickable::DragOverBounds) << qreal(0) << false << 0 << false; + + QTest::newRow("left,stop,margin") << false << false << int(QQuickFlickable::StopAtBounds) << qreal(20) << false << 0 << false; + QTest::newRow("right,stop,margin") << false << true << int(QQuickFlickable::StopAtBounds) << qreal(20) << false << 0 << false; + QTest::newRow("top,stop,margin") << true << false << int(QQuickFlickable::StopAtBounds) << qreal(20) << false << 0 << false; + QTest::newRow("bottom,stop,margin") << true << true << int(QQuickFlickable::StopAtBounds) << qreal(20) << false << 0 << false; + + QTest::newRow("left,stop,after press delay") << false << false << int(QQuickFlickable::StopAtBounds) << qreal(0) << true << 50 << true; + QTest::newRow("left,stop,before press delay") << false << false << int(QQuickFlickable::StopAtBounds) << qreal(0) << true << 50 << false; } void tst_qquickflickable::nestedStopAtBounds() @@ -1497,6 +1589,9 @@ void tst_qquickflickable::nestedStopAtBounds() QFETCH(bool, invert); QFETCH(int, boundsBehavior); QFETCH(qreal, margin); + QFETCH(bool, innerFiltering); + QFETCH(int, pressDelay); + QFETCH(bool, waitForPressDelay); QQuickView view; view.setSource(testFileUrl("nestedStopAtBounds.qml")); @@ -1529,6 +1624,12 @@ void tst_qquickflickable::nestedStopAtBounds() QCOMPARE(inner->isAtYBeginning(), invert); QCOMPARE(inner->isAtYEnd(), !invert); + inner->setPressDelay(pressDelay); + + QQuickMouseArea *mouseArea = inner->findChild<QQuickMouseArea *>("mouseArea"); + QVERIFY(mouseArea); + mouseArea->setEnabled(innerFiltering); + const int threshold = qApp->styleHints()->startDragDistance(); QPoint position(200, 200); @@ -1536,17 +1637,25 @@ void tst_qquickflickable::nestedStopAtBounds() // drag toward the aligned boundary. Outer flickable dragged. moveAndPress(&view, position); - QTest::qWait(10); + if (waitForPressDelay) { + QVERIFY(innerFiltering); // isPressed will never be true if the mouse area isn't enabled. + QTRY_VERIFY(mouseArea->pressed()); + } + axis += invert ? threshold * 2 : -threshold * 2; QTest::mouseMove(&view, position); axis += invert ? threshold : -threshold; QTest::mouseMove(&view, position); QCOMPARE(outer->isDragging(), true); + QCOMPARE(outer->isMoving(), true); QCOMPARE(inner->isDragging(), false); + QCOMPARE(inner->isMoving(), false); QTest::mouseRelease(&view, Qt::LeftButton, 0, position); QVERIFY(!outer->isDragging()); QTRY_VERIFY(!outer->isMoving()); + QVERIFY(!inner->isDragging()); + QVERIFY(!inner->isMoving()); axis = 200; outer->setContentX(50); @@ -1560,10 +1669,15 @@ void tst_qquickflickable::nestedStopAtBounds() axis += invert ? -threshold : threshold; QTest::mouseMove(&view, position); QCOMPARE(outer->isDragging(), false); + QCOMPARE(outer->isMoving(), false); QCOMPARE(inner->isDragging(), true); + QCOMPARE(inner->isMoving(), true); QTest::mouseRelease(&view, Qt::LeftButton, 0, position); - QTRY_VERIFY(!outer->isMoving()); + QVERIFY(!inner->isDragging()); + QTRY_VERIFY(!inner->isMoving()); + QVERIFY(!outer->isDragging()); + QVERIFY(!outer->isMoving()); axis = 200; inner->setContentX(-margin); @@ -1579,9 +1693,16 @@ void tst_qquickflickable::nestedStopAtBounds() axis += invert ? -threshold : threshold; QTest::mouseMove(&view, position); QCOMPARE(outer->isDragging(), true); + QCOMPARE(outer->isMoving(), true); QCOMPARE(inner->isDragging(), false); + QCOMPARE(inner->isMoving(), false); QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + QVERIFY(!outer->isDragging()); + QTRY_VERIFY(!outer->isMoving()); + QVERIFY(!inner->isDragging()); + QVERIFY(!inner->isMoving()); + axis = 200; inner->setContentX(-margin); inner->setContentY(-margin); @@ -1596,8 +1717,15 @@ void tst_qquickflickable::nestedStopAtBounds() axis += invert ? -threshold : threshold; QTest::mouseMove(&view, position); QCOMPARE(outer->isDragging(), true); + QCOMPARE(outer->isMoving(), true); QCOMPARE(inner->isDragging(), false); + QCOMPARE(inner->isMoving(), false); QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + + QVERIFY(!outer->isDragging()); + QTRY_VERIFY(!outer->isMoving()); + QVERIFY(!inner->isDragging()); + QVERIFY(!inner->isMoving()); } void tst_qquickflickable::stopAtBounds_data() @@ -1863,6 +1991,52 @@ void tst_qquickflickable::contentXYNotTruncatedToInt() QVERIFY(flickable->contentX() > qreal(1e10)); } +void tst_qquickflickable::keepGrab() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("keepGrab.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickViewTestUtil::centerOnScreen(window.data()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable); + + QQuickMouseArea *ma = flickable->findChild<QQuickMouseArea*>("ma"); + QVERIFY(ma); + ma->setPreventStealing(true); + + QPoint pos(250, 250); + moveAndPress(window.data(), pos); + for (int i = 0; i < 6; ++i) { + pos += QPoint(10, 10); + QTest::mouseMove(window.data(), pos); + QTest::qWait(10); + } + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(310, 310)); + QTest::qWait(10); + + QCOMPARE(flickable->contentX(), 0.0); + QCOMPARE(flickable->contentY(), 0.0); + + ma->setPreventStealing(false); + + pos = QPoint(250, 250); + moveAndPress(window.data(), pos); + for (int i = 0; i < 6; ++i) { + pos += QPoint(10, 10); + QTest::mouseMove(window.data(), pos); + QTest::qWait(10); + } + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(310, 310)); + QTest::qWait(10); + + QVERIFY(flickable->contentX() != 0.0); + QVERIFY(flickable->contentY() != 0.0); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 9fedfb21ab..536bb40dcc 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -1771,56 +1771,56 @@ static void gc(QQmlEngine &engine) void tst_qquickitem::visualParentOwnership() { - QQuickView view; - view.setSource(testFileUrl("visualParentOwnership.qml")); + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("visualParentOwnership.qml")); - QQuickItem *root = qobject_cast<QQuickItem*>(view.rootObject()); + QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(component.create())); QVERIFY(root); QVariant newObject; { - QVERIFY(QMetaObject::invokeMethod(root, "createItemWithoutParent", Q_RETURN_ARG(QVariant, newObject))); + QVERIFY(QMetaObject::invokeMethod(root.data(), "createItemWithoutParent", Q_RETURN_ARG(QVariant, newObject))); QPointer<QQuickItem> newItem = qvariant_cast<QQuickItem*>(newObject); QVERIFY(!newItem.isNull()); QVERIFY(!newItem->parent()); QVERIFY(!newItem->parentItem()); - newItem->setParentItem(root); + newItem->setParentItem(root.data()); - gc(*view.engine()); + gc(engine); QVERIFY(!newItem.isNull()); newItem->setParentItem(0); - gc(*view.engine()); + gc(engine); QVERIFY(newItem.isNull()); } { - QVERIFY(QMetaObject::invokeMethod(root, "createItemWithoutParent", Q_RETURN_ARG(QVariant, newObject))); + QVERIFY(QMetaObject::invokeMethod(root.data(), "createItemWithoutParent", Q_RETURN_ARG(QVariant, newObject))); QPointer<QQuickItem> firstItem = qvariant_cast<QQuickItem*>(newObject); QVERIFY(!firstItem.isNull()); - firstItem->setParentItem(root); + firstItem->setParentItem(root.data()); - QVERIFY(QMetaObject::invokeMethod(root, "createItemWithoutParent", Q_RETURN_ARG(QVariant, newObject))); + QVERIFY(QMetaObject::invokeMethod(root.data(), "createItemWithoutParent", Q_RETURN_ARG(QVariant, newObject))); QPointer<QQuickItem> secondItem = qvariant_cast<QQuickItem*>(newObject); QVERIFY(!firstItem.isNull()); secondItem->setParentItem(firstItem); - gc(*view.engine()); + gc(engine); delete firstItem; root->setProperty("keepAliveProperty", newObject); - gc(*view.engine()); + gc(engine); QVERIFY(!secondItem.isNull()); root->setProperty("keepAliveProperty", QVariant()); - gc(*view.engine()); + gc(engine); QVERIFY(secondItem.isNull()); } } diff --git a/tests/auto/quick/qquickmousearea/data/nestedFlickableStopAtBounds.qml b/tests/auto/quick/qquickmousearea/data/nestedFlickableStopAtBounds.qml new file mode 100644 index 0000000000..0d5b496766 --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/nestedFlickableStopAtBounds.qml @@ -0,0 +1,44 @@ +import QtQuick 2.5 + + +Rectangle { + width: 240 + height: 320 + + MouseArea { + objectName: "mouseArea" + anchors.fill: parent + + drag.target: moveable + drag.filterChildren: true + + Rectangle { + id: moveable + objectName: "moveable" + color: "red" + x: 50 + y: 80 + width: 200 + height: 200 + } + + Flickable { + objectName: "flickable" + anchors.fill: parent + contentHeight: 450 + + Rectangle { + x: 100 + y: 50 + width: 50 + height: 350 + color: "yellow" + } + + MouseArea { + width: 240 + height: 450 + } + } + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index b69c6eedf8..f22528a8a0 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -122,6 +122,7 @@ private slots: void moveAndReleaseWithoutPress(); void nestedStopAtBounds(); void nestedStopAtBounds_data(); + void nestedFlickableStopAtBounds(); void containsPress_data(); void containsPress(); void ignoreBySource(); @@ -1814,6 +1815,98 @@ void tst_QQuickMouseArea::nestedStopAtBounds() QTest::mouseRelease(&view, Qt::LeftButton, 0, position); } +void tst_QQuickMouseArea::nestedFlickableStopAtBounds() +{ + QQuickView view; + QByteArray errorMessage; + QVERIFY2(initView(view, testFileUrl("nestedFlickableStopAtBounds.qml"), false, &errorMessage), errorMessage.constData()); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(view.rootObject()); + + QQuickMouseArea *mouseArea = view.rootObject()->findChild<QQuickMouseArea*>("mouseArea"); + QVERIFY(mouseArea); + + QQuickFlickable *flickable = mouseArea->findChild<QQuickFlickable*>("flickable"); + QVERIFY(flickable); + + const int threshold = qApp->styleHints()->startDragDistance(); + + QPoint position(200, 280); + int &pos = position.ry(); + + // Drag up - should move the Flickable to end + QTest::mousePress(&view, Qt::LeftButton, 0, position); + QTest::qWait(10); + pos -= threshold * 2; + QTest::mouseMove(&view, position); + pos -= threshold * 2; + QTest::mouseMove(&view, position); + QTest::qWait(10); + pos -= 150; + QTest::mouseMove(&view, position); + QVERIFY(flickable->isDragging()); + QVERIFY(!mouseArea->drag()->active()); + QCOMPARE(flickable->isAtYEnd(), true); + QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + + QTRY_VERIFY(!flickable->isMoving()); + + pos = 280; + + // Drag up again - should activate MouseArea drag + QVERIFY(!mouseArea->drag()->active()); + QTest::mousePress(&view, Qt::LeftButton, 0, position); + QTest::qWait(10); + pos -= threshold * 2; + QTest::mouseMove(&view, position); + pos -= threshold * 2; + QTest::mouseMove(&view, position); + QTest::qWait(10); + pos -= 20; + QTest::mouseMove(&view, position); + QVERIFY(mouseArea->drag()->active()); + QCOMPARE(flickable->isAtYEnd(), true); + QVERIFY(!flickable->isDragging()); + QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + + // Drag to the top and verify that the MouseArea doesn't steal the grab when we drag back (QTBUG-56036) + pos = 50; + + QTest::mousePress(&view, Qt::LeftButton, 0, position); + QTest::qWait(10); + pos += threshold; + QTest::mouseMove(&view, position); + pos += threshold; + QTest::mouseMove(&view, position); + QTest::qWait(10); + pos += 150; + QTest::mouseMove(&view, position); + QVERIFY(flickable->isDragging()); + QVERIFY(!mouseArea->drag()->active()); + QCOMPARE(flickable->isAtYBeginning(), true); + QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + + QTRY_VERIFY(!flickable->isMoving()); + + pos = 280; + + // Drag up again - should not activate MouseArea drag + QTest::mousePress(&view, Qt::LeftButton, 0, position); + QTest::qWait(10); + pos -= threshold; + QTest::mouseMove(&view, position); + pos -= threshold; + QTest::mouseMove(&view, position); + QTest::qWait(10); + pos -= 100; + QTest::mouseMove(&view, position); + QVERIFY(flickable->isDragging()); + QVERIFY(!mouseArea->drag()->active()); + QTest::mouseRelease(&view, Qt::LeftButton, 0, position); +} + void tst_QQuickMouseArea::containsPress_data() { QTest::addColumn<bool>("hoverEnabled"); diff --git a/tests/auto/quick/qquicktext/data/hAlignWidthDependsOnImplicitWidth.qml b/tests/auto/quick/qquicktext/data/hAlignWidthDependsOnImplicitWidth.qml new file mode 100644 index 0000000000..4358a58f57 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/hAlignWidthDependsOnImplicitWidth.qml @@ -0,0 +1,25 @@ +import QtQuick 2.6 + +Item { + width: 200 + height: 200 + + property alias text: label.text + property alias horizontalAlignment: label.horizontalAlignment + property alias elide: label.elide + property int extraWidth: 0 + + Rectangle { + border.color: "red" + x: 100 + width: label.implicitWidth + extraWidth + height: label.implicitHeight + + Text { + id: label + anchors.fill: parent + text: 'press me' + horizontalAlignment: Text.AlignHCenter + } + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 6f7d494255..2032f72e26 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -151,6 +151,9 @@ private slots: void zeroWidthAndElidedDoesntRender(); + void hAlignWidthDependsOnImplicitWidth_data(); + void hAlignWidthDependsOnImplicitWidth(); + private: QStringList standard; QStringList richText; @@ -4115,6 +4118,18 @@ void tst_qquicktext::padding() QCOMPARE(obj->bottomPadding(), 1.11); QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + obj->setWidth(cw / 2); + obj->setElideMode(QQuickText::ElideRight); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + obj->setElideMode(QQuickText::ElideNone); + obj->resetWidth(); + + obj->setWrapMode(QQuickText::WordWrap); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + obj->setWrapMode(QQuickText::NoWrap); + obj->setText("Qt"); QVERIFY(obj->contentWidth() < cw); QCOMPARE(obj->contentHeight(), ch); @@ -4198,6 +4213,51 @@ void tst_qquicktext::zeroWidthAndElidedDoesntRender() QCOMPARE(text->contentWidth(), reference->contentWidth()); } +void tst_qquicktext::hAlignWidthDependsOnImplicitWidth_data() +{ + QTest::addColumn<QQuickText::HAlignment>("horizontalAlignment"); + QTest::addColumn<QQuickText::TextElideMode>("elide"); + QTest::addColumn<int>("extraWidth"); + + QTest::newRow("AlignHCenter, ElideNone, 0 extraWidth") << QQuickText::AlignHCenter << QQuickText::ElideNone << 0; + QTest::newRow("AlignRight, ElideNone, 0 extraWidth") << QQuickText::AlignRight << QQuickText::ElideNone << 0; + QTest::newRow("AlignHCenter, ElideRight, 0 extraWidth") << QQuickText::AlignHCenter << QQuickText::ElideRight << 0; + QTest::newRow("AlignRight, ElideRight, 0 extraWidth") << QQuickText::AlignRight << QQuickText::ElideRight << 0; + QTest::newRow("AlignHCenter, ElideNone, 20 extraWidth") << QQuickText::AlignHCenter << QQuickText::ElideNone << 20; + QTest::newRow("AlignRight, ElideNone, 20 extraWidth") << QQuickText::AlignRight << QQuickText::ElideNone << 20; + QTest::newRow("AlignHCenter, ElideRight, 20 extraWidth") << QQuickText::AlignHCenter << QQuickText::ElideRight << 20; + QTest::newRow("AlignRight, ElideRight, 20 extraWidth") << QQuickText::AlignRight << QQuickText::ElideRight << 20; +} + +void tst_qquicktext::hAlignWidthDependsOnImplicitWidth() +{ + QFETCH(QQuickText::HAlignment, horizontalAlignment); + QFETCH(QQuickText::TextElideMode, elide); + QFETCH(int, extraWidth); + + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("hAlignWidthDependsOnImplicitWidth.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickItem *rect = window->rootObject(); + QVERIFY(rect); + + QVERIFY(rect->setProperty("horizontalAlignment", horizontalAlignment)); + QVERIFY(rect->setProperty("elide", elide)); + QVERIFY(rect->setProperty("extraWidth", extraWidth)); + + QImage image = window->grabWindow(); + const int rectX = 100 * window->screen()->devicePixelRatio(); + QCOMPARE(numberOfNonWhitePixels(0, rectX - 1, image), 0); + + QVERIFY(rect->setProperty("text", "this is mis-aligned")); + image = window->grabWindow(); + QCOMPARE(numberOfNonWhitePixels(0, rectX - 1, image), 0); +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index 1594da46bd..309c01dcdc 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -151,6 +151,7 @@ private slots: void mouseOverTouch(); void buttonOnFlickable(); + void buttonOnDelayedPressFlickable_data(); void buttonOnDelayedPressFlickable(); void buttonOnTouch(); @@ -611,11 +612,25 @@ void tst_TouchMouse::buttonOnFlickable() delete window; } +void tst_TouchMouse::buttonOnDelayedPressFlickable_data() +{ + QTest::addColumn<bool>("scrollBeforeDelayIsOver"); + + // the item should never see the event, + // due to the pressDelay which never delivers if we start moving + QTest::newRow("scroll before press delay is over") << true; + + // wait until the "button" sees the press but then + // start moving: the button gets a press and cancel event + QTest::newRow("scroll after press delay is over") << false; +} + void tst_TouchMouse::buttonOnDelayedPressFlickable() { // flickable - height 500 / 1000 // - eventItem1 y: 100, height 100 // - eventItem2 y: 300, height 100 + QFETCH(bool, scrollBeforeDelayIsOver); qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true); filteredEventList.clear(); @@ -634,7 +649,8 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() window->installEventFilter(this); - flickable->setPressDelay(60); + // wait 600 ms before letting the child see the press event + flickable->setPressDelay(600); // should a mouse area button be clickable on top of flickable? yes :) EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1"); @@ -650,26 +666,23 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() // wait to avoid getting a double click event QTest::qWait(qApp->styleHints()->mouseDoubleClickInterval() + 10); + QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window); + QCOMPARE(windowPriv->touchMouseId, -1); // no grabber - // check that flickable moves - mouse button - QCOMPARE(eventItem1->eventList.size(), 0); + // touch press QPoint p1 = QPoint(10, 110); QTest::touchEvent(window, device).press(0, p1, window); QQuickTouchUtils::flush(window); - // Flickable initially steals events - QCOMPARE(eventItem1->eventList.size(), 0); - // but we'll get the delayed mouse press after a delay - QTRY_COMPARE(eventItem1->eventList.size(), 1); - QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress); - QCOMPARE(filteredEventList.count(), 1); - // eventItem1 should have the mouse grab, and have moved the grab - // for the touchMouseId to the new grabber. - QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window); - QCOMPARE(windowPriv->touchMouseId, 0); - auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent(); - QCOMPARE(pointerEvent->point(0)->grabber(), eventItem1); - QCOMPARE(window->mouseGrabberItem(), eventItem1); + if (scrollBeforeDelayIsOver) { + // no events, the flickable got scrolled, the button sees nothing + QCOMPARE(eventItem1->eventList.size(), 0); + } else { + // wait until the button sees the press + QTRY_COMPARE(eventItem1->eventList.size(), 1); + QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress); + QCOMPARE(filteredEventList.count(), 1); + } p1 += QPoint(0, -10); QPoint p2 = p1 + QPoint(0, -10); @@ -681,12 +694,24 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() QQuickTouchUtils::flush(window); QTest::touchEvent(window, device).move(0, p3, window); QQuickTouchUtils::flush(window); - QVERIFY(flickable->isMovingVertically()); + QTRY_VERIFY(flickable->isMovingVertically()); + + if (scrollBeforeDelayIsOver) { + QCOMPARE(eventItem1->eventList.size(), 0); + QCOMPARE(filteredEventList.count(), 0); + } else { + // see at least press, move and ungrab + QTRY_VERIFY(eventItem1->eventList.size() > 2); + QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress); + QCOMPARE(eventItem1->eventList.last().type, QEvent::UngrabMouse); + QCOMPARE(filteredEventList.count(), 1); + } // flickable should have the mouse grab, and have moved the itemForTouchPointId // for the touchMouseId to the new grabber. QCOMPARE(window->mouseGrabberItem(), flickable); QCOMPARE(windowPriv->touchMouseId, 0); + auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent(); QCOMPARE(pointerEvent->point(0)->grabber(), flickable); QTest::touchEvent(window, device).release(0, p3, window); @@ -694,7 +719,10 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() // We should not have received any synthesised mouse events from Qt gui, // just the delayed press. - QCOMPARE(filteredEventList.count(), 1); + if (scrollBeforeDelayIsOver) + QCOMPARE(filteredEventList.count(), 0); + else + QCOMPARE(filteredEventList.count(), 1); delete window; } |