when the svg element id changes the pixmap must be generated again

svn path=/trunk/KDE/kdelibs/; revision=880555
This commit is contained in:
Marco Martin 2008-11-05 20:43:53 +00:00
parent ecad3fb271
commit 34f2f49a87
2 changed files with 7 additions and 1 deletions

View File

@ -62,6 +62,7 @@ namespace Plasma
IconWidgetPrivate::IconWidgetPrivate(IconWidget *i) IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
: q(i), : q(i),
iconSvg(0), iconSvg(0),
iconSvgElementChanged(0),
m_fadeIn(false), m_fadeIn(false),
m_hoverAnimId(-1), m_hoverAnimId(-1),
m_hoverAlpha(20 / 255), m_hoverAlpha(20 / 255),
@ -505,6 +506,8 @@ void IconWidget::setSvg(const QString &svgFilePath, const QString &elementId)
d->iconSvg->setImagePath(svgFilePath); d->iconSvg->setImagePath(svgFilePath);
d->iconSvg->setContainsMultipleImages(!elementId.isNull()); d->iconSvg->setContainsMultipleImages(!elementId.isNull());
d->iconSvgElement = elementId; d->iconSvgElement = elementId;
d->iconSvgElementChanged = true;
update();
} }
void IconWidget::hoverEffect(bool show) void IconWidget::hoverEffect(bool show)
@ -599,7 +602,7 @@ QPixmap IconWidgetPrivate::decoration(const QStyleOptionGraphicsItem *option, bo
QIcon::State state = option->state & QStyle::State_Open ? QIcon::On : QIcon::Off; QIcon::State state = option->state & QStyle::State_Open ? QIcon::On : QIcon::Off;
if (iconSvg) { if (iconSvg) {
if (iconSvgPixmap.size() != iconSize.toSize()) { if (iconSvgElementChanged || iconSvgPixmap.size() != iconSize.toSize()) {
QImage img(iconSize.toSize(), QImage::Format_ARGB32_Premultiplied); QImage img(iconSize.toSize(), QImage::Format_ARGB32_Premultiplied);
{ {
img.fill(0); img.fill(0);
@ -608,6 +611,7 @@ QPixmap IconWidgetPrivate::decoration(const QStyleOptionGraphicsItem *option, bo
iconSvg->paint(&p, img.rect(), iconSvgElement); iconSvg->paint(&p, img.rect(), iconSvgElement);
} }
iconSvgPixmap = QPixmap::fromImage(img); iconSvgPixmap = QPixmap::fromImage(img);
iconSvgElementChanged = false;
} }
result = iconSvgPixmap; result = iconSvgPixmap;
} else { } else {
@ -1041,6 +1045,7 @@ void IconWidget::setIcon(const QString &icon)
void IconWidget::setIcon(const QIcon &icon) void IconWidget::setIcon(const QIcon &icon)
{ {
d->icon = icon; d->icon = icon;
update();
} }
QSizeF IconWidget::iconSize() const QSizeF IconWidget::iconSize() const

View File

@ -181,6 +181,7 @@ public:
QString infoText; QString infoText;
Svg *iconSvg; Svg *iconSvg;
QString iconSvgElement; QString iconSvgElement;
bool iconSvgElementChanged;
QPixmap iconSvgPixmap; QPixmap iconSvgPixmap;
QColor textColor; QColor textColor;
QColor shadowColor; QColor shadowColor;