summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicsitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsitem.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.cpp75
1 files changed, 55 insertions, 20 deletions
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp
index 5c9651f1c9..9aeee7c37a 100644
--- a/src/widgets/graphicsview/qgraphicsitem.cpp
+++ b/src/widgets/graphicsview/qgraphicsitem.cpp
@@ -3,7 +3,7 @@
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtGui module of the Qt Toolkit.
+** This file is part of the QtWidgets module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
@@ -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) {
@@ -2259,7 +2290,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()) {
@@ -3156,16 +3187,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);
+ }
}
}
}