summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-15 13:12:52 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-15 13:20:57 (GMT)
commit4c779ca7cd74b77ec5f7e480b9762acccce3c4ad (patch)
treece10bb255720e58d8cfd762ddc3e5baea99e9a26
parentfd8be39b40467be69a7cd9c5a009c5a47c6a4e9b (diff)
downloadQt-4c779ca7cd74b77ec5f7e480b9762acccce3c4ad.zip
Qt-4c779ca7cd74b77ec5f7e480b9762acccce3c4ad.tar.gz
Qt-4c779ca7cd74b77ec5f7e480b9762acccce3c4ad.tar.bz2
Fix a bug in FocusScopes; ensure subFocus is set correctly.
The bug was triggered by setting focus on a parent scope (which then passes focus to the innermost scope). Subfocus was set up for the first scope, but not the inner scopes. Reviewed-by: TrustMe
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp4
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp16
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 838bd34..81eeb39 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -2830,6 +2830,8 @@ void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool clim
if (climb) {
while (f->d_ptr->focusScopeItem && f->d_ptr->focusScopeItem->isVisible())
f = f->d_ptr->focusScopeItem;
+ if (f != q_ptr)
+ f->d_ptr->setSubFocus();
}
// Update the scene's focus item.
@@ -4979,7 +4981,7 @@ void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem)
if (parent->d_ptr->subFocusItem != q_ptr)
break;
parent->d_ptr->subFocusItem = 0;
- subFocusItemChange();
+ parent->d_ptr->subFocusItemChange();
} while (!parent->isPanel() && (parent = parent->d_ptr->parent));
}
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 0744fa5..304330e 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -8332,6 +8332,22 @@ void tst_QGraphicsItem::focusScope()
rect4->setParentItem(0);
QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)0);
QVERIFY(!scope3->hasFocus());
+
+ QGraphicsRectItem *rectA = new QGraphicsRectItem;
+ QGraphicsRectItem *scopeA = new QGraphicsRectItem(rectA);
+ scopeA->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
+ scopeA->setFocus();
+ QGraphicsRectItem *scopeB = new QGraphicsRectItem(scopeA);
+ scopeB->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
+ scopeB->setFocus();
+
+ scene.addItem(rectA);
+ QVERIFY(rect5->hasFocus());
+ QVERIFY(!scopeB->hasFocus());
+
+ scopeA->setFocus();
+ QVERIFY(scopeB->hasFocus());
+ QCOMPARE(scopeB->focusItem(), (QGraphicsItem *)scopeB);
}
QTEST_MAIN(tst_QGraphicsItem)