diff options
author | Matt Vogt <matthew.vogt@jollamobile.com> | 2012-11-29 08:35:00 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-29 06:39:10 +0100 |
commit | d02131e743597b9bd3070d986c61a1c91ea8317a (patch) | |
tree | 03f747e256d3c9d86891786aadee79673a509dbe /tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | |
parent | b68d7ab0a52ea9e94a3e62767357e0c735727969 (diff) |
Fix mouse event distribution for Flickable with pressDelay
If an item responds to mouse events but does not accept them, it
can prevent the events from being processed by the correct item
further up the parent chain. For example, a text item inside a
mouse area can wrongly consume a press event, so that the following
release event does not yield a click when processed by the mouse area.
Rather than speculatively assigning the mouse grab to items during
event filter processing, change Flickable to retain the grab for
the duration of the pressDelay and to release it during replay of
the press event.
Change-Id: Ied12b9643838a984c7026978047465c2830e55e4
Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
Diffstat (limited to 'tests/auto/quick/qquickflickable/tst_qquickflickable.cpp')
-rw-r--r-- | tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index ceed276305..66071e65d4 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -346,9 +346,13 @@ void tst_qquickflickable::flickDeceleration() void tst_qquickflickable::pressDelay() { - QQmlComponent component(&engine); - component.setData("import QtQuick 2.0; Flickable { pressDelay: 100; }", QUrl::fromLocalFile("")); - QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(component.create()); + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("pressDelay.qml")); + window->show(); + window->requestActivate(); + QVERIFY(window->rootObject() != 0); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); QSignalSpy spy(flickable, SIGNAL(pressDelayChanged())); QVERIFY(flickable); @@ -360,13 +364,28 @@ void tst_qquickflickable::pressDelay() flickable->setPressDelay(200); QCOMPARE(spy.count(),1); - delete flickable; + QQuickItem *mouseArea = window->rootObject()->findChild<QQuickItem*>("mouseArea"); + QSignalSpy clickedSpy(mouseArea, SIGNAL(clicked(QQuickMouseEvent*))); + + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + + // The press should not occur immediately + QVERIFY(mouseArea->property("pressed").toBool() == false); + + // But, it should occur eventually + QTRY_VERIFY(mouseArea->property("pressed").toBool() == true); + + QCOMPARE(clickedSpy.count(),0); + + // On release the clicked signal should be emitted + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + QCOMPARE(clickedSpy.count(),1); } // QTBUG-17361 void tst_qquickflickable::nestedPressDelay() { - QQuickView *window = new QQuickView; + QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("nestedPressDelay.qml")); window->show(); window->requestActivate(); @@ -378,46 +397,46 @@ void tst_qquickflickable::nestedPressDelay() QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable"); QVERIFY(inner != 0); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(150, 150)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); // the MouseArea is not pressed immediately QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(inner->property("pressed").toBool() == false); - // The outer pressDelay will prevail (50ms, vs. 10sec) + // The inner pressDelay will prevail (50ms, vs. 10sec) // QTRY_VERIFY() has 5sec timeout, so will timeout well within 10sec. QTRY_VERIFY(outer->property("pressed").toBool() == true); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(150, 150)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); // Dragging inner Flickable should work - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(80, 150)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(80, 150)); // the MouseArea is not pressed immediately QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(inner->property("pressed").toBool() == false); - QTest::mouseMove(window, QPoint(60, 150)); - QTest::mouseMove(window, QPoint(40, 150)); - QTest::mouseMove(window, QPoint(20, 150)); + QTest::mouseMove(window.data(), QPoint(60, 150)); + QTest::mouseMove(window.data(), QPoint(40, 150)); + QTest::mouseMove(window.data(), QPoint(20, 150)); - QVERIFY(outer->property("moving").toBool() == false); QVERIFY(inner->property("moving").toBool() == true); + QVERIFY(outer->property("moving").toBool() == false); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(20, 150)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(20, 150)); // Dragging the MouseArea in the inner Flickable should move the inner Flickable - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(150, 150)); + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); // the MouseArea is not pressed immediately QVERIFY(outer->property("pressed").toBool() == false); - QTest::mouseMove(window, QPoint(130, 150)); - QTest::mouseMove(window, QPoint(110, 150)); - QTest::mouseMove(window, QPoint(90, 150)); + 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() == false); QVERIFY(inner->property("moving").toBool() == true); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(90, 150)); - - delete window; + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(90, 150)); } void tst_qquickflickable::flickableDirection() |