diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-08-31 12:06:47 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-08-31 14:14:48 (GMT) |
commit | 62ca28a96d200fe55ed5bc2d0d1df327ab44c97e (patch) | |
tree | 0b88b18056f074f7dfb851f3a7fe0aa885955561 /src/gui/graphicsview/qgraphicsitem.cpp | |
parent | 940b0b9e51f234f251d332f729531d6e9c3cea84 (diff) | |
download | Qt-62ca28a96d200fe55ed5bc2d0d1df327ab44c97e.zip Qt-62ca28a96d200fe55ed5bc2d0d1df327ab44c97e.tar.gz Qt-62ca28a96d200fe55ed5bc2d0d1df327ab44c97e.tar.bz2 |
Fix activation behavior for panels, and add QGraphicsItem::setActive().
Allow delayed activation for more fine grained control over which panels
are activated or left inactive when the scene is created.
Autotests included.
Reviewed-by: Brad
Diffstat (limited to 'src/gui/graphicsview/qgraphicsitem.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 86c589d..31fd53a 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2669,6 +2669,37 @@ bool QGraphicsItem::isActive() const } /*! + \since 4.6 + + If \a active is true, and the scene is active, this item's panel will be + activated. Otherwise, the panel is deactivated. + + If the item is not part of an active scene, \a active will decide what + happens to the panel when the scene becomes active or the item is added to + the scene. If true, the item's panel will be activated when the item is + either added to the scene or the scene is activated. Otherwise, the item + will stay inactive independent of the scene's activated state. + + \sa isPanel(), QGraphicsScene::setActivePanel(), QGraphicsScene::isActive() +*/ +void QGraphicsItem::setActive(bool active) +{ + d_ptr->explicitActivate = 1; + d_ptr->wantsActive = active; + if (d_ptr->scene) { + if (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); + } + } +} + +/*! Returns true if this item is active, and it or its \l{focusProxy()}{focus proxy} has keyboard input focus; otherwise, returns false. @@ -6099,8 +6130,10 @@ bool QGraphicsItem::sceneEvent(QEvent *event) if (d_ptr->scene) { for (int i = 0; i < d_ptr->children.size(); ++i) { QGraphicsItem *child = d_ptr->children.at(i); - if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents)) - d_ptr->scene->sendEvent(child, event); + if (child->isVisible() && !child->isPanel()) { + if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents)) + d_ptr->scene->sendEvent(child, event); + } } } break; |