summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicsscene.cpp
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andrhans@cisco.com>2012-11-23 21:52:41 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-07 09:11:59 +0100
commit4a9c3b2433d4552bdabb832f71204aca95e68897 (patch)
tree4531a83a1c5ca5e5c70d95a7ece64f269f0834ce /src/widgets/graphicsview/qgraphicsscene.cpp
parent9c02a285529945bf1c3b8fb6d6faf7b382724f72 (diff)
Repair QGraphicsWidget focus chain when used with ItemIsPanel.
Add handling of the focus chain to QGraphicsItem::setFlags(), so that the focus chain is repaired (panels pop out of the chain and non-panels merge back in) when the ItemIsPanel flag is toggled. Add handling focus chain to QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting for panels. Before this fix, you must enable the ItemIsPanel flag before adding the item as a child to a parent panel, and you lose focus when using the tab key to focus around a panel after it has been reparented into another panel. Task-number: QTBUG-28187 Change-Id: I1d0d81a90697eaf715a8a337c8bf6c2159329e68 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsscene.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index ee65fb8fa6..769b488f39 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -607,7 +607,7 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
q->removeItem(item->d_ptr->children.at(i));
}
- if (!item->d_ptr->inDestructor && item == tabFocusFirst) {
+ if (!item->d_ptr->inDestructor && !item->parentItem() && item->isWidget()) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0);
}
@@ -2528,14 +2528,13 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
// No first tab focus widget - make this the first tab focus
// widget.
d->tabFocusFirst = widget;
- } else if (!widget->parentWidget()) {
+ } else if (!widget->parentWidget() && !widget->isPanel()) {
// Adding a widget that is not part of a tab focus chain.
- QGraphicsWidget *last = d->tabFocusFirst->d_func()->focusPrev;
- QGraphicsWidget *lastNew = widget->d_func()->focusPrev;
- last->d_func()->focusNext = widget;
- widget->d_func()->focusPrev = last;
- d->tabFocusFirst->d_func()->focusPrev = lastNew;
- lastNew->d_func()->focusNext = d->tabFocusFirst;
+ QGraphicsWidget *myNewPrev = d->tabFocusFirst->d_func()->focusPrev;
+ myNewPrev->d_func()->focusNext = widget;
+ widget->d_func()->focusPrev->d_func()->focusNext = d->tabFocusFirst;
+ d->tabFocusFirst->d_func()->focusPrev = widget->d_func()->focusPrev;
+ widget->d_func()->focusPrev = myNewPrev;
}
}
@@ -5330,7 +5329,7 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
return true;
}
}
- if (!d->tabFocusFirst) {
+ if (!item && !d->tabFocusFirst) {
// No widgets...
return false;
}
@@ -5342,8 +5341,10 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
} else {
QGraphicsWidget *test = static_cast<QGraphicsWidget *>(item);
widget = next ? test->d_func()->focusNext : test->d_func()->focusPrev;
- if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))
+ if (!widget->panel() && ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))) {
+ // Tab out of the scene.
return false;
+ }
}
QGraphicsWidget *widgetThatHadFocus = widget;