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:
parent
c825bd7509
commit
8bdbc034d4
@ -71,9 +71,6 @@ void SvgItem::setElementId(const QString &elementID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_elementID = elementID;
|
m_elementID = elementID;
|
||||||
if (m_svg) {
|
|
||||||
m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty());
|
|
||||||
}
|
|
||||||
emit elementIdChanged();
|
emit elementIdChanged();
|
||||||
emit naturalSizeChanged();
|
emit naturalSizeChanged();
|
||||||
|
|
||||||
@ -104,8 +101,6 @@ void SvgItem::setSvg(Plasma::Svg *svg)
|
|||||||
disconnect(m_svg.data(), 0, this, 0);
|
disconnect(m_svg.data(), 0, this, 0);
|
||||||
}
|
}
|
||||||
m_svg = svg;
|
m_svg = svg;
|
||||||
m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty());
|
|
||||||
m_svg.data()->resize(width(), height());
|
|
||||||
|
|
||||||
if (svg) {
|
if (svg) {
|
||||||
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
|
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
|
||||||
@ -164,7 +159,9 @@ QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updateP
|
|||||||
//updating the material
|
//updating the material
|
||||||
|
|
||||||
if (m_textureChanged || textureNode->texture()->textureSize() != QSize(width(), height())) {
|
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);
|
QSGTexture *texture = window()->createTextureFromImage(image);
|
||||||
textureNode->setTexture(texture);
|
textureNode->setTexture(texture);
|
||||||
m_textureChanged = false;
|
m_textureChanged = false;
|
||||||
@ -218,14 +215,6 @@ qreal SvgItem::implicitHeight() const
|
|||||||
return QQuickItem::implicitHeight();
|
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
|
} // Plasma namespace
|
||||||
|
|
||||||
#include "svgitem.moc"
|
#include "svgitem.moc"
|
||||||
|
@ -98,9 +98,6 @@ Q_SIGNALS:
|
|||||||
void implicitWidthChanged();
|
void implicitWidthChanged();
|
||||||
void implicitHeightChanged();
|
void implicitHeightChanged();
|
||||||
|
|
||||||
protected:
|
|
||||||
void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);
|
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void updateNeeded();
|
void updateNeeded();
|
||||||
|
|
||||||
|
@ -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)
|
void Svg::paint(QPainter *painter, const QPointF &point, const QString &elementID)
|
||||||
|
@ -106,7 +106,7 @@ class PLASMA_EXPORT Svg : public QObject
|
|||||||
* string for the whole SVG (the default)
|
* string for the whole SVG (the default)
|
||||||
* @return a QPixmap of the rendered SVG
|
* @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());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user