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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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