summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2010-04-21 05:34:51 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2010-04-21 05:40:39 (GMT)
commit62d40d166f77de67072eced7eac4f3c38697af52 (patch)
tree2e942083882358c4c9365b155881fdcf4bbca046 /tests/auto/declarative
parent5beddba73a7b2890f775d45aeb2f21407f8c3d0d (diff)
downloadQt-62d40d166f77de67072eced7eac4f3c38697af52.zip
Qt-62d40d166f77de67072eced7eac4f3c38697af52.tar.gz
Qt-62d40d166f77de67072eced7eac4f3c38697af52.tar.bz2
Add forceFocus method to QDeclarativeItem.
Reviewed-by: Aaron Kennedy
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml81
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/test.qml2
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/test4.qml2
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/test5.qml2
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp57
5 files changed, 141 insertions, 3 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..adde522
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml
@@ -0,0 +1,81 @@
+import Qt 4.6
+
+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..f060bdc 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml
@@ -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/test4.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml
index d8bd390..e41c6b8 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/test4.qml
@@ -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..838e557 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml
@@ -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"