diff --git a/widgets/itembackground.cpp b/widgets/itembackground.cpp index 8cc831616..9924c4ed3 100644 --- a/widgets/itembackground.cpp +++ b/widgets/itembackground.cpp @@ -34,12 +34,14 @@ class ItemBackgroundPrivate { public: ItemBackgroundPrivate(ItemBackground *parent) - : q(parent) + : q(parent), + target(0) {} void animationUpdate(qreal progress); ItemBackground *q; + QGraphicsItem *target; Plasma::FrameSvg *frameSvg; QRectF oldGeometry; QRectF newGeometry; @@ -106,15 +108,36 @@ void ItemBackground::setTarget(const QRectF &newGeometry) void ItemBackground::setTargetItem(QGraphicsItem *target) { + if (d->target && d->target != target) { + d->target->removeSceneEventFilter(this); + } + if (target) { QRectF rect = target->boundingRect(); rect.moveTopLeft(target->pos()); setTarget(rect); + + if (d->target != target) { + d->target = target; + d->target->installSceneEventFilter(this); + } } else { hide(); } } +bool ItemBackground::sceneEventFilter(QGraphicsItem *watched, QEvent *event) +{ + if (watched == d->target) { + if (event->type() == QEvent::GraphicsSceneResize || + event->type() == QEvent::GraphicsSceneMove) { + setTargetItem(d->target); + } + } + + return false; +} + QVariant ItemBackground::itemChange(GraphicsItemChange change, const QVariant &value) { if (d->immediate) { diff --git a/widgets/itembackground.h b/widgets/itembackground.h index 46ae0c452..016555b8d 100644 --- a/widgets/itembackground.h +++ b/widgets/itembackground.h @@ -67,6 +67,11 @@ protected: */ QVariant itemChange(GraphicsItemChange change, const QVariant &value); + /** + * @reimp from QGraphicsItem + */ + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); + private: ItemBackgroundPrivate * const d; Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))