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
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
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;
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();
}
void visible();
void enabled();
+ void enabledFocus();
void mouseGrab();
void touchEventAccept();
delete child2;
}
+void tst_qquickitem::enabledFocus()
+{
+ QQuickCanvas canvas;
+ ensureFocus(&canvas);
+
+ QQuickFocusScope root;
+
+ root.setFocus(true);
+ root.setEnabled(false);
+
+ QCOMPARE(root.isEnabled(), false);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), false);
+
+ root.setParentItem(canvas.rootItem());
+
+ QCOMPARE(root.isEnabled(), false);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+
+ root.setEnabled(true);
+ QCOMPARE(root.isEnabled(), true);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), true);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+
+ QQuickItem child1;
+ child1.setParentItem(&root);
+
+ QCOMPARE(child1.isEnabled(), true);
+ QCOMPARE(child1.hasFocus(), false);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+
+ QQuickItem child2;
+ child2.setFocus(true);
+ child2.setParentItem(&root);
+
+ QCOMPARE(root.isEnabled(), true);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), true);
+ QCOMPARE(child2.isEnabled(), true);
+ QCOMPARE(child2.hasFocus(), true);
+ QCOMPARE(child2.hasActiveFocus(), true);
+ QCOMPARE(canvas.activeFocusItem(), &child2);
+
+ child2.setEnabled(false);
+
+ QCOMPARE(root.isEnabled(), true);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), true);
+ QCOMPARE(child1.isEnabled(), true);
+ QCOMPARE(child1.hasFocus(), false);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(child2.isEnabled(), false);
+ QCOMPARE(child2.hasFocus(), true);
+ QCOMPARE(child2.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+
+ child1.setEnabled(false);
+ QCOMPARE(child1.isEnabled(), false);
+ QCOMPARE(child1.hasFocus(), false);
+ QCOMPARE(child1.hasActiveFocus(), false);
+
+ child1.setFocus(true);
+ QCOMPARE(child1.isEnabled(), false);
+ QCOMPARE(child1.hasFocus(), true);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(child2.isEnabled(), false);
+ QCOMPARE(child2.hasFocus(), false);
+ QCOMPARE(child2.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+
+ child1.setEnabled(true);
+ QCOMPARE(child1.isEnabled(), true);
+ QCOMPARE(child1.hasFocus(), true);
+ QCOMPARE(child1.hasActiveFocus(), true);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&child1));
+
+ root.setFocus(false);
+ QCOMPARE(root.isEnabled(), true);
+ QCOMPARE(root.hasFocus(), false);
+ QCOMPARE(root.hasActiveFocus(), false);
+ QCOMPARE(child1.isEnabled(), true);
+ QCOMPARE(child1.hasFocus(), true);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+
+ child2.forceActiveFocus();
+ QCOMPARE(root.isEnabled(), true);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), true);
+ QCOMPARE(child1.isEnabled(), true);
+ QCOMPARE(child1.hasFocus(), false);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(child2.isEnabled(), false);
+ QCOMPARE(child2.hasFocus(), true);
+ QCOMPARE(child2.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+
+ root.setEnabled(false);
+ QCOMPARE(root.isEnabled(), false);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), false);
+ QCOMPARE(child1.isEnabled(), false);
+ QCOMPARE(child1.hasFocus(), false);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(child2.isEnabled(), false);
+ QCOMPARE(child2.hasFocus(), true);
+ QCOMPARE(child2.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+
+ child1.forceActiveFocus();
+ QCOMPARE(root.isEnabled(), false);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), false);
+ QCOMPARE(child1.isEnabled(), false);
+ QCOMPARE(child1.hasFocus(), true);
+ QCOMPARE(child1.hasActiveFocus(), false);
+ QCOMPARE(child2.isEnabled(), false);
+ QCOMPARE(child2.hasFocus(), false);
+ QCOMPARE(child2.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+
+ root.setEnabled(true);
+ QCOMPARE(root.isEnabled(), true);
+ QCOMPARE(root.hasFocus(), true);
+ QCOMPARE(root.hasActiveFocus(), true);
+ QCOMPARE(child1.isEnabled(), true);
+ QCOMPARE(child1.hasFocus(), true);
+ QCOMPARE(child1.hasActiveFocus(), true);
+ QCOMPARE(child2.isEnabled(), false);
+ QCOMPARE(child2.hasFocus(), false);
+ QCOMPARE(child2.hasActiveFocus(), false);
+ QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&child1));
+}
+
void tst_qquickitem::mouseGrab()
{
QQuickCanvas *canvas = new QQuickCanvas;