2010-10-12 19:51:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Marco Martin <mart@kde.org>
|
2014-03-05 12:14:40 +01:00
|
|
|
* Copyright 2014 David Edmundson <davidedmundson@kde.org>
|
2010-10-12 19:51:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-11-01 19:27:55 +01:00
|
|
|
#include "framesvgitem.h"
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2014-03-05 12:14:40 +01:00
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QSGTexture>
|
|
|
|
#include <QDebug>
|
2010-11-05 20:50:28 +00:00
|
|
|
|
2014-07-14 20:02:47 +02:00
|
|
|
#include <plasma/private/framesvg_p.h>
|
|
|
|
|
2014-03-05 12:14:40 +01:00
|
|
|
#include "svgtexturenode.h"
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2014-05-11 20:58:53 -04:00
|
|
|
#include <cmath> //floor()
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2014-07-14 20:02:47 +02:00
|
|
|
class FrameItemNode : public SVGTextureNode
|
|
|
|
{
|
|
|
|
public:
|
2014-07-15 16:28:41 +02:00
|
|
|
FrameItemNode(FrameSvgItem* frameSvg, FrameSvg::EnabledBorders borders, QSGNode* parent)
|
2014-07-14 20:02:47 +02:00
|
|
|
: SVGTextureNode()
|
|
|
|
, m_frameSvg(frameSvg)
|
|
|
|
, m_border(borders)
|
2014-07-15 16:28:41 +02:00
|
|
|
, m_lastParent(parent)
|
2014-07-14 20:02:47 +02:00
|
|
|
{
|
2014-07-15 16:28:41 +02:00
|
|
|
m_lastParent->appendChildNode(this);
|
|
|
|
fetchPrefix();
|
2014-07-14 20:02:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 16:28:41 +02:00
|
|
|
void fetchPrefix()
|
2014-07-14 20:02:47 +02:00
|
|
|
{
|
2014-07-15 19:54:45 +02:00
|
|
|
QString elementId = m_frameSvg->actualPrefix() + FrameSvgPrivate::borderToElementId(m_border);
|
2014-07-15 16:28:41 +02:00
|
|
|
|
2014-07-14 20:02:47 +02:00
|
|
|
QSize someSize = m_frameSvg->frameSvg()->elementSize(elementId);
|
|
|
|
|
|
|
|
QImage image = m_frameSvg->frameSvg()->image(someSize, elementId);
|
2014-07-15 16:28:41 +02:00
|
|
|
setVisible(!image.isNull());
|
|
|
|
if(!image.isNull()) {
|
|
|
|
QSGTexture* texture = m_frameSvg->window()->createTextureFromImage(image);
|
|
|
|
setTexture(texture);
|
|
|
|
} else {
|
|
|
|
qDebug() << "not painting " << elementId;
|
|
|
|
}
|
2014-07-14 20:02:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 16:28:41 +02:00
|
|
|
void reposition(const QRect& geometry)
|
|
|
|
{
|
2014-07-14 20:02:47 +02:00
|
|
|
FrameData* frameData = m_frameSvg->frameData();
|
2014-07-15 16:28:41 +02:00
|
|
|
if (!frameData)
|
|
|
|
return;
|
2014-07-14 20:02:47 +02:00
|
|
|
|
2014-07-15 16:28:41 +02:00
|
|
|
setRect(FrameSvgPrivate::sectionRect(frameData, m_border, geometry));
|
|
|
|
}
|
|
|
|
|
|
|
|
void setVisible(bool visible)
|
|
|
|
{
|
|
|
|
if (visible == bool(parent()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (visible) {
|
|
|
|
m_lastParent->appendChildNode(this);
|
|
|
|
} else {
|
|
|
|
m_lastParent->removeChildNode(this);
|
|
|
|
}
|
2014-07-14 20:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FrameSvgItem* m_frameSvg;
|
|
|
|
FrameSvg::EnabledBorders m_border;
|
2014-07-15 16:28:41 +02:00
|
|
|
QSGNode *m_lastParent;
|
2014-07-14 20:02:47 +02:00
|
|
|
};
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
|
|
|
|
FrameSvgItemMargins::FrameSvgItemMargins(Plasma::FrameSvg *frameSvg, QObject *parent)
|
|
|
|
: QObject(parent),
|
2014-02-21 21:13:12 +01:00
|
|
|
m_frameSvg(frameSvg),
|
|
|
|
m_fixed(false)
|
2010-10-12 19:51:57 +00:00
|
|
|
{
|
2013-07-29 19:05:59 +02:00
|
|
|
//qDebug() << "margins at: " << left() << top() << right() << bottom();
|
2012-11-07 12:43:11 +01:00
|
|
|
connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::left() const
|
|
|
|
{
|
2014-02-21 21:13:12 +01:00
|
|
|
if (m_fixed) {
|
|
|
|
return m_frameSvg->fixedMarginSize(Types::LeftMargin);
|
|
|
|
} else {
|
|
|
|
return m_frameSvg->marginSize(Types::LeftMargin);
|
|
|
|
}
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::top() const
|
|
|
|
{
|
2014-02-21 21:13:12 +01:00
|
|
|
if (m_fixed) {
|
|
|
|
return m_frameSvg->fixedMarginSize(Types::TopMargin);
|
|
|
|
} else {
|
|
|
|
return m_frameSvg->marginSize(Types::TopMargin);
|
|
|
|
}
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::right() const
|
|
|
|
{
|
2014-02-21 21:13:12 +01:00
|
|
|
if (m_fixed) {
|
|
|
|
return m_frameSvg->fixedMarginSize(Types::RightMargin);
|
|
|
|
} else {
|
|
|
|
return m_frameSvg->marginSize(Types::RightMargin);
|
|
|
|
}
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::bottom() const
|
|
|
|
{
|
2014-02-21 21:13:12 +01:00
|
|
|
if (m_fixed) {
|
|
|
|
return m_frameSvg->fixedMarginSize(Types::BottomMargin);
|
|
|
|
} else {
|
|
|
|
return m_frameSvg->marginSize(Types::BottomMargin);
|
|
|
|
}
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 12:43:11 +01:00
|
|
|
void FrameSvgItemMargins::update()
|
|
|
|
{
|
|
|
|
emit marginsChanged();
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:13:12 +01:00
|
|
|
void FrameSvgItemMargins::setFixed(bool fixed)
|
|
|
|
{
|
|
|
|
if (fixed == m_fixed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fixed = fixed;
|
|
|
|
emit marginsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameSvgItemMargins::isFixed() const
|
|
|
|
{
|
|
|
|
return m_fixed;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
FrameSvgItem::FrameSvgItem(QQuickItem *parent)
|
2014-03-05 12:14:40 +01:00
|
|
|
: QQuickItem(parent),
|
2014-07-15 16:28:41 +02:00
|
|
|
m_textureChanged(false),
|
2014-07-16 17:01:05 +02:00
|
|
|
m_sizeChanged(false),
|
|
|
|
m_fastPath(true)
|
2010-10-12 19:51:57 +00:00
|
|
|
{
|
|
|
|
m_frameSvg = new Plasma::FrameSvg(this);
|
|
|
|
m_margins = new FrameSvgItemMargins(m_frameSvg, this);
|
2014-02-21 21:13:12 +01:00
|
|
|
m_fixedMargins = new FrameSvgItemMargins(m_frameSvg, this);
|
|
|
|
m_fixedMargins->setFixed(true);
|
2013-02-02 00:54:25 +01:00
|
|
|
setFlag(ItemHasContents, true);
|
2010-10-12 19:51:57 +00:00
|
|
|
connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate()));
|
2014-02-24 16:55:19 +01:00
|
|
|
connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio);
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameSvgItem::~FrameSvgItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::setImagePath(const QString &path)
|
|
|
|
{
|
2012-11-07 12:43:11 +01:00
|
|
|
if (m_frameSvg->imagePath() == path) {
|
2012-08-11 19:13:21 -03:00
|
|
|
return;
|
2012-11-07 12:43:11 +01:00
|
|
|
}
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
m_frameSvg->setImagePath(path);
|
2011-03-27 12:37:23 +02:00
|
|
|
m_frameSvg->setElementPrefix(m_prefix);
|
2014-01-28 15:15:55 +01:00
|
|
|
updateDevicePixelRatio();
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2012-11-27 13:33:50 +01:00
|
|
|
if (implicitWidth() <= 0) {
|
2013-05-10 19:29:13 +02:00
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (implicitHeight() <= 0) {
|
2013-05-10 19:29:13 +02:00
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
2012-08-11 19:13:21 -03:00
|
|
|
emit imagePathChanged();
|
2013-01-23 15:05:27 +01:00
|
|
|
m_margins->update();
|
2013-02-13 17:47:03 +01:00
|
|
|
|
2014-02-13 12:45:21 +01:00
|
|
|
if (isComponentComplete()) {
|
|
|
|
m_frameSvg->resizeFrame(QSizeF(width(), height()));
|
2014-03-05 12:14:40 +01:00
|
|
|
m_textureChanged = true;
|
2014-02-13 12:45:21 +01:00
|
|
|
update();
|
|
|
|
}
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString FrameSvgItem::imagePath() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->imagePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::setPrefix(const QString &prefix)
|
|
|
|
{
|
2012-11-07 12:43:11 +01:00
|
|
|
if (m_prefix == prefix) {
|
2012-08-11 19:13:21 -03:00
|
|
|
return;
|
2012-11-07 12:43:11 +01:00
|
|
|
}
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
m_frameSvg->setElementPrefix(prefix);
|
2011-03-27 12:37:23 +02:00
|
|
|
m_prefix = prefix;
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2012-11-27 13:33:50 +01:00
|
|
|
if (implicitWidth() <= 0) {
|
2013-05-10 19:29:13 +02:00
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (implicitHeight() <= 0) {
|
2013-05-10 19:29:13 +02:00
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
2012-08-11 19:13:21 -03:00
|
|
|
emit prefixChanged();
|
2012-11-07 12:43:11 +01:00
|
|
|
m_margins->update();
|
2014-02-13 12:45:21 +01:00
|
|
|
|
|
|
|
if (isComponentComplete()) {
|
|
|
|
m_frameSvg->resizeFrame(QSizeF(width(), height()));
|
2014-03-05 12:14:40 +01:00
|
|
|
m_textureChanged = true;
|
2014-02-13 12:45:21 +01:00
|
|
|
update();
|
|
|
|
}
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString FrameSvgItem::prefix() const
|
|
|
|
{
|
2011-03-27 12:37:23 +02:00
|
|
|
return m_prefix;
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameSvgItemMargins *FrameSvgItem::margins() const
|
|
|
|
{
|
|
|
|
return m_margins;
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:13:12 +01:00
|
|
|
FrameSvgItemMargins *FrameSvgItem::fixedMargins() const
|
|
|
|
{
|
|
|
|
return m_fixedMargins;
|
|
|
|
}
|
|
|
|
|
2010-11-05 20:50:28 +00:00
|
|
|
void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders)
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
if (m_frameSvg->enabledBorders() == borders) {
|
2012-08-11 19:13:21 -03:00
|
|
|
return;
|
2014-04-26 01:45:47 +02:00
|
|
|
}
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2010-11-05 20:50:28 +00:00
|
|
|
m_frameSvg->setEnabledBorders(borders);
|
2012-08-11 19:13:21 -03:00
|
|
|
emit enabledBordersChanged();
|
2014-03-05 12:14:40 +01:00
|
|
|
m_textureChanged = true;
|
2013-02-13 17:47:03 +01:00
|
|
|
update();
|
2010-11-05 20:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::FrameSvg::EnabledBorders FrameSvgItem::enabledBorders() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->enabledBorders();
|
|
|
|
}
|
|
|
|
|
2014-03-04 18:13:46 +01:00
|
|
|
bool FrameSvgItem::hasElementPrefix(const QString &prefix) const
|
|
|
|
{
|
|
|
|
return m_frameSvg->hasElementPrefix(prefix);
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
|
2014-04-26 01:45:47 +02:00
|
|
|
const QRectF &oldGeometry)
|
2010-10-12 19:51:57 +00:00
|
|
|
{
|
2014-02-13 12:45:21 +01:00
|
|
|
if (isComponentComplete()) {
|
|
|
|
m_frameSvg->resizeFrame(newGeometry.size());
|
2014-07-15 16:28:41 +02:00
|
|
|
m_sizeChanged = true;
|
2014-02-13 12:45:21 +01:00
|
|
|
}
|
2013-02-01 17:26:26 +01:00
|
|
|
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
2010-10-12 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::doUpdate()
|
|
|
|
{
|
2012-11-27 13:33:50 +01:00
|
|
|
if (implicitWidth() <= 0) {
|
2013-05-10 19:29:13 +02:00
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (implicitHeight() <= 0) {
|
2013-05-10 19:29:13 +02:00
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
2014-07-16 17:01:05 +02:00
|
|
|
bool hasOverlay = !actualPrefix().startsWith(QLatin1String("mask-")) && m_frameSvg->hasElement(actualPrefix() % "overlay");
|
|
|
|
m_fastPath = !hasOverlay;
|
2014-07-16 13:51:53 +02:00
|
|
|
m_textureChanged = true;
|
2010-10-12 19:51:57 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2012-11-27 13:33:50 +01:00
|
|
|
void FrameSvgItem::setImplicitWidth(qreal width)
|
|
|
|
{
|
|
|
|
if (implicitWidth() == width) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
QQuickItem::setImplicitWidth(width);
|
2012-11-27 13:33:50 +01:00
|
|
|
|
|
|
|
emit implicitWidthChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItem::implicitWidth() const
|
|
|
|
{
|
2013-02-01 17:26:26 +01:00
|
|
|
return QQuickItem::implicitWidth();
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgItem::setImplicitHeight(qreal height)
|
|
|
|
{
|
|
|
|
if (implicitHeight() == height) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
QQuickItem::setImplicitHeight(height);
|
2012-11-27 13:33:50 +01:00
|
|
|
|
|
|
|
emit implicitHeightChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItem::implicitHeight() const
|
|
|
|
{
|
2013-02-01 17:26:26 +01:00
|
|
|
return QQuickItem::implicitHeight();
|
2012-11-27 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
2013-02-21 14:58:09 +01:00
|
|
|
Plasma::FrameSvg *FrameSvgItem::frameSvg() const
|
|
|
|
{
|
|
|
|
return m_frameSvg;
|
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
|
2014-03-05 12:14:40 +01:00
|
|
|
{
|
|
|
|
if (!window() || !m_frameSvg || !m_frameSvg->hasElementPrefix(m_prefix)) {
|
|
|
|
delete oldNode;
|
|
|
|
return Q_NULLPTR;
|
|
|
|
}
|
|
|
|
|
2014-07-16 17:01:05 +02:00
|
|
|
if (m_fastPath) {
|
|
|
|
if (m_textureChanged) {
|
|
|
|
delete oldNode;
|
|
|
|
oldNode = 0;
|
|
|
|
}
|
2014-03-05 12:14:40 +01:00
|
|
|
|
2014-07-16 17:01:05 +02:00
|
|
|
if (!oldNode) {
|
|
|
|
oldNode = new QSGNode;
|
|
|
|
|
|
|
|
new FrameItemNode(this, FrameSvg::NoBorder, oldNode); //needs to be de first, in case of composeOverBorder
|
|
|
|
new FrameItemNode(this, FrameSvg::TopBorder | FrameSvg::LeftBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::TopBorder | FrameSvg::RightBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::TopBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::BottomBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::BottomBorder | FrameSvg::LeftBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::BottomBorder | FrameSvg::RightBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::LeftBorder, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::RightBorder, oldNode);
|
|
|
|
|
|
|
|
m_sizeChanged = true;
|
|
|
|
m_textureChanged = false;
|
|
|
|
}
|
2014-07-15 16:28:41 +02:00
|
|
|
|
2014-07-16 17:01:05 +02:00
|
|
|
FrameData* frame = frameData();
|
|
|
|
if (frame && m_sizeChanged)
|
|
|
|
{
|
|
|
|
QRect geometry = m_frameSvg->d->contentGeometry(frame, QSize(width(), height()));
|
|
|
|
for(int i = 0; i<oldNode->childCount(); ++i) {
|
|
|
|
FrameItemNode* it = static_cast<FrameItemNode*>(oldNode->childAtIndex(i));
|
|
|
|
it->reposition(geometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sizeChanged = false;
|
|
|
|
} else if(!frame) {
|
|
|
|
qWarning() << "no frame for" << imagePath() << prefix();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SVGTextureNode *textureNode = dynamic_cast<SVGTextureNode *>(oldNode);
|
|
|
|
if (!textureNode) {
|
|
|
|
delete oldNode;
|
|
|
|
textureNode = new SVGTextureNode;
|
|
|
|
textureNode->setFiltering(QSGTexture::Nearest);
|
|
|
|
m_textureChanged = true; //force updating the texture on our newly created node
|
|
|
|
oldNode = textureNode;
|
|
|
|
}
|
2014-07-15 16:28:41 +02:00
|
|
|
|
2014-07-16 17:01:05 +02:00
|
|
|
if ((m_textureChanged || m_sizeChanged) || textureNode->texture()->textureSize() != m_frameSvg->size()) {
|
|
|
|
QImage image = m_frameSvg->framePixmap().toImage();
|
|
|
|
QSGTexture *texture = window()->createTextureFromImage(image);
|
|
|
|
texture->setFiltering(QSGTexture::Nearest);
|
|
|
|
textureNode->setTexture(texture);
|
|
|
|
textureNode->setRect(0, 0, width(), height());
|
2014-07-14 18:44:33 +02:00
|
|
|
|
2014-07-16 17:01:05 +02:00
|
|
|
m_textureChanged = false;
|
|
|
|
m_sizeChanged = false;
|
2014-07-14 20:02:47 +02:00
|
|
|
}
|
2014-03-05 12:14:40 +01:00
|
|
|
}
|
|
|
|
|
2014-07-14 18:44:33 +02:00
|
|
|
return oldNode;
|
2014-03-05 12:14:40 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 12:45:21 +01:00
|
|
|
void FrameSvgItem::componentComplete()
|
|
|
|
{
|
|
|
|
QQuickItem::componentComplete();
|
|
|
|
m_frameSvg->resizeFrame(QSize(width(), height()));
|
2014-03-05 12:14:40 +01:00
|
|
|
m_textureChanged = true;
|
2014-02-13 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 15:15:55 +01:00
|
|
|
void FrameSvgItem::updateDevicePixelRatio()
|
|
|
|
{
|
2014-02-25 19:39:12 +01:00
|
|
|
//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)
|
2014-06-03 14:15:12 +02:00
|
|
|
m_frameSvg->setDevicePixelRatio(qMax<qreal>(1.0, floor(m_units.devicePixelRatio())));
|
2014-03-05 12:14:40 +01:00
|
|
|
m_textureChanged = true;
|
2014-01-28 15:15:55 +01:00
|
|
|
}
|
|
|
|
|
2014-07-14 20:02:47 +02:00
|
|
|
FrameData* FrameSvgItem::frameData() const
|
|
|
|
{
|
2014-07-15 19:54:45 +02:00
|
|
|
//We need to do that prefix, otherwise we are fetching the requested prefix, which might be different
|
|
|
|
return m_frameSvg->d->frames.value(actualPrefix());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FrameSvgItem::actualPrefix() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->d->prefix;
|
2014-07-14 20:02:47 +02:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2011-11-01 19:27:55 +01:00
|
|
|
#include "framesvgitem.moc"
|