From feea867bd3ce0c9943890295551eb9f10f867e90 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 31 Aug 2009 12:14:47 +0000 Subject: [PATCH] make it possible to do contntx resct syncing svn path=/trunk/KDE/kdelibs/; revision=1017768 --- widgets/itembackground.cpp | 23 +++++++++++++++++++++-- widgets/itembackground.h | 9 +++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/widgets/itembackground.cpp b/widgets/itembackground.cpp index 26c64e60d..c3fb997d2 100644 --- a/widgets/itembackground.cpp +++ b/widgets/itembackground.cpp @@ -40,8 +40,9 @@ public: void animationUpdate(qreal progress); void targetDestroyed(QObject*); + void frameSvgChanged(); - ItemBackground *q; + ItemBackground * const q; QGraphicsItem *target; Plasma::FrameSvg *frameSvg; QRectF oldGeometry; @@ -57,18 +58,26 @@ ItemBackground::ItemBackground(QGraphicsWidget *parent) : QGraphicsWidget(parent), d(new ItemBackgroundPrivate(this)) { + setCacheMode(DeviceCoordinateCache); + setFlag(ItemIsMovable, false); + setFlag(ItemIsSelectable, false); + setFlag(ItemIsFocusable, false); + d->frameSvg = new Plasma::FrameSvg(this); d->animId = 0; d->opacity = 1; d->fading = false; d->fadeIn = false; d->immediate = false; - setContentsMargins(0, 0, 0, 0); + qreal l, t, r, b; + d->frameSvg->getMargins(l, t, r, b); + setContentsMargins(l, t, r, b); d->frameSvg->setImagePath("widgets/viewitem"); d->frameSvg->setEnabledBorders(Plasma::FrameSvg::AllBorders); d->frameSvg->setCacheAllRenderedFrames(true); d->frameSvg->setElementPrefix("hover"); + connect(d->frameSvg, SIGNAL(repaintNeeded()), this, SLOT(frameSvgChanged())); setAcceptedMouseButtons(0); setZValue(-800); @@ -240,8 +249,18 @@ void ItemBackgroundPrivate::targetDestroyed(QObject*) q->setTargetItem(0); } +void ItemBackgroundPrivate::frameSvgChanged() +{ + qreal l, t, r, b; + frameSvg->getMargins(l, t, r, b); + q->setContentsMargins(l, t, r, b); + q->update(); + emit q->appearanceChanged(); } +} // Plasma namespace + + #include "itembackground.moc" diff --git a/widgets/itembackground.h b/widgets/itembackground.h index 1f83345b1..35af9511a 100644 --- a/widgets/itembackground.h +++ b/widgets/itembackground.h @@ -61,6 +61,13 @@ public: */ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +Q_SIGNALS: + /** + * Emitted when the visual layout and appearance changes. Useful for syncronizing + * content margins. + */ + void appearanceChanged(); + protected: /** * @reimp from QGraphicsWidget @@ -80,7 +87,9 @@ protected: private: Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress)) Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*)) + Q_PRIVATE_SLOT(d, void frameSvgChanged()) + friend class ItemBackgroundPrivate; ItemBackgroundPrivate * const d; }; }