add matrixForElement(const QString& elementId) const as discussed on panel-devel

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=695665
This commit is contained in:
Leo Franchi 2007-08-02 16:14:35 +00:00
parent ac918ad4bf
commit ce090faab8
2 changed files with 22 additions and 1 deletions

14
svg.cpp
View File

@ -177,10 +177,16 @@ class Svg::Private
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);
}
QMatrix matrixForElement(const QString& elementId)
{
createRenderer();
return renderer->matrixForElement(elementId);
}
static QHash<QString, SharedSvgRenderer::Ptr> renderers;
SharedSvgRenderer::Ptr renderer;
@ -261,6 +267,12 @@ bool Svg::elementExists(const QString& elementId) const
return d->renderer->elementExists(elementId);
}
QMatrix Svg::matrixForElement(const QString& elementId) const
{
d->createRenderer();
return d->renderer->matrixForElement(elementId);
}
bool Svg::isValid() const
{
d->createRenderer();

9
svg.h
View File

@ -30,6 +30,7 @@ class QRect;
class QRectF;
class QSize;
class QSizeF;
class QMatrix;
namespace Plasma
{
@ -156,6 +157,14 @@ class PLASMA_EXPORT Svg : public QObject
**/
Q_INVOKABLE bool elementExists( const QString& elementId ) const;
/**
* The transformation matrix of the element. That includes the
* transformation on the element itself.
* @arg elementId the id of the element
* @return the matrix for the element
**/
Q_INVOKABLE QMatrix matrixForElement(const QString& elementId) const;
/**
* @return true if the SVG file exists and the document is valid,
* otherwise false. This method can be expensive as it