Render SvgItem natively rather than going through QQuickPaintedItem
This commit is contained in:
parent
1a55ac0c8c
commit
9851f8c789
@ -20,6 +20,10 @@
|
|||||||
#include "svgitem.h"
|
#include "svgitem.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QQuickWindow>
|
||||||
|
#include <QSGTexture>
|
||||||
|
#include <QSGSimpleTextureNode>
|
||||||
|
|
||||||
|
|
||||||
#include "QDebug"
|
#include "QDebug"
|
||||||
#include "plasma/svg.h"
|
#include "plasma/svg.h"
|
||||||
@ -28,7 +32,7 @@ namespace Plasma
|
|||||||
{
|
{
|
||||||
|
|
||||||
SvgItem::SvgItem(QQuickItem *parent)
|
SvgItem::SvgItem(QQuickItem *parent)
|
||||||
: QQuickPaintedItem(parent),
|
: QQuickItem(parent),
|
||||||
m_smooth(false)
|
m_smooth(false)
|
||||||
{
|
{
|
||||||
setFlag(QQuickItem::ItemHasContents, true);
|
setFlag(QQuickItem::ItemHasContents, true);
|
||||||
@ -110,7 +114,6 @@ void SvgItem::setSmooth(const bool smooth)
|
|||||||
}
|
}
|
||||||
m_smooth = smooth;
|
m_smooth = smooth;
|
||||||
emit smoothChanged();
|
emit smoothChanged();
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SvgItem::smooth() const
|
bool SvgItem::smooth() const
|
||||||
@ -118,22 +121,23 @@ bool SvgItem::smooth() const
|
|||||||
return m_smooth;
|
return m_smooth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvgItem::paint(QPainter *painter)
|
QSGNode* SvgItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData)
|
||||||
{
|
{
|
||||||
if (!m_svg) {
|
Q_UNUSED(updatePaintNodeData);
|
||||||
return;
|
QSGSimpleTextureNode *textureNode = static_cast<QSGSimpleTextureNode*>(oldNode);
|
||||||
|
if (!textureNode) {
|
||||||
|
textureNode = new QSGSimpleTextureNode;
|
||||||
}
|
}
|
||||||
//do without painter save, faster and the support can be compiled out
|
|
||||||
const bool wasAntiAlias = painter->testRenderHint(QPainter::Antialiasing);
|
|
||||||
const bool wasSmoothTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform);
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, m_smooth);
|
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth);
|
|
||||||
|
|
||||||
//setContainsMultipleImages has to be done there since m_frameSvg can be shared with somebody else
|
if (window() && m_svg) {
|
||||||
m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty());
|
m_svg.data()->resize(width(), height());
|
||||||
m_svg.data()->paint(painter, boundingRect(), m_elementID);
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias);
|
//TODO make m_svg return a QImage so that we can avoid the deep copy in toImage();
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform);
|
const QPixmap pixmap = m_svg.data()->pixmap();
|
||||||
|
textureNode->setRect(0,0, pixmap.width(), pixmap.height());
|
||||||
|
textureNode->setTexture(window()->createTextureFromImage(pixmap.toImage()));
|
||||||
|
}
|
||||||
|
return textureNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvgItem::updateNeeded()
|
void SvgItem::updateNeeded()
|
||||||
@ -144,6 +148,7 @@ void SvgItem::updateNeeded()
|
|||||||
if (implicitHeight() <= 0) {
|
if (implicitHeight() <= 0) {
|
||||||
setImplicitHeight(naturalSize().height());
|
setImplicitHeight(naturalSize().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,14 @@
|
|||||||
#ifndef SVGITEM_P
|
#ifndef SVGITEM_P
|
||||||
#define SVGITEM_P
|
#define SVGITEM_P
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
class QImage;
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
|
|
||||||
class Svg;
|
class Svg;
|
||||||
|
|
||||||
class SvgItem : public QQuickPaintedItem
|
class SvgItem : public QQuickItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -81,14 +82,14 @@ public:
|
|||||||
|
|
||||||
QSizeF naturalSize() const;
|
QSizeF naturalSize() const;
|
||||||
|
|
||||||
void paint(QPainter *painter);
|
|
||||||
|
|
||||||
void setImplicitWidth(qreal width);
|
void setImplicitWidth(qreal width);
|
||||||
qreal implicitWidth() const;
|
qreal implicitWidth() const;
|
||||||
|
|
||||||
void setImplicitHeight(qreal height);
|
void setImplicitHeight(qreal height);
|
||||||
qreal implicitHeight() const;
|
qreal implicitHeight() const;
|
||||||
|
|
||||||
|
QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void elementIdChanged();
|
void elementIdChanged();
|
||||||
void svgChanged();
|
void svgChanged();
|
||||||
|
Loading…
Reference in New Issue
Block a user