track item deletion as well

svn path=/trunk/KDE/kdelibs/; revision=1017735
This commit is contained in:
Aaron J. Seigo 2009-08-31 10:13:44 +00:00
parent bf26e35f5c
commit a36b7045f9
2 changed files with 33 additions and 1 deletions

View File

@ -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<QGraphicsWidget*>(target);
} else {
obj = dynamic_cast<QObject *>(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<QGraphicsWidget*>(target);
} else {
obj = dynamic_cast<QObject *>(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"

View File

@ -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;
};
}