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:
parent
8d4d0e0631
commit
e0616c8c5f
17
svg.cpp
17
svg.cpp
@ -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
9
svg.h
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user