summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-09 08:01:10 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-09 15:18:07 (GMT)
commit948038f077ea413ab7aa7634d1c9987ec7ab50f6 (patch)
tree4f1142819abe81fedad25e276b28900f1b16c157 /src/gui
parentc44402453593cbdf2eafa66f6ee23d17aacf44fd (diff)
downloadQt-948038f077ea413ab7aa7634d1c9987ec7ab50f6.zip
Qt-948038f077ea413ab7aa7634d1c9987ec7ab50f6.tar.gz
Qt-948038f077ea413ab7aa7634d1c9987ec7ab50f6.tar.bz2
Only active QGraphicsScenes can have active input focus.
This change ensures that only active scenes can have active input focus items. If you try to set input focus on items that are in an inactive scene, these items will gain input focus only when the scene is activated. For scenes attached to a view, this change should only fix the bug that you could have a blinking line edit in a scene when the view is inactive, meaning you couldn't type into the line edit. For scenes that have no view, you now must activate the scene in order to give the items active input focus. This will affect those who use QGraphicsScene with custom key and focus handling. Reviewed-by: brad
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp19
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp11
2 files changed, 21 insertions, 9 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 86c60be..e553517 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1026,8 +1026,12 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent)
dirtySceneTransform = 1;
// Restore the sub focus chain.
- if (lastSubFocusItem)
- lastSubFocusItem->d_ptr->setSubFocus();
+ if (lastSubFocusItem) {
+ if (parent && parent->isActive())
+ lastSubFocusItem->setFocus();
+ else
+ lastSubFocusItem->d_ptr->setSubFocus();
+ }
// Deliver post-change notification
q->itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant);
@@ -2746,7 +2750,7 @@ void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
// Update the scene's focus item.
if (d_ptr->scene) {
QGraphicsItem *p = panel();
- if (!p || p->isActive()) {
+ if ((!p && d_ptr->scene->isActive()) || p->isActive()) {
// Visible items immediately gain focus from scene.
d_ptr->scene->d_func()->setFocusItemHelper(f, focusReason);
}
@@ -4850,13 +4854,16 @@ void QGraphicsItemPrivate::ensureSceneTransform()
*/
void QGraphicsItemPrivate::setSubFocus()
{
- // Update focus child chain.
+ // Update focus child chain. Stop at panels, or if this item
+ // is hidden, stop at the first item with a visible parent.
QGraphicsItem *item = q_ptr;
QGraphicsItem *parent = item;
- bool hidden = !visible;
do {
parent->d_func()->subFocusItem = item;
- } while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (!hidden || !parent->d_func()->visible));
+ } while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (visible || !parent->d_ptr->visible));
+
+ if (!parent && scene && !scene->isActive())
+ scene->d_func()->lastFocusItem = q_ptr;
}
/*!
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index b09c5f4..43f2932 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -665,9 +665,14 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
QInputMethodEvent imEvent;
sendEvent(lastFocusItem, &imEvent);
- // Close any external input method panel
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->inputContext()->reset();
+ // Close any external input method panel. This happens
+ // automatically by removing WA_InputMethodEnabled on
+ // the views, but if we are changing focus, we have to
+ // do it ourselves.
+ if (item) {
+ for (int i = 0; i < views.size(); ++i)
+ views.at(i)->inputContext()->reset();
+ }
}
}