IMPROVEMENT: automatically repaint when the svg changes beneath it

svn path=/trunk/KDE/kdelibs/; revision=1167531
This commit is contained in:
Aaron J. Seigo 2010-08-24 20:40:43 +00:00
parent 70fd5a6ae4
commit cc942a894c
2 changed files with 26 additions and 9 deletions

View File

@ -27,27 +27,34 @@
namespace Plasma
{
class SvgWidgetPrivate
{
public:
SvgWidgetPrivate(Svg *s, const QString &element)
: svg(s), elementID(element)
{
}
public:
SvgWidgetPrivate(SvgWidget *widget, Svg *s, const QString &element)
: q(widget), svg(s), elementID(element)
{
}
Svg *svg;
QString elementID;
void svgChanged()
{
q->update();
}
SvgWidget *q;
Svg *svg;
QString elementID;
};
SvgWidget::SvgWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags),
d(new SvgWidgetPrivate(0, QString()))
d(new SvgWidgetPrivate(this, 0, QString()))
{
}
SvgWidget::SvgWidget(Svg *svg, const QString &elementID, QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags),
d(new SvgWidgetPrivate(svg, elementID))
d(new SvgWidgetPrivate(this, svg, elementID))
{
}
@ -76,7 +83,15 @@ void SvgWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void SvgWidget::setSvg(Svg *svg)
{
if (d->svg) {
disconnect(d->svg);
}
d->svg = svg;
if (svg) {
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(svgChanged()));
}
update();
}

View File

@ -66,6 +66,8 @@ class PLASMA_EXPORT SvgWidget : public QGraphicsWidget
void mousePressEvent(QGraphicsSceneMouseEvent * event);
private:
Q_PRIVATE_SLOT(d, void svgChanged())
SvgWidgetPrivate * const d;
};