diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-08-31 14:03:34 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-08-31 14:14:48 (GMT) |
commit | 46624cfb90986e1977a539d279516bd5ade3675f (patch) | |
tree | 2454b0c367d126940e6b4d1020d4b9816a50e44d /tests/auto/qgraphicsitem | |
parent | 62ca28a96d200fe55ed5bc2d0d1df327ab44c97e (diff) | |
download | Qt-46624cfb90986e1977a539d279516bd5ade3675f.zip Qt-46624cfb90986e1977a539d279516bd5ade3675f.tar.gz Qt-46624cfb90986e1977a539d279516bd5ade3675f.tar.bz2 |
Add auto-activation on show/hide and setParentItem().
If you show a child panel of an active panel, the child will now be
activated and the parent deactivated. Hiding the child panel will
reactive the parent. If the parent is 0, no other panel is activated.
Reparenting a panel onto an active panel will also activate the (new)
child. Reparenting away does not affect activation in any way.
This change also fixes QGraphicsWidget::isActiveWindow(), which returned
true for all toplevel widgets (not in a panel/window). This is wrong;
either the non-panel items are active, or a panel is active. The
correct behavior is the same as calling QGraphicsItem::isActive(). Fixed
the autotests (which wrongly tested that both a panel and a non-panel
item were active at the same time).
This change causes popups (QGraphics{Proxy,}Widget) to deactivate the
parent widget. On the positive side this activates the popup, and ensures
that the parent regains proper focus when the popup is closed. However
it also means the parent widget is inactive while the popup is open,
which (e.g.) causes editable combobox line edit cursors to stop blinking.
This is to be fixed soon, but the fix is a bit big so we'll do that later.
Autotests included.
Reviewed-by: Brad
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 517380e..2acb76d 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -291,6 +291,7 @@ private slots: void addPanelToActiveScene(); void activate(); void setActivePanelOnInactiveScene(); + void activationOnShowHide(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -8038,5 +8039,68 @@ void tst_QGraphicsItem::setActivePanelOnInactiveScene() QCOMPARE(sceneActivationChangeSpy.count(), 0); } +void tst_QGraphicsItem::activationOnShowHide() +{ + QGraphicsScene scene; + QEvent activate(QEvent::WindowActivate); + QApplication::sendEvent(&scene, &activate); + + QGraphicsRectItem *rootPanel = scene.addRect(QRectF()); + rootPanel->setFlag(QGraphicsItem::ItemIsPanel); + rootPanel->setActive(true); + + QGraphicsRectItem *subPanel = new QGraphicsRectItem; + subPanel->setFlag(QGraphicsItem::ItemIsPanel); + + // Reparenting onto an active panel auto-activates the child panel. + subPanel->setParentItem(rootPanel); + QVERIFY(subPanel->isActive()); + QVERIFY(!rootPanel->isActive()); + + // Hiding an active child panel will reactivate the parent panel. + subPanel->hide(); + QVERIFY(rootPanel->isActive()); + + // Showing a child panel will auto-activate it. + subPanel->show(); + QVERIFY(subPanel->isActive()); + QVERIFY(!rootPanel->isActive()); + + // Adding an unrelated panel doesn't affect activation. + QGraphicsRectItem *otherPanel = new QGraphicsRectItem; + otherPanel->setFlag(QGraphicsItem::ItemIsPanel); + scene.addItem(otherPanel); + QVERIFY(subPanel->isActive()); + + // Showing an unrelated panel doesn't affect activation. + otherPanel->hide(); + otherPanel->show(); + QVERIFY(subPanel->isActive()); + + // Add a non-panel item. + QGraphicsRectItem *otherItem = new QGraphicsRectItem; + scene.addItem(otherItem); + otherItem->setActive(true); + QVERIFY(otherItem->isActive()); + + // Reparent a panel onto an active non-panel item. + subPanel->setParentItem(otherItem); + QVERIFY(subPanel->isActive()); + + // Showing a child panel of a non-panel item will activate it. + subPanel->hide(); + QVERIFY(!subPanel->isActive()); + QVERIFY(otherItem->isActive()); + subPanel->show(); + QVERIFY(subPanel->isActive()); + + // Hiding a toplevel active panel will pass activation back + // to the non-panel items. + rootPanel->setActive(true); + rootPanel->hide(); + QVERIFY(!rootPanel->isActive()); + QVERIFY(otherItem->isActive()); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" |