Update SVG outside paint loop
This commit is contained in:
parent
9e5727d15c
commit
c825bd7509
@ -22,7 +22,7 @@
|
|||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QSGTexture>
|
#include <QSGTexture>
|
||||||
#include <QSGSimpleTextureNode>
|
#include <QSGSimpleTextureNode>
|
||||||
|
#include <QRectF>
|
||||||
|
|
||||||
#include "QDebug"
|
#include "QDebug"
|
||||||
#include "plasma/svg.h"
|
#include "plasma/svg.h"
|
||||||
@ -71,6 +71,9 @@ 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();
|
||||||
|
|
||||||
@ -101,12 +104,16 @@ 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()));
|
||||||
connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged()));
|
connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged()));
|
||||||
connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged()));
|
connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (implicitWidth() <= 0) {
|
if (implicitWidth() <= 0) {
|
||||||
setImplicitWidth(naturalSize().width());
|
setImplicitWidth(naturalSize().width());
|
||||||
}
|
}
|
||||||
@ -157,9 +164,6 @@ 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())) {
|
||||||
m_svg.data()->resize(width(), height());
|
|
||||||
m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty());
|
|
||||||
|
|
||||||
const QImage image = m_svg.data()->image(m_elementID);
|
const QImage image = m_svg.data()->image(m_elementID);
|
||||||
QSGTexture *texture = window()->createTextureFromImage(image);
|
QSGTexture *texture = window()->createTextureFromImage(image);
|
||||||
textureNode->setTexture(texture);
|
textureNode->setTexture(texture);
|
||||||
@ -214,6 +218,14 @@ 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,6 +98,9 @@ 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();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user