Fix svg support on Plasma::ToolButton, setting correct path and size of svg

svn path=/trunk/KDE/kdelibs/; revision=997953
This commit is contained in:
Arthur Renato Mello 2009-07-16 18:03:22 +00:00
parent d4ca38b20f
commit d9d08c94e0
2 changed files with 35 additions and 2 deletions

View File

@ -66,11 +66,27 @@ public:
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
pm.fill(Qt::transparent);
if (mime->is("image/svg+xml")) {
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
svg = new Svg();
QPainter p(&pm);
svg->paint(&p, pm.rect());
svg->setImagePath(absImagePath);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
QSizeF elementSize = svg->elementSize(svgElement);
float scale = pm.width() / qMax(elementSize.width(), elementSize.height());
svg->resize(svg->size() * scale);
QRectF elementRect(QPointF(0,0), svg->elementSize(svgElement));
elementRect.moveCenter(q->rect().center());
svg->paint(&p, elementRect, svgElement);
} else {
svg->resize(pm.size());
svg->paint(&p, pm.rect());
}
} else {
pm = QPixmap(absImagePath);
}
@ -93,6 +109,7 @@ public:
QString imagePath;
QString absImagePath;
Svg *svg;
QString svgElement;
};
void ToolButtonPrivate::syncActiveRect()
@ -221,6 +238,12 @@ void ToolButton::setImage(const QString &path)
d->setPixmap(this);
}
void ToolButton::setImage(const QString &path, const QString &elementid)
{
d->svgElement = elementid;
setImage(path);
}
void ToolButton::setIcon(const QIcon &icon)
{
nativeWidget()->setIcon(icon);

View File

@ -83,6 +83,16 @@ public:
*/
void setImage(const QString &path);
/**
* Sets the path to an svg image to display and the id of the used svg element, if necessary.
*
* @arg path the path to the image; if a relative path, then a themed image will be loaded.
* @arg elementid the id of a svg element.
*
* @since 4.4
*/
void setImage(const QString &path, const QString &elementid);
/**
* @return the image path being displayed currently, or an empty string if none.
*/