summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-11 07:30:53 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-15 09:31:02 (GMT)
commita06c7db92ff13a1f8a353851a586ae12755e7c6c (patch)
tree775c7364e2591045304bfd737f0dd93b88a2bf9a /tests
parent9b579d7821205250b8d64b06a19d5e4fccd56f31 (diff)
downloadQt-a06c7db92ff13a1f8a353851a586ae12755e7c6c.zip
Qt-a06c7db92ff13a1f8a353851a586ae12755e7c6c.tar.gz
Qt-a06c7db92ff13a1f8a353851a586ae12755e7c6c.tar.bz2
Fix bugs in handling of initial focus.
Make sure you can't set focus on an inactive scene, allow items with subfocus to gain focus even if added to a scene that's not active, and finally ensure that activating a panel in an active, but unfocused scene, gives focus to the scene. Also added a test that checks adding normal vs. panel items to an active vs. inactive scene, and what happens if you initially say the item should have focus. Reviewed-by: TrustMe
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index 6998684..07d7cce 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -264,6 +264,8 @@ private slots:
void inputMethod_data();
void inputMethod();
void dispatchHoverOnPress();
+ void initialFocus_data();
+ void initialFocus();
// task specific tests below me
void task139710_bspTreeCrash();
@@ -3822,5 +3824,61 @@ void tst_QGraphicsScene::dispatchHoverOnPress()
}
}
+void tst_QGraphicsScene::initialFocus_data()
+{
+ QTest::addColumn<bool>("activeScene");
+ QTest::addColumn<bool>("explicitSetFocus");
+ QTest::addColumn<bool>("isPanel");
+ QTest::addColumn<bool>("shouldHaveFocus");
+
+ QTest::newRow("inactive scene, normal item") << false << false << false << false;
+ QTest::newRow("inactive scene, panel item") << false << false << true << false;
+ QTest::newRow("inactive scene, normal item, explicit focus") << false << true << false << true;
+ QTest::newRow("inactive scene, panel, explicit focus") << false << true << true << true;
+ QTest::newRow("active scene, normal item") << true << false << false << false;
+ QTest::newRow("active scene, panel item") << true << false << true << false;
+ QTest::newRow("active scene, normal item, explicit focus") << true << true << false << true;
+ QTest::newRow("active scene, panel, explicit focus") << true << true << true << true;
+}
+
+void tst_QGraphicsScene::initialFocus()
+{
+ QFETCH(bool, activeScene);
+ QFETCH(bool, explicitSetFocus);
+ QFETCH(bool, isPanel);
+ QFETCH(bool, shouldHaveFocus);
+
+ QGraphicsRectItem *rect = new QGraphicsRectItem;
+ rect->setFlag(QGraphicsItem::ItemIsFocusable);
+ QVERIFY(!rect->hasFocus());
+
+ if (isPanel)
+ rect->setFlag(QGraphicsItem::ItemIsPanel);
+
+ // Setting focus on an item before adding to the scene will ensure
+ // it gets focus when the scene is activated.
+ if (explicitSetFocus)
+ rect->setFocus();
+
+ QGraphicsScene scene;
+ QVERIFY(!scene.isActive());
+
+ if (activeScene) {
+ QEvent windowActivate(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &windowActivate);
+ scene.setFocus();
+ }
+
+ scene.addItem(rect);
+
+ if (!activeScene) {
+ QEvent windowActivate(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &windowActivate);
+ scene.setFocus();
+ }
+
+ QCOMPARE(rect->hasFocus(), shouldHaveFocus);
+}
+
QTEST_MAIN(tst_QGraphicsScene)
#include "tst_qgraphicsscene.moc"