From a36b7045f9436c13fb8c31dcdb39de83438eacd9 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 31 Aug 2009 10:13:44 +0000 Subject: [PATCH] track item deletion as well svn path=/trunk/KDE/kdelibs/; revision=1017735 --- widgets/itembackground.cpp | 30 ++++++++++++++++++++++++++++++ widgets/itembackground.h | 4 +++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/widgets/itembackground.cpp b/widgets/itembackground.cpp index 9924c4ed3..3b038a7be 100644 --- a/widgets/itembackground.cpp +++ b/widgets/itembackground.cpp @@ -39,6 +39,7 @@ public: {} void animationUpdate(qreal progress); + void targetDestroyed(QObject*); ItemBackground *q; QGraphicsItem *target; @@ -110,6 +111,17 @@ void ItemBackground::setTargetItem(QGraphicsItem *target) { if (d->target && d->target != target) { d->target->removeSceneEventFilter(this); + + QObject *obj = 0; + if (target->isWidget()) { + obj = static_cast(target); + } else { + obj = dynamic_cast(target); + } + + if (obj) { + disconnect(obj, 0, obj, 0); + } } if (target) { @@ -119,9 +131,22 @@ void ItemBackground::setTargetItem(QGraphicsItem *target) if (d->target != target) { d->target = target; + d->target->installSceneEventFilter(this); + + QObject *obj = 0; + if (target->isWidget()) { + obj = static_cast(target); + } else { + obj = dynamic_cast(target); + } + + if (obj) { + connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(targetDestroyed(QObject*))); + } } } else { + d->target = 0; hide(); } } @@ -209,6 +234,11 @@ void ItemBackgroundPrivate::animationUpdate(qreal progress) q->update(); } +void ItemBackgroundPrivate::targetDestroyed(QObject*) +{ + q->setTargetItem(0); +} + } #include "itembackground.moc" diff --git a/widgets/itembackground.h b/widgets/itembackground.h index 016555b8d..9ef1b5552 100644 --- a/widgets/itembackground.h +++ b/widgets/itembackground.h @@ -73,8 +73,10 @@ protected: bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); private: - ItemBackgroundPrivate * const d; Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress)) + Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*)) + + ItemBackgroundPrivate * const d; }; }