diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2014-04-10 21:18:09 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-12 06:31:42 +0200 |
commit | 8da17239ed4a68270c74f6a5e5ca04d82d99b547 (patch) | |
tree | 9c9882364d9be9349f631a2c8fc027bc6c36d68c /tests/auto/quick/qquickitem2/tst_qquickitem.cpp | |
parent | 7254e09442278f9e083a423c832c24b58e8fedec (diff) |
Avoid event propagation with Keys.forwardTo
[ChangeLog][QtQuick][Important Behavior Changes] Keys.forwardTo no
longer propagates key events to the target item's parents. This makes
Keys.forwardTo act more as expected, like an event filter. This way
Keys.forwardTo becomes usable for composite types that want to enable
the Keys attached property handling by forwarding key events from an
internal editor.
Task-number: QTBUG-37924
Change-Id: I66d1b7245df39678767e79d4bdd46fc15e5c5c3f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickitem2/tst_qquickitem.cpp')
-rw-r--r-- | tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index e6fd98ac35..6778d6a8b6 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -85,6 +85,7 @@ private slots: void standardKeys(); void keysProcessingOrder(); void keysim(); + void keysForward(); void keyNavigation_data(); void keyNavigation(); void keyNavigation_RightToLeft(); @@ -1386,6 +1387,78 @@ void tst_QQuickItem::keysim() delete window; } +void tst_QQuickItem::keysForward() +{ + QQuickView window; + window.setBaseSize(QSize(240,320)); + + window.setSource(testFileUrl("keysforward.qml")); + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + QVERIFY(QGuiApplication::focusWindow() == &window); + + QQuickItem *rootItem = qobject_cast<QQuickItem *>(window.rootObject()); + QVERIFY(rootItem); + QQuickItem *sourceItem = rootItem->property("source").value<QQuickItem *>(); + QVERIFY(sourceItem); + QQuickItem *primaryTarget = rootItem->property("primaryTarget").value<QQuickItem *>(); + QVERIFY(primaryTarget); + QQuickItem *secondaryTarget = rootItem->property("secondaryTarget").value<QQuickItem *>(); + QVERIFY(secondaryTarget); + + // primary target accepts/consumes Key_P + QKeyEvent pressKeyP(QEvent::KeyPress, Qt::Key_P, Qt::NoModifier, "P"); + QCoreApplication::sendEvent(sourceItem, &pressKeyP); + QCOMPARE(rootItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P); + QVERIFY(pressKeyP.isAccepted()); + + QKeyEvent releaseKeyP(QEvent::KeyRelease, Qt::Key_P, Qt::NoModifier, "P"); + QCoreApplication::sendEvent(sourceItem, &releaseKeyP); + QCOMPARE(rootItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P); + QVERIFY(releaseKeyP.isAccepted()); + + // secondary target accepts/consumes Key_S + QKeyEvent pressKeyS(QEvent::KeyPress, Qt::Key_S, Qt::NoModifier, "S"); + QCoreApplication::sendEvent(sourceItem, &pressKeyS); + QCOMPARE(rootItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S); + QVERIFY(pressKeyS.isAccepted()); + + QKeyEvent releaseKeyS(QEvent::KeyRelease, Qt::Key_S, Qt::NoModifier, "S"); + QCoreApplication::sendEvent(sourceItem, &releaseKeyS); + QCOMPARE(rootItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S); + QVERIFY(releaseKeyS.isAccepted()); + + // neither target accepts/consumes Key_Q + QKeyEvent pressKeyQ(QEvent::KeyPress, Qt::Key_Q, Qt::NoModifier, "Q"); + QCoreApplication::sendEvent(sourceItem, &pressKeyQ); + QCOMPARE(rootItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("pressedKeys").toList(), QVariantList() << Qt::Key_Q); + QCOMPARE(primaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_Q); + QCOMPARE(secondaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S << Qt::Key_Q); + QVERIFY(!pressKeyQ.isAccepted()); + + QKeyEvent releaseKeyQ(QEvent::KeyRelease, Qt::Key_Q, Qt::NoModifier, "Q"); + QCoreApplication::sendEvent(sourceItem, &releaseKeyQ); + QCOMPARE(rootItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("releasedKeys").toList(), QVariantList() << Qt::Key_Q); + QCOMPARE(primaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_Q); + QCOMPARE(secondaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S << Qt::Key_Q); + QVERIFY(!releaseKeyQ.isAccepted()); +} + QQuickItemPrivate *childPrivate(QQuickItem *rootItem, const char * itemString) { QQuickItem *item = findItem<QQuickItem>(rootItem, QString(QLatin1String(itemString))); |