aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitem.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-01-23 13:30:37 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-01 08:37:49 +0100
commit6a8439070ed0582311053d130500facfd3e9d89d (patch)
treea6e0bfe04d2947b15158c66e6c95620e1cb02831 /src/quick/items/qquickitem.cpp
parente7224de627ac89a7c4701f53dc884616891a0199 (diff)
Update item focus when the enabled property is changed.
Remove active focus from an item when it is disabled, and give active focus to an enabled item if it has focus within a scope with active focus. Task-number: QTBUG-22404 Change-Id: Iff2b774a9ff784e6107a4ed6524c93e749ae0182 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r--src/quick/items/qquickitem.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index c9d81c0d11..032427d438 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -1913,7 +1913,7 @@ void QQuickItem::setParentItem(QQuickItem *parentItem)
QQuickItemPrivate::get(d->parentItem)->addChild(this);
d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
- d->setEffectiveEnableRecur(d->calcEffectiveEnable());
+ d->setEffectiveEnableRecur(0, d->calcEffectiveEnable());
if (scopeFocusedItem && d->parentItem && d->canvas) {
// We need to test whether this item becomes scope focused
@@ -3901,7 +3901,11 @@ void QQuickItem::setEnabled(bool e)
d->explicitEnable = e;
- d->setEffectiveEnableRecur(d->calcEffectiveEnable());
+ QQuickItem *scope = parentItem();
+ while (scope && !scope->isFocusScope())
+ scope = scope->parentItem();
+
+ d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
}
bool QQuickItemPrivate::calcEffectiveVisible() const
@@ -3959,12 +3963,10 @@ bool QQuickItemPrivate::calcEffectiveEnable() const
return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
}
-void QQuickItemPrivate::setEffectiveEnableRecur(bool newEffectiveEnable)
+void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope, bool newEffectiveEnable)
{
Q_Q(QQuickItem);
- // XXX todo - need to fixup focus
-
if (newEffectiveEnable && !explicitEnable) {
// This item locally overrides enable
return;
@@ -3981,10 +3983,21 @@ void QQuickItemPrivate::setEffectiveEnableRecur(bool newEffectiveEnable)
QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(canvas);
if (canvasPriv->mouseGrabberItem == q)
q->ungrabMouse();
+ if (scope && !effectiveEnable && activeFocus) {
+ canvasPriv->clearFocusInScope(
+ scope, q, QQuickCanvasPrivate::DontChangeFocusProperty | QQuickCanvasPrivate::DontChangeSubFocusItem);
+ }
}
- for (int ii = 0; ii < childItems.count(); ++ii)
- QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(newEffectiveEnable);
+ for (int ii = 0; ii < childItems.count(); ++ii) {
+ QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
+ flags & QQuickItem::ItemIsFocusScope ? q : scope, newEffectiveEnable);
+ }
+
+ if (canvas && scope && effectiveEnable && focus) {
+ QQuickCanvasPrivate::get(canvas)->setFocusInScope(
+ scope, q, QQuickCanvasPrivate::DontChangeFocusProperty | QQuickCanvasPrivate::DontChangeSubFocusItem);
+ }
emit q->enabledChanged();
}