move/resize the background when the target item does so

svn path=/trunk/KDE/kdelibs/; revision=1017728
This commit is contained in:
Aaron J. Seigo 2009-08-31 10:04:17 +00:00
parent 88faa0813f
commit bf26e35f5c
2 changed files with 29 additions and 1 deletions

View File

@ -34,12 +34,14 @@ class ItemBackgroundPrivate
{ {
public: public:
ItemBackgroundPrivate(ItemBackground *parent) ItemBackgroundPrivate(ItemBackground *parent)
: q(parent) : q(parent),
target(0)
{} {}
void animationUpdate(qreal progress); void animationUpdate(qreal progress);
ItemBackground *q; ItemBackground *q;
QGraphicsItem *target;
Plasma::FrameSvg *frameSvg; Plasma::FrameSvg *frameSvg;
QRectF oldGeometry; QRectF oldGeometry;
QRectF newGeometry; QRectF newGeometry;
@ -106,15 +108,36 @@ void ItemBackground::setTarget(const QRectF &newGeometry)
void ItemBackground::setTargetItem(QGraphicsItem *target) void ItemBackground::setTargetItem(QGraphicsItem *target)
{ {
if (d->target && d->target != target) {
d->target->removeSceneEventFilter(this);
}
if (target) { if (target) {
QRectF rect = target->boundingRect(); QRectF rect = target->boundingRect();
rect.moveTopLeft(target->pos()); rect.moveTopLeft(target->pos());
setTarget(rect); setTarget(rect);
if (d->target != target) {
d->target = target;
d->target->installSceneEventFilter(this);
}
} else { } else {
hide(); 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) QVariant ItemBackground::itemChange(GraphicsItemChange change, const QVariant &value)
{ {
if (d->immediate) { if (d->immediate) {

View File

@ -67,6 +67,11 @@ protected:
*/ */
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* @reimp from QGraphicsItem
*/
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
private: private:
ItemBackgroundPrivate * const d; ItemBackgroundPrivate * const d;
Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress)) Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))