Port FrameSVGItem to paint directly
REVIEW: 116618
This commit is contained in:
parent
c3d6c00a95
commit
6599c25087
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 Marco Martin <mart@kde.org>
|
* Copyright 2010 Marco Martin <mart@kde.org>
|
||||||
|
* Copyright 2014 David Edmundson <davidedmundson@kde.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
@ -19,10 +20,11 @@
|
|||||||
|
|
||||||
#include "framesvgitem.h"
|
#include "framesvgitem.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QQuickWindow>
|
||||||
|
#include <QSGTexture>
|
||||||
#include "QDebug"
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "svgtexturenode.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -93,7 +95,8 @@ bool FrameSvgItemMargins::isFixed() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
FrameSvgItem::FrameSvgItem(QQuickItem *parent)
|
FrameSvgItem::FrameSvgItem(QQuickItem *parent)
|
||||||
: QQuickPaintedItem(parent)
|
: QQuickItem(parent),
|
||||||
|
m_textureChanged(false)
|
||||||
{
|
{
|
||||||
m_frameSvg = new Plasma::FrameSvg(this);
|
m_frameSvg = new Plasma::FrameSvg(this);
|
||||||
m_margins = new FrameSvgItemMargins(m_frameSvg, this);
|
m_margins = new FrameSvgItemMargins(m_frameSvg, this);
|
||||||
@ -132,6 +135,7 @@ void FrameSvgItem::setImagePath(const QString &path)
|
|||||||
|
|
||||||
if (isComponentComplete()) {
|
if (isComponentComplete()) {
|
||||||
m_frameSvg->resizeFrame(QSizeF(width(), height()));
|
m_frameSvg->resizeFrame(QSizeF(width(), height()));
|
||||||
|
m_textureChanged = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,6 +168,7 @@ void FrameSvgItem::setPrefix(const QString &prefix)
|
|||||||
|
|
||||||
if (isComponentComplete()) {
|
if (isComponentComplete()) {
|
||||||
m_frameSvg->resizeFrame(QSizeF(width(), height()));
|
m_frameSvg->resizeFrame(QSizeF(width(), height()));
|
||||||
|
m_textureChanged = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,6 +195,7 @@ void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders bord
|
|||||||
|
|
||||||
m_frameSvg->setEnabledBorders(borders);
|
m_frameSvg->setEnabledBorders(borders);
|
||||||
emit enabledBordersChanged();
|
emit enabledBordersChanged();
|
||||||
|
m_textureChanged = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,16 +209,12 @@ bool FrameSvgItem::hasElementPrefix(const QString &prefix) const
|
|||||||
return m_frameSvg->hasElementPrefix(prefix);
|
return m_frameSvg->hasElementPrefix(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameSvgItem::paint(QPainter *painter)
|
|
||||||
{
|
|
||||||
m_frameSvg->paintFrame(painter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
|
void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
|
||||||
const QRectF &oldGeometry)
|
const QRectF &oldGeometry)
|
||||||
{
|
{
|
||||||
if (isComponentComplete()) {
|
if (isComponentComplete()) {
|
||||||
m_frameSvg->resizeFrame(newGeometry.size());
|
m_frameSvg->resizeFrame(newGeometry.size());
|
||||||
|
m_textureChanged = true;
|
||||||
}
|
}
|
||||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
||||||
}
|
}
|
||||||
@ -227,6 +229,7 @@ void FrameSvgItem::doUpdate()
|
|||||||
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_textureChanged = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,10 +270,37 @@ Plasma::FrameSvg *FrameSvgItem::frameSvg() const
|
|||||||
return m_frameSvg;
|
return m_frameSvg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSGNode* FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData*)
|
||||||
|
{
|
||||||
|
if (!window() || !m_frameSvg || !m_frameSvg->hasElementPrefix(m_prefix)) {
|
||||||
|
delete oldNode;
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
SVGTextureNode *textureNode = static_cast<SVGTextureNode *>(oldNode);
|
||||||
|
if (!textureNode) {
|
||||||
|
textureNode = new SVGTextureNode;
|
||||||
|
textureNode->setFiltering(QSGTexture::Nearest);
|
||||||
|
m_textureChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_textureChanged || textureNode->texture()->textureSize() != m_frameSvg->size()) {
|
||||||
|
const QImage image = m_frameSvg->framePixmap().toImage();
|
||||||
|
QSGTexture *texture = window()->createTextureFromImage(image);
|
||||||
|
texture->setFiltering(QSGTexture::Nearest);
|
||||||
|
textureNode->setTexture(texture);
|
||||||
|
m_textureChanged = false;
|
||||||
|
textureNode->setRect(0, 0, width(), height());
|
||||||
|
}
|
||||||
|
|
||||||
|
return textureNode;
|
||||||
|
}
|
||||||
|
|
||||||
void FrameSvgItem::componentComplete()
|
void FrameSvgItem::componentComplete()
|
||||||
{
|
{
|
||||||
QQuickItem::componentComplete();
|
QQuickItem::componentComplete();
|
||||||
m_frameSvg->resizeFrame(QSize(width(), height()));
|
m_frameSvg->resizeFrame(QSize(width(), height()));
|
||||||
|
m_textureChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -279,6 +309,7 @@ void FrameSvgItem::updateDevicePixelRatio()
|
|||||||
//devicepixelratio is always set integer in the svg, so needs at least 192dpi to double up.
|
//devicepixelratio is always set integer in the svg, so needs at least 192dpi to double up.
|
||||||
//(it needs to be integer to have lines contained inside a svg piece to keep being pixel aligned)
|
//(it needs to be integer to have lines contained inside a svg piece to keep being pixel aligned)
|
||||||
m_frameSvg->setDevicePixelRatio(qMax((qreal)1.0, floor(m_units.devicePixelRatio())));
|
m_frameSvg->setDevicePixelRatio(qMax((qreal)1.0, floor(m_units.devicePixelRatio())));
|
||||||
|
m_textureChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright 2010 Marco Martin <mart@kde.org> *
|
* Copyright 2010 Marco Martin <mart@kde.org> *
|
||||||
|
* Copyright 2014 David Edmundson <davidedmundson@kde.org> *
|
||||||
|
* *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -19,7 +21,7 @@
|
|||||||
#ifndef FRAMESVGITEM_P
|
#ifndef FRAMESVGITEM_P
|
||||||
#define FRAMESVGITEM_P
|
#define FRAMESVGITEM_P
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
#include <Plasma/FrameSvg>
|
#include <Plasma/FrameSvg>
|
||||||
|
|
||||||
@ -75,7 +77,7 @@ private:
|
|||||||
bool m_fixed;
|
bool m_fixed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FrameSvgItem : public QQuickPaintedItem
|
class FrameSvgItem : public QQuickItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -141,8 +143,6 @@ public:
|
|||||||
FrameSvgItemMargins *margins() const;
|
FrameSvgItemMargins *margins() const;
|
||||||
FrameSvgItemMargins *fixedMargins() const;
|
FrameSvgItemMargins *fixedMargins() const;
|
||||||
|
|
||||||
void paint(QPainter *painter);
|
|
||||||
|
|
||||||
void geometryChanged(const QRectF &newGeometry,
|
void geometryChanged(const QRectF &newGeometry,
|
||||||
const QRectF &oldGeometry);
|
const QRectF &oldGeometry);
|
||||||
|
|
||||||
@ -164,6 +164,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE bool hasElementPrefix(const QString & prefix) const;
|
Q_INVOKABLE bool hasElementPrefix(const QString & prefix) const;
|
||||||
|
|
||||||
|
virtual QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void componentComplete();
|
virtual void componentComplete();
|
||||||
|
|
||||||
@ -184,6 +186,7 @@ private:
|
|||||||
FrameSvgItemMargins *m_fixedMargins;
|
FrameSvgItemMargins *m_fixedMargins;
|
||||||
QString m_prefix;
|
QString m_prefix;
|
||||||
Units m_units;
|
Units m_units;
|
||||||
|
bool m_textureChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,29 +24,16 @@
|
|||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QSGTexture>
|
#include <QSGTexture>
|
||||||
#include <QSGSimpleTextureNode>
|
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "QDebug"
|
|
||||||
#include "plasma/svg.h"
|
#include "plasma/svg.h"
|
||||||
|
|
||||||
|
#include "svgtexturenode.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class SVGTextureNode : public QSGSimpleTextureNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SVGTextureNode() {}
|
|
||||||
void setTexture(QSGTexture *texture);
|
|
||||||
private:
|
|
||||||
QScopedPointer<QSGTexture> m_texture;
|
|
||||||
};
|
|
||||||
|
|
||||||
void SVGTextureNode::setTexture(QSGTexture *texture) {
|
|
||||||
m_texture.reset(texture);
|
|
||||||
QSGSimpleTextureNode::setTexture(texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
SvgItem::SvgItem(QQuickItem *parent)
|
SvgItem::SvgItem(QQuickItem *parent)
|
||||||
: QQuickItem(parent),
|
: QQuickItem(parent),
|
||||||
m_smooth(false),
|
m_smooth(false),
|
||||||
|
30
src/declarativeimports/core/svgtexturenode.h
Normal file
30
src/declarativeimports/core/svgtexturenode.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef SVGTEXTURENODE_H
|
||||||
|
#define SVGTEXTURENODE_H
|
||||||
|
|
||||||
|
#include <QSGSimpleTextureNode>
|
||||||
|
|
||||||
|
namespace Plasma {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class wraps QSGSimpleTextureNode
|
||||||
|
* and manages the lifespan on the texture
|
||||||
|
*/
|
||||||
|
|
||||||
|
class SVGTextureNode : public QSGSimpleTextureNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SVGTextureNode() {}
|
||||||
|
/**
|
||||||
|
* Set the current texture
|
||||||
|
* the object takes ownership of the texture
|
||||||
|
*/
|
||||||
|
void setTexture(QSGTexture *texture) {
|
||||||
|
m_texture.reset(texture);
|
||||||
|
QSGSimpleTextureNode::setTexture(texture);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
QScopedPointer<QSGTexture> m_texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // SVGTextureNode
|
Loading…
Reference in New Issue
Block a user