diff --git a/widgets/checkbox.cpp b/widgets/checkbox.cpp index 279941b2c..c441199d9 100644 --- a/widgets/checkbox.cpp +++ b/widgets/checkbox.cpp @@ -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 { diff --git a/widgets/checkbox.h b/widgets/checkbox.h index d3b7ffa78..09847f9c7 100644 --- a/widgets/checkbox.h +++ b/widgets/checkbox.h @@ -112,6 +112,8 @@ protected: private: Q_PRIVATE_SLOT(d, void setPalette()) + Q_PRIVATE_SLOT(d, void setPixmap()) + CheckBoxPrivate * const d; }; diff --git a/widgets/label.cpp b/widgets/label.cpp index d8301b82e..ea113c2fe 100644 --- a/widgets/label.cpp +++ b/widgets/label.cpp @@ -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); } diff --git a/widgets/label.h b/widgets/label.h index a1900f5dc..ad969851c 100644 --- a/widgets/label.h +++ b/widgets/label.h @@ -153,6 +153,7 @@ protected: private: Q_PRIVATE_SLOT(d, void setPalette()) + Q_PRIVATE_SLOT(d, void setPixmap()) LabelPrivate * const d; }; diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index f90face65..964e832b0 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -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 diff --git a/widgets/pushbutton.h b/widgets/pushbutton.h index a3d729f49..80dd0e555 100644 --- a/widgets/pushbutton.h +++ b/widgets/pushbutton.h @@ -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 diff --git a/widgets/radiobutton.cpp b/widgets/radiobutton.cpp index 9c50c8e6f..2728d7f11 100644 --- a/widgets/radiobutton.cpp +++ b/widgets/radiobutton.cpp @@ -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(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); } diff --git a/widgets/radiobutton.h b/widgets/radiobutton.h index 0cbfb772a..65d7df63a 100644 --- a/widgets/radiobutton.h +++ b/widgets/radiobutton.h @@ -111,6 +111,8 @@ protected: void resizeEvent(QGraphicsSceneResizeEvent *event); private: + Q_PRIVATE_SLOT(d, void setPixmap()) + RadioButtonPrivate * const d; }; diff --git a/widgets/toolbutton.cpp b/widgets/toolbutton.cpp index 61e0fef42..3a63469d3 100644 --- a/widgets/toolbutton.cpp +++ b/widgets/toolbutton.cpp @@ -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 diff --git a/widgets/toolbutton.h b/widgets/toolbutton.h index 1bc58b05a..6c26ee20a 100644 --- a/widgets/toolbutton.h +++ b/widgets/toolbutton.h @@ -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 diff --git a/widgets/widget.cpp.template b/widgets/widget.cpp.template index 60dfd82c8..ab744d9a5 100644 --- a/widgets/widget.cpp.template +++ b/widgets/widget.cpp.template @@ -33,8 +33,9 @@ namespace Plasma class Private { public: - Private() - : svg(0) + Private( *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<*>(q->widget())->setIcon(QIcon(pm)); } + *q; QString imagePath; QString absImagePath; Svg *svg; @@ -72,7 +80,7 @@ public: ::(QGraphicsWidget *parent) : QGraphicsProxyWidget(parent), - d(new Private) + d(new Private(this)) { * native = new ; //TODO: forward signals diff --git a/widgets/widget.h.template b/widgets/widget.h.template index 43216e64a..c444acac5 100644 --- a/widgets/widget.h.template +++ b/widgets/widget.h.template @@ -97,6 +97,8 @@ protected: void resizeEvent(QGraphicsSceneResizeEvent *event); private: + Q_PRIVATE_SLOT(d, void setPixmap()) + Private * const d; };