Make the SVG render at the size specified by Svg::size() instead of ignoring it.

Here you go ruphy, you can now implement applet resizing to your heart's content :)

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=669300
This commit is contained in:
Matt Williams 2007-05-28 23:47:41 +00:00
parent c2b3db02e8
commit f6849f9d23

23
svg.cpp
View File

@ -83,7 +83,7 @@ class Svg::Private
if (elementId.isEmpty()) {
s = size.toSize();
} else {
s = renderer->boundsOnElement(elementId).size().toSize();
s = elementSize(elementId);
}
//kDebug() << "size for " << elementId << " is " << s << endl;
@ -115,6 +115,18 @@ class Svg::Private
renderer = new KSvgRenderer(path);
}
QSize elementSize( const QString& elementId )
{
createRenderer();
QSizeF elementSize = renderer->boundsOnElement(elementId).size();
QSizeF naturalSize = renderer->defaultSize();
qreal dx = size.width() / naturalSize.width();
qreal dy = size.height() / naturalSize.height();
elementSize.scale( elementSize.width() * dx, elementSize.height() * dy, Qt::IgnoreAspectRatio );
return elementSize.toSize();
}
//TODO: share renderers between Svg objects with identical themePath
KSvgRenderer* renderer;
QString themePath;
@ -175,14 +187,7 @@ void Svg::resize()
QSize Svg::elementSize(const QString& elementId) const
{
d->createRenderer();
QSizeF elementSize = d->renderer->boundsOnElement(elementId).size();
QSizeF naturalSize = d->renderer->defaultSize();
qreal dx = d->size.width() / naturalSize.width();
qreal dy = d->size.height() / naturalSize.height();
elementSize.scale( elementSize.width() * dx, elementSize.height() * dy, Qt::IgnoreAspectRatio );
return elementSize.toSize();
return d->elementSize(elementId);
}
QSize Svg::size() const