diff options
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsitem.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsitem.cpp | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 87f5f17531..5dc59436ad 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -1867,15 +1867,46 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) d_ptr->scene->d_func()->updateInputMethodSensitivityInViews(); } + if ((flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) { + bool becomesPanel = (flags & ItemIsPanel); + if ((d_ptr->panelModality != NonModal) && d_ptr->scene) { + // update the panel's modal state + if (becomesPanel) + d_ptr->scene->d_func()->enterModal(this); + else + d_ptr->scene->d_func()->leaveModal(this); + } + if (d_ptr->isWidget && (becomesPanel || parentWidget())) { + QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this); + QGraphicsWidget *focusFirst = w; + QGraphicsWidget *focusLast = w; + for (;;) { + QGraphicsWidget *test = focusLast->d_func()->focusNext; + if (!w->isAncestorOf(test) || test == w) + break; + focusLast = test; + } - if ((d_ptr->panelModality != NonModal) - && d_ptr->scene - && (flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) { - // update the panel's modal state - if (flags & ItemIsPanel) - d_ptr->scene->d_func()->enterModal(this); - else - d_ptr->scene->d_func()->leaveModal(this); + if (becomesPanel) { + // unlink own widgets from focus chain + QGraphicsWidget *beforeMe = w->d_func()->focusPrev; + QGraphicsWidget *afterMe = focusLast->d_func()->focusNext; + beforeMe->d_func()->focusNext = afterMe; + afterMe->d_func()->focusPrev = beforeMe; + focusFirst->d_func()->focusPrev = focusLast; + focusLast->d_func()->focusNext = focusFirst; + if (!isAncestorOf(focusFirst->d_func()->focusNext)) + focusFirst->d_func()->focusNext = w; + } else if (QGraphicsWidget *pw = parentWidget()) { + // link up own widgets to focus chain + QGraphicsWidget *beforeMe = pw; + QGraphicsWidget *afterMe = pw->d_func()->focusNext; + beforeMe->d_func()->focusNext = w; + afterMe->d_func()->focusPrev = focusLast; + w->d_func()->focusPrev = beforeMe; + focusLast->d_func()->focusNext = afterMe; + } + } } if (d_ptr->scene) { @@ -2257,7 +2288,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, scene->d_func()->leaveModal(q_ptr); } if (hasFocus && scene) { - // Hiding the closest non-panel ancestor of the focus item + // Hiding the focus item or the closest non-panel ancestor of the focus item QGraphicsItem *focusItem = scene->focusItem(); bool clear = true; if (isWidget && !focusItem->isPanel()) { @@ -3154,16 +3185,20 @@ void QGraphicsItem::setActive(bool active) // Activate this item. d_ptr->scene->setActivePanel(this); } else { - // Deactivate this item, and reactivate the parent panel, - // or the last active panel (if any). - QGraphicsItem *nextToActivate = 0; - if (d_ptr->parent) - nextToActivate = d_ptr->parent->panel(); - if (!nextToActivate) - nextToActivate = d_ptr->scene->d_func()->lastActivePanel; - if (nextToActivate == this || isAncestorOf(nextToActivate)) - nextToActivate = 0; - d_ptr->scene->setActivePanel(nextToActivate); + QGraphicsItem *activePanel = d_ptr->scene->activePanel(); + QGraphicsItem *thisPanel = panel(); + if (!activePanel || activePanel == thisPanel) { + // Deactivate this item, and reactivate the parent panel, + // or the last active panel (if any). + QGraphicsItem *nextToActivate = 0; + if (d_ptr->parent) + nextToActivate = d_ptr->parent->panel(); + if (!nextToActivate) + nextToActivate = d_ptr->scene->d_func()->lastActivePanel; + if (nextToActivate == this || isAncestorOf(nextToActivate)) + nextToActivate = 0; + d_ptr->scene->setActivePanel(nextToActivate); + } } } } |