make it possible to do contntx resct syncing

svn path=/trunk/KDE/kdelibs/; revision=1017768
This commit is contained in:
Aaron J. Seigo 2009-08-31 12:14:47 +00:00
parent b4fa1b3859
commit feea867bd3
2 changed files with 30 additions and 2 deletions

View File

@ -40,8 +40,9 @@ public:
void animationUpdate(qreal progress); void animationUpdate(qreal progress);
void targetDestroyed(QObject*); void targetDestroyed(QObject*);
void frameSvgChanged();
ItemBackground *q; ItemBackground * const q;
QGraphicsItem *target; QGraphicsItem *target;
Plasma::FrameSvg *frameSvg; Plasma::FrameSvg *frameSvg;
QRectF oldGeometry; QRectF oldGeometry;
@ -57,18 +58,26 @@ ItemBackground::ItemBackground(QGraphicsWidget *parent)
: QGraphicsWidget(parent), : QGraphicsWidget(parent),
d(new ItemBackgroundPrivate(this)) d(new ItemBackgroundPrivate(this))
{ {
setCacheMode(DeviceCoordinateCache);
setFlag(ItemIsMovable, false);
setFlag(ItemIsSelectable, false);
setFlag(ItemIsFocusable, false);
d->frameSvg = new Plasma::FrameSvg(this); d->frameSvg = new Plasma::FrameSvg(this);
d->animId = 0; d->animId = 0;
d->opacity = 1; d->opacity = 1;
d->fading = false; d->fading = false;
d->fadeIn = false; d->fadeIn = false;
d->immediate = 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->setImagePath("widgets/viewitem");
d->frameSvg->setEnabledBorders(Plasma::FrameSvg::AllBorders); d->frameSvg->setEnabledBorders(Plasma::FrameSvg::AllBorders);
d->frameSvg->setCacheAllRenderedFrames(true); d->frameSvg->setCacheAllRenderedFrames(true);
d->frameSvg->setElementPrefix("hover"); d->frameSvg->setElementPrefix("hover");
connect(d->frameSvg, SIGNAL(repaintNeeded()), this, SLOT(frameSvgChanged()));
setAcceptedMouseButtons(0); setAcceptedMouseButtons(0);
setZValue(-800); setZValue(-800);
@ -240,8 +249,18 @@ void ItemBackgroundPrivate::targetDestroyed(QObject*)
q->setTargetItem(0); 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" #include "itembackground.moc"

View File

@ -61,6 +61,13 @@ public:
*/ */
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 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: protected:
/** /**
* @reimp from QGraphicsWidget * @reimp from QGraphicsWidget
@ -80,7 +87,9 @@ protected:
private: private:
Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress)) Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))
Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*)) Q_PRIVATE_SLOT(d, void targetDestroyed(QObject*))
Q_PRIVATE_SLOT(d, void frameSvgChanged())
friend class ItemBackgroundPrivate;
ItemBackgroundPrivate * const d; ItemBackgroundPrivate * const d;
}; };
} }