Add SVG::image(QSize size,QString elementId)

This allows SVGItem to fetch elements at various sizes without resizing
the SVG.
This commit is contained in:
David Edmundson 2014-02-28 15:24:08 +01:00
parent c825bd7509
commit 8bdbc034d4
4 changed files with 7 additions and 20 deletions

View File

@ -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"

View File

@ -98,9 +98,6 @@ Q_SIGNALS:
void implicitWidthChanged();
void implicitHeightChanged();
protected:
void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);
protected Q_SLOTS:
void updateNeeded();

View File

@ -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)

View File

@ -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());
/**