diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-06-07 12:29:07 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-08 06:17:54 +0200 |
commit | 04b4445eadb09873821f165074c72c6f477e18d2 (patch) | |
tree | 9910c1aae2d5af7b6897fc4780e01be513719533 /src/quick/items/qquickitem.cpp | |
parent | 762b4d90110465aeceb96f44cd06dcda229dfe89 (diff) |
Fix handling of a direct child stealing focus from a parent-less item.
When an item gains focus it will remove focus from the previous item
that held focus. Normally this is the sub-focus item of an ancestor
item, however if the item with focus is at the root of the tree there
will be no sub-focus item and the focus of root item needs to be cleared
instead. Likewise if an item doesn't have a parent, focus still needs
to be removed from any sub focus item.
Change-Id: I0f192692e21e288c87ba0104f3d597363190f87c
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index ae912a2354..5eb824cdc3 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -4953,6 +4953,9 @@ void QQuickItem::setFocus(bool focus) QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope, false); QQuickItemPrivate::get(oldSubFocusItem)->focus = false; changed << oldSubFocusItem; + } else if (!scope->isFocusScope() && scope->hasFocus()) { + QQuickItemPrivate::get(scope)->focus = false; + changed << scope; } d->updateSubFocusItem(scope, focus); @@ -4963,8 +4966,19 @@ void QQuickItem::setFocus(bool focus) QQuickCanvasPrivate::notifyFocusChangesRecur(changed.data(), changed.count() - 1); } } else { + QVarLengthArray<QQuickItem *, 20> changed; + QQuickItem *oldSubFocusItem = d->subFocusItem; + if (!isFocusScope() && oldSubFocusItem) { + QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(this, false); + QQuickItemPrivate::get(oldSubFocusItem)->focus = false; + changed << oldSubFocusItem; + } + d->focus = focus; + changed << this; emit focusChanged(focus); + + QQuickCanvasPrivate::notifyFocusChangesRecur(changed.data(), changed.count() - 1); } } |