summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicsitem.cpp
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andrhans@cisco.com>2012-11-23 11:48:27 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-26 21:23:15 +0100
commitbfb569b6e70cc6a56566002d1cb278a0122189d1 (patch)
treec17330cd85296b0a512c2dd654712b99a78d4582 /src/widgets/graphicsview/qgraphicsitem.cpp
parent85cf6cd5f253694ad0e7d51fdd0fcfdfe65d8dc8 (diff)
Ensure subfocus is not reset to 0 when hiding a panel.
When hiding any widget that is not a panel, it is correct to clear subfocus. In case clearFocus() has been called, the result is that focusItem() / focusWidget() points to 0, which is correct. Upon reactivation, nothing gains input focus. When changing focus, the following setSubFocus() call will ensure subfocus points to the new widget. When hiding a panel, however, it's essential that subfocus within that panel is not cleared, otherwise, when re-showing the panel, nothing will have focus, whereas the expected behavior is that focus is restored to the last item that had focus, i.e., the focusItem() a.k.a. subfocus widget. Task-number: QTBUG-22256 Change-Id: I84d849a505764e074e1369fef923cef1ad5c0b1e Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsitem.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp
index 95244b8534..70b44428f2 100644
--- a/src/widgets/graphicsview/qgraphicsitem.cpp
+++ b/src/widgets/graphicsview/qgraphicsitem.cpp
@@ -2216,7 +2216,8 @@ bool QGraphicsItem::isVisibleTo(const QGraphicsItem *parent) const
Sets this item's visibility to \a newVisible. If \a explicitly is true,
this item will be "explicitly" \a newVisible; otherwise, it.. will not be.
*/
-void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bool update)
+void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly,
+ bool update, bool hiddenByPanel)
{
Q_Q(QGraphicsItem);
@@ -2277,7 +2278,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
} while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
}
if (clear)
- clearFocusHelper(/* giveFocusToParent = */ false);
+ clearFocusHelper(/* giveFocusToParent = */ false, hiddenByPanel);
}
if (q_ptr->isSelected())
q_ptr->setSelected(false);
@@ -2301,7 +2302,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
&& !(flags & QGraphicsItem::ItemHasNoContents));
foreach (QGraphicsItem *child, children) {
if (!newVisible || !child->d_ptr->explicitlyHidden)
- child->d_ptr->setVisibleHelper(newVisible, false, updateChildren);
+ child->d_ptr->setVisibleHelper(newVisible, false, updateChildren, hiddenByPanel);
}
// Update activation
@@ -2399,7 +2400,10 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo
*/
void QGraphicsItem::setVisible(bool visible)
{
- d_ptr->setVisibleHelper(visible, /* explicit = */ true);
+ d_ptr->setVisibleHelper(visible,
+ /* explicit = */ true,
+ /* update = */ true,
+ /* hiddenByPanel = */ isPanel());
}
/*!
@@ -3159,10 +3163,16 @@ void QGraphicsItem::setActive(bool active)
// Activate this item.
d_ptr->scene->setActivePanel(this);
} else {
- // Deactivate this item, and reactivate the last active item
- // (if any).
- QGraphicsItem *lastActive = d_ptr->scene->d_func()->lastActivePanel;
- d_ptr->scene->setActivePanel(lastActive != this ? lastActive : 0);
+ // 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);
}
}
}
@@ -3256,7 +3266,7 @@ void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool clim
// Update the child focus chain.
QGraphicsItem *commonAncestor = 0;
- if (scene && scene->focusItem()) {
+ if (scene && scene->focusItem() && scene->focusItem()->panel() == q_ptr->panel()) {
commonAncestor = scene->focusItem()->commonAncestorItem(f);
scene->focusItem()->d_ptr->clearSubFocus(scene->focusItem(), commonAncestor);
}
@@ -3286,13 +3296,14 @@ void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool clim
*/
void QGraphicsItem::clearFocus()
{
- d_ptr->clearFocusHelper(/* giveFocusToParent = */ true);
+ d_ptr->clearFocusHelper(/* giveFocusToParent = */ true,
+ /* hiddenByParentPanel = */ false);
}
/*!
\internal
*/
-void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent)
+void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenByParentPanel)
{
if (giveFocusToParent) {
// Pass focus to the closest parent focus scope
@@ -3317,7 +3328,8 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent)
if (q_ptr->hasFocus()) {
// Invisible items with focus must explicitly clear subfocus.
- clearSubFocus(q_ptr);
+ if (!hiddenByParentPanel)
+ clearSubFocus(q_ptr);
// If this item has the scene's input focus, clear it.
scene->setFocusItem(0);