diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativefocusscope')
7 files changed, 146 insertions, 8 deletions
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml new file mode 100644 index 0000000..5904fd6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml @@ -0,0 +1,81 @@ +import Qt 4.7 + +Rectangle { + width: 800; height: 600 + + FocusScope { + focus: true + + FocusScope { + id: firstScope + focus: true + + Rectangle { + objectName: "item0" + height: 120; width: 420 + + color: "transparent" + border.width: 5; border.color: firstScope.wantsFocus?"blue":"black" + + Rectangle { + id: item1; objectName: "item1" + x: 10; y: 10; width: 100; height: 100; color: "green" + border.width: 5; border.color: wantsFocus?"blue":"black" + focus: true + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + + Rectangle { + id: item2; objectName: "item2" + x: 310; y: 10; width: 100; height: 100; color: "green" + border.width: 5; border.color: wantsFocus?"blue":"black" + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + } + } + + FocusScope { + id: secondScope + + Rectangle { + objectName: "item3" + y: 160; height: 120; width: 420 + + color: "transparent" + border.width: 5; border.color: secondScope.wantsFocus?"blue":"black" + + Rectangle { + id: item4; objectName: "item4" + x: 10; y: 10; width: 100; height: 100; color: "green" + border.width: 5; border.color: wantsFocus?"blue":"black" + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + + Rectangle { + id: item5; objectName: "item5" + x: 310; y: 10; width: 100; height: 100; color: "green" + border.width: 5; border.color: wantsFocus?"blue":"black" + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + } + } + } + Keys.onDigit4Pressed: item4.focus = true + Keys.onDigit5Pressed: item5.forceFocus() +} diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml index 647e5bf..6b09c29 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import Qt 4.7 Rectangle { color: "white" @@ -20,7 +20,7 @@ Rectangle { color: "transparent" border.width: 5 - //border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.wantsFocus?"blue":"black" Rectangle { id: item1; objectName: "item1" diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml index 277fda4..216277e 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test2.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import Qt 4.7 Rectangle { color: "white" diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml index 9344d07..2ac0d18 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test3.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import Qt 4.7 Rectangle { color: "white" diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml index d8bd390..8862b39 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import Qt 4.7 Rectangle { color: "white" @@ -19,7 +19,7 @@ Rectangle { color: "transparent" border.width: 5 - //border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.wantsFocus?"blue":"black" Rectangle { id: item1; objectName: "item1" diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml index da452cf..d67ec57 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import Qt 4.7 Rectangle { color: "white" @@ -20,7 +20,7 @@ Rectangle { color: "transparent" border.width: 5 - //border.color: myScope.wantsFocus?"blue":"black" + border.color: myScope.wantsFocus?"blue":"black" Rectangle { x: 10; y: 10 diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp index 1bd8331..04bb1c5 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp +++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp @@ -63,6 +63,7 @@ private slots: void nested(); void noFocus(); void textEdit(); + void forceFocus(); }; /* @@ -273,6 +274,62 @@ void tst_qdeclarativefocusscope::textEdit() delete view; } +void tst_qdeclarativefocusscope::forceFocus() +{ + QDeclarativeView *view = new QDeclarativeView; + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/forcefocus.qml")); + + QDeclarativeRectangle *item0 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item0")); + QDeclarativeRectangle *item1 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item1")); + QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2")); + QDeclarativeRectangle *item3 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item3")); + QDeclarativeRectangle *item4 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item4")); + QDeclarativeRectangle *item5 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item5")); + QVERIFY(item0 != 0); + QVERIFY(item1 != 0); + QVERIFY(item2 != 0); + QVERIFY(item3 != 0); + QVERIFY(item4 != 0); + QVERIFY(item5 != 0); + + view->show(); + qApp->setActiveWindow(view); + qApp->processEvents(); + +#ifdef Q_WS_X11 + // to be safe and avoid failing setFocus with window managers + qt_x11_wait_for_window_manager(view); +#endif + + QVERIFY(view->hasFocus()); + QVERIFY(view->scene()->hasFocus()); + QVERIFY(item0->wantsFocus() == true); + QVERIFY(item1->hasFocus() == true); + QVERIFY(item2->hasFocus() == false); + QVERIFY(item3->wantsFocus() == false); + QVERIFY(item4->hasFocus() == false); + QVERIFY(item5->hasFocus() == false); + + QTest::keyClick(view, Qt::Key_4); + QVERIFY(item0->wantsFocus() == true); + QVERIFY(item1->hasFocus() == true); + QVERIFY(item2->hasFocus() == false); + QVERIFY(item3->wantsFocus() == false); + QVERIFY(item4->hasFocus() == false); + QVERIFY(item5->hasFocus() == false); + + QTest::keyClick(view, Qt::Key_5); + QVERIFY(item0->wantsFocus() == false); + QVERIFY(item1->hasFocus() == false); + QVERIFY(item2->hasFocus() == false); + QVERIFY(item3->wantsFocus() == true); + QVERIFY(item4->hasFocus() == false); + QVERIFY(item5->hasFocus() == true); + + delete view; +} + + QTEST_MAIN(tst_qdeclarativefocusscope) #include "tst_qdeclarativefocusscope.moc" |