From d6f2d8dcb6dbee89fc55bd439ab4a837f4f9fb4c Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Sat, 24 Nov 2012 21:50:05 +0100 Subject: Make sure panels always gain focus when activated or tab is pressed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This changes behavior, but I would argue it's a good change. If you create a panel and activate it (e.g., by simply showing it or reparenting it onto an already-visible item), you expect the panel to gain focus / which is sort of the whole point of activating it. Prior to this change, you had to have explicitly called setFocus() on one of the panel's children, which would give that item subfocus, for that item to auto- gain focus when the panel was activated. This change makes it more automatic. If the panel itself or any of the widgets in its focus chain can gain focus, they will gain focus when the panel is activated. So the new logic is - if the panel already has a focus item, so if someone explicitly set subfocus on an item before the panel is shown, that item gets focus. Otherwise, if the panel itself can gain focus (e.g., someone makes a line edit / text edit panel), it gains focus when activated. Otherwise, we search the focus chain until we find the first item that can gain focus. This last case is the file dialog case, where the dialog itself can't gain focus but typically the first item in the focus chain is the primary focus widget, such as the search field or the directory list view. The change also fixes this for the first Tab. If you clear focus on a panel, the user expects to be able to press Tab to regain focus. Prior to this change that didn't happen. Now, the panel or the first in the focus chain that can get focus gets focus on first tab. Task-number: QTBUG-28194 Change-Id: Id7ec1741d0d5eb4ea845469909c8d684e14017f1 Reviewed-by: Jan Arve Sæther --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 9a996cd0c6..d5a40d0743 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -10238,23 +10238,24 @@ void tst_QGraphicsItem::modality_clickFocus() EventSpy2 rect1Spy(&scene, rect1); EventSpy2 rect2Spy(&scene, rect2); - // activate rect1, it should not get focus + // activate rect1, it should get focus rect1->setActive(true); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); + QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); - // focus stays unset when rect2 becomes modal + // focus stays when rect2 becomes modal rect2->setPanelModality(QGraphicsItem::SceneModal); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); + QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); // clicking on rect1 should not set it's focus item + rect1->clearFocus(); sendMouseClick(&scene, QPointF(-25, -25)); QCOMPARE(rect1->focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); @@ -10262,33 +10263,34 @@ void tst_QGraphicsItem::modality_clickFocus() rect2->setActive(true); sendMouseClick(&scene, QPointF(75, 75)); QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); // clicking on rect1 does *not* give it focus rect1->setActive(true); + rect1->clearFocus(); sendMouseClick(&scene, QPointF(-25, -25)); QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 2); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); // focus doesn't change when leaving modality either rect2->setPanelModality(QGraphicsItem::NonModal); QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 2); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); // click on rect1, it should get focus now sendMouseClick(&scene, QPointF(-25, -25)); QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 3); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); } -- cgit v1.2.3 From 533105cadfde6d0113ea25481b9723e2b06de8e4 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 11 Dec 2012 21:04:12 +0100 Subject: Deactivating an inactive panel no longer causes unwanted deactivation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QGraphicsItem::setActive() is by design not guarded against calls that do not change the current activation state of the item (e.g., calling setActive(true) on an active item or calling setActive(false) on an inactive item). This is to ensure that it's possible to set explicit activation state on items, either before they are added to a scene, or while the scene itself is inactive. Before this fix, calling setActive(false) on a panel item that is not currently active would by accident clear activation from any other panel that might have focus. After this fix, activation is only cleared if the item setActive() was called on itself is the active panel, or is the panel that will regain activation once the scene is reactivated. Task-number: QTBUG-28544 Change-Id: Ic4752f1e4400f9a0660bc968834747610212bb52 Reviewed-by: Bjørn Erik Nilsen Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Yoann Lopes --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index d5a40d0743..cd246ac25d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -428,6 +428,7 @@ private slots: void activate(); void setActivePanelOnInactiveScene(); void activationOnShowHide(); + void deactivateInactivePanel(); void moveWhileDeleting(); void ensureDirtySceneTransform(); void focusScope(); @@ -9030,6 +9031,40 @@ public: } }; +void tst_QGraphicsItem::deactivateInactivePanel() +{ + QGraphicsScene scene; + QGraphicsItem *panel1 = scene.addRect(QRectF(0, 0, 10, 10)); + panel1->setFlag(QGraphicsItem::ItemIsPanel); + + QGraphicsItem *panel2 = scene.addRect(QRectF(0, 0, 10, 10)); + panel2->setFlag(QGraphicsItem::ItemIsPanel); + + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + panel1->setActive(true); + QVERIFY(scene.isActive()); + QVERIFY(panel1->isActive()); + QVERIFY(!panel2->isActive()); + QCOMPARE(scene.activePanel(), panel1); + + panel2->setActive(true); + QVERIFY(panel2->isActive()); + QVERIFY(!panel1->isActive()); + QCOMPARE(scene.activePanel(), panel2); + + panel2->setActive(false); + QVERIFY(panel1->isActive()); + QVERIFY(!panel2->isActive()); + QCOMPARE(scene.activePanel(), panel1); + + panel2->setActive(false); + QVERIFY(panel1->isActive()); + QVERIFY(!panel2->isActive()); + QCOMPARE(scene.activePanel(), panel1); +} + void tst_QGraphicsItem::moveWhileDeleting() { QGraphicsScene scene; -- cgit v1.2.3 From ccbff3fce504bd2ee99fe22f6e275c7033a3f9f7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 7 Jan 2013 11:39:45 +0100 Subject: Clean up some metatype declarations and registrations Change-Id: I0826f6502cc45279f29f248f5f28f4fc9e6c8b4e Reviewed-by: David Faure --- tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 37543a33a0..0d48789a7a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -2204,7 +2204,6 @@ void tst_QGraphicsItem::sceneMatrix() void tst_QGraphicsItem::setMatrix() { QGraphicsScene scene; - qRegisterMetaType >("QList"); QSignalSpy spy(&scene, SIGNAL(changed(QList))); QRectF unrotatedRect(-12, -34, 56, 78); QGraphicsRectItem item(unrotatedRect, 0); -- cgit v1.2.3