diff options
Diffstat (limited to 'tests/auto/quick')
8 files changed, 388 insertions, 31 deletions
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 18dd1bc325..b774481592 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -70,6 +70,7 @@ private slots: void returnToBounds(); void returnToBounds_data(); void wheel(); + void trackpad(); void movingAndFlicking(); void movingAndFlicking_data(); void movingAndDragging(); @@ -489,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 @@ -502,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 @@ -515,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() @@ -722,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); @@ -733,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); @@ -746,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() @@ -1477,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() @@ -1499,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")); @@ -1531,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); @@ -1538,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); @@ -1562,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); @@ -1581,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); @@ -1598,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() 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" |