elementRect() ... and hopefully i got the math right because i haven't tested it at all. for lfranchi, with love.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=693068
This commit is contained in:
Aaron J. Seigo 2007-07-26 23:07:26 +00:00
parent 8d4d0e0631
commit e0616c8c5f
2 changed files with 25 additions and 1 deletions

17
svg.cpp
View File

@ -170,6 +170,18 @@ class Svg::Private
return elementSize.toSize();
}
QRect elementRect(const QString& elementId)
{
createRenderer();
QRectF elementRect = renderer->boundsOnElement(elementId);
QSizeF naturalSize = renderer->defaultSize();
qreal dx = size.width() / naturalSize.width();
qreal dy = size.height() / naturalSize.height();
return QRect(elementRect.x() * dx, elementRect.y() * dy,
elementRect.width() * dx, elementRect.height() * dy);
}
static QHash<QString, SharedSvgRenderer::Ptr> renderers;
SharedSvgRenderer::Ptr renderer;
QString themePath;
@ -238,6 +250,11 @@ QSize Svg::elementSize(const QString& elementId) const
return d->elementSize(elementId);
}
QRect Svg::elementRect(const QString& elementId) const
{
return d->elementRect(elementId);
}
bool Svg::elementExists(const QString& elementId) const
{
d->createRenderer();

9
svg.h
View File

@ -138,10 +138,17 @@ class PLASMA_EXPORT Svg : public QObject
/**
* Size of a given element
* @arg elementId the id of the element to check
* @return the current size of a given element
* @return the current size of a given element, given the current size of the Svg
**/
Q_INVOKABLE QSize elementSize( const QString& elementId ) const;
/**
* The bounding rect of a given element
* @arg elementId the id of the element to check
* @return the current rect of a given element, given the current size of the Svg
**/
Q_INVOKABLE QRect elementRect(const QString& elementId) const;
/**
* Check when an element exists in the loaded Svg
* @arg elementId the id of the element to check