diff --git a/svg.cpp b/svg.cpp index 858eab344..18d2cc466 100644 --- a/svg.cpp +++ b/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 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(); diff --git a/svg.h b/svg.h index f0804b5a6..3e82fd0b7 100644 --- a/svg.h +++ b/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