Force repainting a texture if the theme changes
This commit is contained in:
parent
1eb0deb0df
commit
9e5727d15c
@ -46,7 +46,8 @@ void SVGTextureNode::setTexture(QSGTexture *texture) {
|
|||||||
|
|
||||||
SvgItem::SvgItem(QQuickItem *parent)
|
SvgItem::SvgItem(QQuickItem *parent)
|
||||||
: QQuickItem(parent),
|
: QQuickItem(parent),
|
||||||
m_smooth(false)
|
m_smooth(false),
|
||||||
|
m_textureChanged(false)
|
||||||
{
|
{
|
||||||
setFlag(QQuickItem::ItemHasContents, true);
|
setFlag(QQuickItem::ItemHasContents, true);
|
||||||
}
|
}
|
||||||
@ -72,6 +73,8 @@ void SvgItem::setElementId(const QString &elementID)
|
|||||||
m_elementID = elementID;
|
m_elementID = elementID;
|
||||||
emit elementIdChanged();
|
emit elementIdChanged();
|
||||||
emit naturalSizeChanged();
|
emit naturalSizeChanged();
|
||||||
|
|
||||||
|
m_textureChanged = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +114,8 @@ void SvgItem::setSvg(Plasma::Svg *svg)
|
|||||||
setImplicitHeight(naturalSize().height());
|
setImplicitHeight(naturalSize().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_textureChanged = true;
|
||||||
|
|
||||||
emit svgChanged();
|
emit svgChanged();
|
||||||
emit naturalSizeChanged();
|
emit naturalSizeChanged();
|
||||||
}
|
}
|
||||||
@ -138,25 +143,28 @@ QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updateP
|
|||||||
{
|
{
|
||||||
if (!window() || !m_svg) {
|
if (!window() || !m_svg) {
|
||||||
delete oldNode;
|
delete oldNode;
|
||||||
return 0;
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SVGTextureNode *textureNode = static_cast<SVGTextureNode *>(oldNode);
|
SVGTextureNode *textureNode = static_cast<SVGTextureNode *>(oldNode);
|
||||||
if (!textureNode) {
|
if (!textureNode) {
|
||||||
textureNode = new SVGTextureNode;
|
textureNode = new SVGTextureNode;
|
||||||
|
m_textureChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO use a heuristic to work out when to redraw
|
//TODO use a heuristic to work out when to redraw
|
||||||
//if !m_smooth and size is approximate simply change the textureNode.rect without
|
//if !m_smooth and size is approximate simply change the textureNode.rect without
|
||||||
//updating the material
|
//updating the material
|
||||||
|
|
||||||
if (!textureNode->texture() || textureNode->texture()->textureSize() != QSize(width(), height())) {
|
if (m_textureChanged || textureNode->texture()->textureSize() != QSize(width(), height())) {
|
||||||
m_svg.data()->resize(width(), height());
|
m_svg.data()->resize(width(), height());
|
||||||
m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty());
|
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);
|
||||||
|
m_textureChanged = false;
|
||||||
|
|
||||||
textureNode->setRect(0, 0, width(), height());
|
textureNode->setRect(0, 0, width(), height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ private:
|
|||||||
QWeakPointer<Plasma::Svg> m_svg;
|
QWeakPointer<Plasma::Svg> m_svg;
|
||||||
QString m_elementID;
|
QString m_elementID;
|
||||||
bool m_smooth;
|
bool m_smooth;
|
||||||
|
bool m_textureChanged;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user