* repaint the svg when the theme changes

* delete the svg before creating a new one
* only create a new svg object if the path has changed

svn path=/trunk/KDE/kdelibs/; revision=1022989
This commit is contained in:
Aaron J. Seigo 2009-09-13 17:13:55 +00:00
parent 0ab4b19c25
commit 45b39e84c4
12 changed files with 81 additions and 38 deletions

View File

@ -54,8 +54,14 @@ public:
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml")) {
svg = new Svg();
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {

View File

@ -112,6 +112,8 @@ protected:
private:
Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
CheckBoxPrivate * const d;
};

View File

@ -49,7 +49,7 @@ public:
delete svg;
}
void setPixmap(Label *q)
void setPixmap()
{
if (imagePath.isEmpty()) {
return;
@ -58,9 +58,14 @@ public:
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml") || mime->is("application/x-gzip")) {
svg = new Svg();
svg->setImagePath(imagePath);
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
@ -149,7 +154,7 @@ void Label::setImage(const QString &path)
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
d->setPixmap();
}
QString Label::image() const
@ -218,7 +223,7 @@ void Label::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Dat
void Label::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}

View File

@ -153,6 +153,7 @@ protected:
private:
Q_PRIVATE_SLOT(d, void setPalette())
Q_PRIVATE_SLOT(d, void setPixmap())
LabelPrivate * const d;
};

View File

@ -59,7 +59,7 @@ public:
delete svg;
}
void setPixmap(PushButton *q)
void setPixmap()
{
if (imagePath.isEmpty()) {
return;
@ -70,8 +70,12 @@ public:
pm.fill(Qt::transparent);
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
svg = new Svg();
svg->setImagePath(absImagePath);
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
@ -220,7 +224,7 @@ void PushButton::setImage(const QString &path)
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
d->setPixmap();
}
void PushButton::setImage(const QString &path, const QString &elementid)
@ -286,7 +290,7 @@ KPushButton *PushButton::nativeWidget() const
void PushButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
d->setPixmap();
if (d->background) {
//resize all four panels

View File

@ -191,11 +191,12 @@ protected:
void changeEvent(QEvent *event);
private:
PushButtonPrivate *const d;
friend class PushButtonPrivate;
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))
Q_PRIVATE_SLOT(d, void setPixmap())
friend class PushButtonPrivate;
PushButtonPrivate *const d;
};
} // namespace Plasma

View File

@ -34,8 +34,9 @@ namespace Plasma
class RadioButtonPrivate
{
public:
RadioButtonPrivate()
: svg(0)
RadioButtonPrivate(RadioButton *w)
: q(w),
svg(0)
{
}
@ -44,7 +45,7 @@ public:
delete svg;
}
void setPixmap(RadioButton *q)
void setPixmap()
{
if (imagePath.isEmpty()) {
return;
@ -53,8 +54,14 @@ public:
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml")) {
svg = new Svg();
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
@ -64,6 +71,7 @@ public:
static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
}
RadioButton *q;
QString imagePath;
QString absImagePath;
Svg *svg;
@ -71,7 +79,7 @@ public:
RadioButton::RadioButton(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new RadioButtonPrivate)
d(new RadioButtonPrivate(this))
{
QRadioButton *native = new QRadioButton;
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
@ -119,7 +127,7 @@ void RadioButton::setImage(const QString &path)
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
d->setPixmap();
}
QString RadioButton::image() const
@ -144,7 +152,7 @@ QRadioButton *RadioButton::nativeWidget() const
void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
d->setPixmap();
QGraphicsProxyWidget::resizeEvent(event);
}

View File

@ -111,6 +111,8 @@ protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap())
RadioButtonPrivate * const d;
};

View File

@ -59,7 +59,7 @@ public:
delete svg;
}
void setPixmap(ToolButton *q)
void setPixmap()
{
if (imagePath.isEmpty()) {
return;
@ -70,11 +70,14 @@ public:
pm.fill(Qt::transparent);
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
svg = new Svg();
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->setImagePath(absImagePath);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
QSizeF elementSize = svg->elementSize(svgElement);
float scale = pm.width() / qMax(elementSize.width(), elementSize.height());
@ -237,7 +240,7 @@ void ToolButton::setImage(const QString &path)
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap(this);
d->setPixmap();
}
void ToolButton::setImage(const QString &path, const QString &elementid)
@ -278,7 +281,7 @@ QToolButton *ToolButton::nativeWidget() const
void ToolButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap(this);
d->setPixmap();
if (d->background) {
//resize all four panels

View File

@ -160,13 +160,14 @@ protected:
void changeEvent(QEvent *event);
private:
ToolButtonPrivate *const d;
friend class ToolButtonPrivate;
Q_PRIVATE_SLOT(d, void syncBorders())
Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))
Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
Q_PRIVATE_SLOT(d, void setPixmap())
friend class ToolButtonPrivate;
ToolButtonPrivate *const d;
};
} // namespace Plasma

View File

@ -33,8 +33,9 @@ namespace Plasma
class <Name>Private
{
public:
<Name>Private()
: svg(0)
<Name>Private(<Name> *w)
: q(w),
svg(0)
{
}
@ -53,7 +54,13 @@ public:
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml")) {
svg = new Svg();
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
@ -65,6 +72,7 @@ public:
//static_cast<<Native>*>(q->widget())->setIcon(QIcon(pm));
}
<Name> *q;
QString imagePath;
QString absImagePath;
Svg *svg;
@ -72,7 +80,7 @@ public:
<Name>::<Name>(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new <Name>Private)
d(new <Name>Private(this))
{
<Native>* native = new <Native>;
//TODO: forward signals

View File

@ -97,6 +97,8 @@ protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap())
<Name>Private * const d;
};