aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickitem2
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-10-01 21:09:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-01 12:25:04 +0100
commita7415035ed375d31e0e6d503ea8af43bf98d3fb7 (patch)
treed4dbc5212a855805c0967fca77aa06d4d515fedf /tests/auto/quick/qquickitem2
parent5b05a78d0055757adb3b2703ea990e07dbcd145a (diff)
KeyNavigation should use forceActiveFocus
It would only set focus which works fine as long as the target is in the same FocusScope. But as user one would expect that the target actually receives the focus. Using forceActiveFocus is sensible since the current item needs to have the "activeFocus" anyway and within the same focus scope setting focus=true on another item will take away the active focus. Task-number: QTBUG-34209 Change-Id: I824f15fd0d4d42eb2f0c6c1b02660f2e007b3362 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com> Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'tests/auto/quick/qquickitem2')
-rw-r--r--tests/auto/quick/qquickitem2/data/keynavigationtest_focusscope.qml93
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp12
2 files changed, 104 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickitem2/data/keynavigationtest_focusscope.qml b/tests/auto/quick/qquickitem2/data/keynavigationtest_focusscope.qml
new file mode 100644
index 0000000000..985086ff49
--- /dev/null
+++ b/tests/auto/quick/qquickitem2/data/keynavigationtest_focusscope.qml
@@ -0,0 +1,93 @@
+import QtQuick 2.0
+
+Grid {
+ columns: 2
+ width: 100; height: 100
+ function verify() {
+ if (item1.KeyNavigation.right != item2)
+ return false;
+ if (item1.KeyNavigation.down != item3)
+ return false;
+ if (item1.KeyNavigation.tab != item2)
+ return false;
+ if (item1.KeyNavigation.backtab != item4)
+ return false;
+
+ if (item2.KeyNavigation.left != item1)
+ return false;
+ if (item2.KeyNavigation.down != item4)
+ return false;
+ if (item2.KeyNavigation.tab != item3)
+ return false;
+ if (item2.KeyNavigation.backtab != item1)
+ return false;
+
+ if (item3.KeyNavigation.right != item4)
+ return false;
+ if (item3.KeyNavigation.up != item1)
+ return false;
+ if (item3.KeyNavigation.tab != item4)
+ return false;
+ if (item3.KeyNavigation.backtab != item2)
+ return false;
+
+ if (item4.KeyNavigation.left != item3)
+ return false;
+ if (item4.KeyNavigation.up != item2)
+ return false;
+ if (item4.KeyNavigation.tab != item1)
+ return false;
+ if (item4.KeyNavigation.backtab != item3)
+ return false;
+
+ return true;
+ }
+
+ Rectangle {
+ id: item1
+ objectName: "item1"
+ focus: true
+ width: 50; height: 50
+ color: focus ? "red" : "lightgray"
+ KeyNavigation.right: item2
+ KeyNavigation.down: item3
+ KeyNavigation.tab: item2
+ KeyNavigation.backtab: item4
+ }
+ FocusScope {
+ Rectangle {
+ id: item2
+ objectName: "item2"
+ width: 50; height: 50
+ color: focus ? "red" : "lightgray"
+ KeyNavigation.left: item1
+ KeyNavigation.down: item4
+ KeyNavigation.tab: item3
+ KeyNavigation.backtab: item1
+ }
+ }
+ FocusScope {
+ Rectangle {
+ id: item3
+ objectName: "item3"
+ width: 50; height: 50
+ color: focus ? "red" : "lightgray"
+ KeyNavigation.right: item4
+ KeyNavigation.up: item1
+ KeyNavigation.tab: item4
+ KeyNavigation.backtab: item2
+ }
+ FocusScope {
+ Rectangle {
+ id: item4
+ objectName: "item4"
+ width: 50; height: 50
+ color: focus ? "red" : "lightgray"
+ KeyNavigation.left: item3
+ KeyNavigation.up: item2
+ KeyNavigation.tab: item1
+ KeyNavigation.backtab: item3
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index c451ea5e0a..8a4ed5ae4c 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -83,6 +83,7 @@ private slots:
void standardKeys();
void keysProcessingOrder();
void keysim();
+ void keyNavigation_data();
void keyNavigation();
void keyNavigation_RightToLeft();
void keyNavigation_skipNotVisible();
@@ -1408,12 +1409,21 @@ void tst_QQuickItem::layoutMirroringIllegalParent()
QVERIFY(object != 0);
}
+void tst_QQuickItem::keyNavigation_data()
+{
+ QTest::addColumn<QString>("source");
+ QTest::newRow("KeyNavigation") << QStringLiteral("keynavigationtest.qml");
+ QTest::newRow("KeyNavigation_FocusScope") << QStringLiteral("keynavigationtest_focusscope.qml");
+}
+
void tst_QQuickItem::keyNavigation()
{
+ QFETCH(QString, source);
+
QQuickView *window = new QQuickView(0);
window->setBaseSize(QSize(240,320));
- window->setSource(testFileUrl("keynavigationtest.qml"));
+ window->setSource(testFileUrl(source));
window->show();
window->requestActivate();
QVERIFY(QTest::qWaitForWindowActive(window));