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:
parent
c2b3db02e8
commit
f6849f9d23
23
svg.cpp
23
svg.cpp
@ -83,7 +83,7 @@ class Svg::Private
|
|||||||
if (elementId.isEmpty()) {
|
if (elementId.isEmpty()) {
|
||||||
s = size.toSize();
|
s = size.toSize();
|
||||||
} else {
|
} else {
|
||||||
s = renderer->boundsOnElement(elementId).size().toSize();
|
s = elementSize(elementId);
|
||||||
}
|
}
|
||||||
//kDebug() << "size for " << elementId << " is " << s << endl;
|
//kDebug() << "size for " << elementId << " is " << s << endl;
|
||||||
|
|
||||||
@ -115,6 +115,18 @@ class Svg::Private
|
|||||||
renderer = new KSvgRenderer(path);
|
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
|
//TODO: share renderers between Svg objects with identical themePath
|
||||||
KSvgRenderer* renderer;
|
KSvgRenderer* renderer;
|
||||||
QString themePath;
|
QString themePath;
|
||||||
@ -175,14 +187,7 @@ void Svg::resize()
|
|||||||
|
|
||||||
QSize Svg::elementSize(const QString& elementId) const
|
QSize Svg::elementSize(const QString& elementId) const
|
||||||
{
|
{
|
||||||
d->createRenderer();
|
return d->elementSize(elementId);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize Svg::size() const
|
QSize Svg::size() const
|
||||||
|
Loading…
Reference in New Issue
Block a user