From 8bdbc034d42021a715486dfb17ead498d589d955 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 28 Feb 2014 15:24:08 +0100 Subject: [PATCH] Add SVG::image(QSize size,QString elementId) This allows SVGItem to fetch elements at various sizes without resizing the SVG. --- src/declarativeimports/core/svgitem.cpp | 17 +++-------------- src/declarativeimports/core/svgitem.h | 3 --- src/plasma/svg.cpp | 5 +++-- src/plasma/svg.h | 2 +- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/declarativeimports/core/svgitem.cpp b/src/declarativeimports/core/svgitem.cpp index d51cb66c1..0214442e1 100644 --- a/src/declarativeimports/core/svgitem.cpp +++ b/src/declarativeimports/core/svgitem.cpp @@ -71,9 +71,6 @@ void SvgItem::setElementId(const QString &elementID) } m_elementID = elementID; - if (m_svg) { - m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty()); - } emit elementIdChanged(); emit naturalSizeChanged(); @@ -104,8 +101,6 @@ void SvgItem::setSvg(Plasma::Svg *svg) disconnect(m_svg.data(), 0, this, 0); } m_svg = svg; - m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty()); - m_svg.data()->resize(width(), height()); if (svg) { connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded())); @@ -164,7 +159,9 @@ QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updateP //updating the material if (m_textureChanged || textureNode->texture()->textureSize() != QSize(width(), height())) { - const QImage image = m_svg.data()->image(m_elementID); + //setContainsMultipleImages has to be done there since m_frameSvg can be shared with somebody else + m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty()); + const QImage image = m_svg.data()->image(QSize(width(), height()), m_elementID); QSGTexture *texture = window()->createTextureFromImage(image); textureNode->setTexture(texture); m_textureChanged = false; @@ -218,14 +215,6 @@ qreal SvgItem::implicitHeight() const return QQuickItem::implicitHeight(); } -void SvgItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - if (m_svg) { - m_svg.data()->resize(newGeometry.width(), newGeometry.height()); - } - QQuickItem::geometryChanged(newGeometry, oldGeometry); -} - } // Plasma namespace #include "svgitem.moc" diff --git a/src/declarativeimports/core/svgitem.h b/src/declarativeimports/core/svgitem.h index 085768344..77ed7ea40 100644 --- a/src/declarativeimports/core/svgitem.h +++ b/src/declarativeimports/core/svgitem.h @@ -98,9 +98,6 @@ Q_SIGNALS: void implicitWidthChanged(); void implicitHeightChanged(); -protected: - void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry); - protected Q_SLOTS: void updateNeeded(); diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp index eaeab93fc..1967397a9 100644 --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -668,9 +668,10 @@ QPixmap Svg::pixmap(const QString &elementID) } } -QImage Svg::image(const QString &elementID) +QImage Svg::image(const QSize& size, const QString& elementID) { - return pixmap(elementID).toImage(); + QPixmap pix(d->findInCache(elementID, size)); + return pix.toImage(); } void Svg::paint(QPainter *painter, const QPointF &point, const QString &elementID) diff --git a/src/plasma/svg.h b/src/plasma/svg.h index 76e4ee6f3..5d3fc5884 100644 --- a/src/plasma/svg.h +++ b/src/plasma/svg.h @@ -106,7 +106,7 @@ class PLASMA_EXPORT Svg : public QObject * string for the whole SVG (the default) * @return a QPixmap of the rendered SVG */ - Q_INVOKABLE QImage image(const QString &elementID = QString()); + Q_INVOKABLE QImage image(const QSize &size, const QString &elementID = QString()); /**