Commit d59f8683 authored by Bea Lam's avatar Bea Lam Committed by Qt by Nokia

Pull out some duplicate focus-related code

Change-Id: I920a9b75ccbdb3a9b169c7669121734c14d18ff9
Reviewed-by: default avatarAndrew den Exter <andrew.den-exter@nokia.com>
parent 0ecadd95
......@@ -548,27 +548,12 @@ void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F
if (item != rootItem && !(options & DontChangeSubFocusItem)) {
QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
// Correct focus chain in scope
if (oldSubFocusItem) {
QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
while (sfi != scope) {
QQuickItemPrivate::get(sfi)->subFocusItem = 0;
sfi = sfi->parentItem();
}
}
{
scopePrivate->subFocusItem = item;
QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
while (sfi != scope) {
QQuickItemPrivate::get(sfi)->subFocusItem = item;
sfi = sfi->parentItem();
}
}
if (oldSubFocusItem) {
QQuickItemPrivate::get(oldSubFocusItem)->focus = false;
changed << oldSubFocusItem;
}
QQuickItemPrivate::get(item)->updateSubFocusItem(scope, true);
}
if (!(options & DontChangeFocusProperty)) {
......@@ -658,20 +643,13 @@ void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item,
if (item != rootItem && !(options & DontChangeSubFocusItem)) {
QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
// Correct focus chain in scope
if (oldSubFocusItem) {
QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
while (sfi != scope) {
QQuickItemPrivate::get(sfi)->subFocusItem = 0;
sfi = sfi->parentItem();
}
}
scopePrivate->subFocusItem = 0;
if (oldSubFocusItem && !(options & DontChangeFocusProperty)) {
QQuickItemPrivate::get(oldSubFocusItem)->focus = false;
changed << oldSubFocusItem;
}
QQuickItemPrivate::get(item)->updateSubFocusItem(scope, false);
} else if (!(options & DontChangeFocusProperty)) {
QQuickItemPrivate::get(item)->focus = false;
changed << item;
......
......@@ -1621,6 +1621,36 @@ void QQuickItemPrivate::setAccessibleFlagAndListener()
}
}
void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope, bool focus)
{
Q_Q(QQuickItem);
Q_ASSERT(scope);
QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
// Correct focus chain in scope
if (oldSubFocusItem) {
QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
while (sfi != scope) {
QQuickItemPrivate::get(sfi)->subFocusItem = 0;
sfi = sfi->parentItem();
}
}
if (focus) {
scopePrivate->subFocusItem = q;
QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
while (sfi != scope) {
QQuickItemPrivate::get(sfi)->subFocusItem = q;
sfi = sfi->parentItem();
}
} else {
scopePrivate->subFocusItem = 0;
}
}
/*!
\class QQuickItem
\brief The QQuickItem class provides the most basic of all visual items in QML.
......@@ -1895,18 +1925,17 @@ void QQuickItem::setParentItem(QQuickItem *parentItem)
QQuickItem *scopeItem = 0;
if (d->canvas && hasFocus()) {
scopeItem = oldParentItem;
while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem();
scopeFocusedItem = this;
} else if (d->canvas && !isFocusScope() && d->subFocusItem) {
scopeItem = oldParentItem;
while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem();
scopeFocusedItem = d->subFocusItem;
}
if (scopeFocusedItem)
if (scopeFocusedItem) {
scopeItem = oldParentItem;
while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem();
QQuickCanvasPrivate::get(d->canvas)->clearFocusInScope(scopeItem, scopeFocusedItem,
QQuickCanvasPrivate::DontChangeFocusProperty);
}
const bool wasVisible = isVisible();
op->removeChild(this);
......
......@@ -475,6 +475,7 @@ public:
void initCanvas(InitializationState *, QQuickCanvas *);
QQuickItem *subFocusItem;
void updateSubFocusItem(QQuickItem *scope, bool focus);
QTransform canvasToItemTransform() const;
QTransform itemToCanvasTransform() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment