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>
|
2014-07-16 17:36:59 +02:00
|
|
|
#include <QSGGeometry>
|
|
|
|
|
2014-03-05 12:14:40 +01:00
|
|
|
#include <QDebug>
|
2014-07-17 22:29:54 +02:00
|
|
|
#include <QPainter>
|
2010-11-05 20:50:28 +00:00
|
|
|
|
2014-07-14 20:02:47 +02:00
|
|
|
#include <plasma/private/framesvg_p.h>
|
2014-07-21 18:01:26 +02:00
|
|
|
#include <plasma/private/framesvg_helpers.h>
|
2014-07-14 20:02:47 +02:00
|
|
|
|
2014-10-15 13:22:27 +02:00
|
|
|
#include <QuickAddons/ManagedTextureNode>
|
|
|
|
#include <QuickAddons/ImageTexturesCache>
|
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-16 17:36:59 +02:00
|
|
|
|
2014-10-15 13:22:27 +02:00
|
|
|
Q_GLOBAL_STATIC(ImageTexturesCache, s_cache)
|
2014-07-25 12:41:53 +02:00
|
|
|
|
2014-07-22 03:14:26 +02:00
|
|
|
class FrameNode : public QSGNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FrameNode(const QString& prefix, FrameSvg* svg)
|
|
|
|
: QSGNode()
|
|
|
|
, leftWidth(0)
|
|
|
|
, rightWidth(0)
|
|
|
|
, topHeight(0)
|
|
|
|
, bottomHeight(0)
|
|
|
|
{
|
|
|
|
if (svg->enabledBorders() & FrameSvg::LeftBorder)
|
2015-11-27 20:03:48 +00:00
|
|
|
leftWidth = svg->elementSize(prefix % QLatin1String("left")).width();
|
2014-07-22 03:14:26 +02:00
|
|
|
if (svg->enabledBorders() & FrameSvg::RightBorder)
|
2015-11-27 20:03:48 +00:00
|
|
|
rightWidth = svg->elementSize(prefix % QLatin1String("right")).width();
|
2014-07-22 03:14:26 +02:00
|
|
|
if (svg->enabledBorders() & FrameSvg::TopBorder)
|
2015-11-27 20:03:48 +00:00
|
|
|
topHeight = svg->elementSize(prefix % QLatin1String("top")).height();
|
2014-07-22 03:14:26 +02:00
|
|
|
if (svg->enabledBorders() & FrameSvg::BottomBorder)
|
2015-11-27 20:03:48 +00:00
|
|
|
bottomHeight = svg->elementSize(prefix % QLatin1String("bottom")).height();
|
2014-07-22 03:14:26 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 16:24:32 +02:00
|
|
|
QRect contentsRect(const QSize& size) const
|
2014-07-22 03:14:26 +02:00
|
|
|
{
|
|
|
|
const QSize contentSize(size.width() - leftWidth - rightWidth, size.height() - topHeight - bottomHeight);
|
|
|
|
|
|
|
|
return QRect(QPoint(leftWidth, topHeight), contentSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int leftWidth;
|
|
|
|
int rightWidth;
|
|
|
|
int topHeight;
|
|
|
|
int bottomHeight;
|
|
|
|
};
|
|
|
|
|
2014-10-15 13:22:27 +02:00
|
|
|
class FrameItemNode : public ManagedTextureNode
|
2014-07-14 20:02:47 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-07-16 17:36:59 +02:00
|
|
|
enum FitMode {
|
2014-07-16 22:51:29 +02:00
|
|
|
//render SVG at native resolution then stretch it in openGL
|
|
|
|
FastStretch,
|
|
|
|
//on resize re-render the part of the frame from the SVG
|
2014-07-16 17:36:59 +02:00
|
|
|
Stretch,
|
|
|
|
Tile
|
|
|
|
};
|
|
|
|
|
|
|
|
FrameItemNode(FrameSvgItem* frameSvg, FrameSvg::EnabledBorders borders, FitMode fitMode, QSGNode* parent)
|
2014-10-15 13:22:27 +02:00
|
|
|
: ManagedTextureNode()
|
2014-07-14 20:02:47 +02:00
|
|
|
, m_frameSvg(frameSvg)
|
|
|
|
, m_border(borders)
|
2014-07-15 16:28:41 +02:00
|
|
|
, m_lastParent(parent)
|
2014-07-16 17:36:59 +02:00
|
|
|
, m_fitMode(fitMode)
|
2014-07-14 20:02:47 +02:00
|
|
|
{
|
2014-07-15 16:28:41 +02:00
|
|
|
m_lastParent->appendChildNode(this);
|
2014-07-16 22:22:43 +02:00
|
|
|
|
2014-07-16 17:36:59 +02:00
|
|
|
if (m_fitMode == Tile) {
|
|
|
|
if (m_border == FrameSvg::TopBorder || m_border == FrameSvg::BottomBorder || m_border == FrameSvg::NoBorder) {
|
|
|
|
static_cast<QSGTextureMaterial*>(material())->setHorizontalWrapMode(QSGTexture::Repeat);
|
|
|
|
static_cast<QSGOpaqueTextureMaterial*>(opaqueMaterial())->setHorizontalWrapMode(QSGTexture::Repeat);
|
|
|
|
}
|
|
|
|
if (m_border == FrameSvg::LeftBorder || m_border == FrameSvg::RightBorder || m_border == FrameSvg::NoBorder) {
|
|
|
|
static_cast<QSGTextureMaterial*>(material())->setVerticalWrapMode(QSGTexture::Repeat);
|
|
|
|
static_cast<QSGOpaqueTextureMaterial*>(opaqueMaterial())->setVerticalWrapMode(QSGTexture::Repeat);
|
|
|
|
}
|
|
|
|
}
|
2014-07-16 22:51:29 +02:00
|
|
|
|
|
|
|
if (m_fitMode == Tile || m_fitMode == FastStretch) {
|
2014-07-21 18:01:26 +02:00
|
|
|
QString elementId = m_frameSvg->frameSvg()->actualPrefix() + FrameSvgHelpers::borderToElementId(m_border);
|
2014-07-16 22:51:29 +02:00
|
|
|
m_elementNativeSize = m_frameSvg->frameSvg()->elementSize(elementId);
|
|
|
|
|
2014-07-22 13:35:35 +02:00
|
|
|
if (m_elementNativeSize.isEmpty()) {
|
|
|
|
//if the default element is empty, we can avoid the slower tiling path
|
|
|
|
//this also avoids a divide by 0 error
|
|
|
|
m_fitMode = FastStretch;
|
|
|
|
}
|
|
|
|
|
2014-07-22 16:24:32 +02:00
|
|
|
updateTexture(m_elementNativeSize, elementId);
|
2014-07-16 22:51:29 +02:00
|
|
|
}
|
2014-07-14 20:02:47 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 16:24:32 +02:00
|
|
|
void updateTexture(const QSize &size, const QString &elementId)
|
2014-07-16 20:40:12 +02:00
|
|
|
{
|
2015-02-11 23:21:35 +01:00
|
|
|
QQuickWindow::CreateTextureOptions options;
|
2015-02-16 16:46:16 +01:00
|
|
|
//Qt < 5.3.2. has a crash on some atlas textures
|
|
|
|
#if (QT_VERSION > QT_VERSION_CHECK(5, 3, 2))
|
2015-02-11 23:21:35 +01:00
|
|
|
if (m_fitMode != Tile) {
|
|
|
|
options = QQuickWindow::TextureCanUseAtlas;
|
|
|
|
}
|
2015-02-16 16:46:16 +01:00
|
|
|
#endif
|
2015-02-11 23:21:35 +01:00
|
|
|
setTexture(s_cache->loadTexture(m_frameSvg->window(), m_frameSvg->frameSvg()->image(size, elementId), options));
|
2014-07-16 20:40:12 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 15:44:25 +02:00
|
|
|
void reposition(const QRect& frameGeometry, QSize& fullSize)
|
2014-07-15 16:28:41 +02:00
|
|
|
{
|
2014-07-21 18:01:26 +02:00
|
|
|
QRect nodeRect = FrameSvgHelpers::sectionRect(m_border, frameGeometry, fullSize);
|
2014-07-18 12:44:06 +02:00
|
|
|
|
|
|
|
//ensure we're not passing a weird rectangle to updateTexturedRectGeometry
|
|
|
|
if(!nodeRect.isValid() || nodeRect.isEmpty())
|
|
|
|
nodeRect = QRect();
|
|
|
|
|
2015-02-11 23:21:35 +01:00
|
|
|
//the position of the relevant texture within this texture ID.
|
|
|
|
//for atlas' this will only be a small part of the texture
|
|
|
|
QRectF textureRect;
|
|
|
|
|
2014-07-16 17:36:59 +02:00
|
|
|
if (m_fitMode == Tile) {
|
2015-02-11 23:21:35 +01:00
|
|
|
textureRect = QRectF(0,0,1,1); //we can never be in an atlas for tiled images.
|
|
|
|
|
|
|
|
//if tiling horizontally
|
2014-07-16 17:36:59 +02:00
|
|
|
if (m_border == FrameSvg::TopBorder || m_border == FrameSvg::BottomBorder || m_border == FrameSvg::NoBorder) {
|
2014-07-16 20:40:12 +02:00
|
|
|
textureRect.setWidth(nodeRect.width() / m_elementNativeSize.width());
|
2014-07-16 17:36:59 +02:00
|
|
|
}
|
2015-02-11 23:21:35 +01:00
|
|
|
//if tiling vertically
|
2014-07-16 17:36:59 +02:00
|
|
|
if (m_border == FrameSvg::LeftBorder || m_border == FrameSvg::RightBorder || m_border == FrameSvg::NoBorder) {
|
2014-07-16 20:40:12 +02:00
|
|
|
textureRect.setHeight(nodeRect.height() / m_elementNativeSize.height());
|
2014-07-16 17:36:59 +02:00
|
|
|
}
|
2014-07-16 22:51:29 +02:00
|
|
|
} else if (m_fitMode == Stretch) {
|
2014-07-21 15:44:25 +02:00
|
|
|
QString prefix = m_frameSvg->frameSvg()->actualPrefix();
|
|
|
|
|
2014-07-21 18:01:26 +02:00
|
|
|
QString elementId = prefix + FrameSvgHelpers::borderToElementId(m_border);
|
2014-07-21 15:44:25 +02:00
|
|
|
|
2014-07-16 22:51:29 +02:00
|
|
|
//re-render the SVG at new size
|
2014-07-22 16:24:32 +02:00
|
|
|
updateTexture(nodeRect.size(), elementId);
|
2015-02-11 23:21:35 +01:00
|
|
|
textureRect = texture()->normalizedTextureSubRect();
|
|
|
|
} else if (texture()) { // for fast stretch.
|
|
|
|
textureRect = texture()->normalizedTextureSubRect();
|
|
|
|
}
|
2014-07-16 20:40:12 +02:00
|
|
|
|
|
|
|
QSGGeometry::updateTexturedRectGeometry(geometry(), nodeRect, textureRect);
|
|
|
|
markDirty(QSGNode::DirtyGeometry);
|
|
|
|
}
|
|
|
|
|
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-16 20:40:12 +02:00
|
|
|
QSize m_elementNativeSize;
|
2014-07-16 17:36:59 +02:00
|
|
|
FitMode m_fitMode;
|
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
|
|
|
}
|
|
|
|
|
2014-10-13 15:14:56 +02:00
|
|
|
qreal FrameSvgItemMargins::horizontal() const
|
|
|
|
{
|
|
|
|
return left() + right();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvgItemMargins::vertical() const
|
|
|
|
{
|
|
|
|
return top() + bottom();
|
|
|
|
}
|
|
|
|
|
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);
|
2014-10-10 17:36:44 +02:00
|
|
|
connect(m_frameSvg, &Svg::fromCurrentThemeChanged, this, &FrameSvgItem::fromCurrentThemeChanged);
|
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
|
|
|
|
2015-03-25 12:07:41 +01:00
|
|
|
updateDevicePixelRatio();
|
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);
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2014-09-17 20:21:34 +02:00
|
|
|
if (implicitWidth() <= 0) {
|
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
|
|
|
}
|
2012-11-27 13:33:50 +01:00
|
|
|
|
2014-09-17 20:21:34 +02:00
|
|
|
if (implicitHeight() <= 0) {
|
|
|
|
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();
|
2015-03-30 13:42:40 +02:00
|
|
|
m_fixedMargins->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
|
|
|
|
2014-09-17 20:21:34 +02:00
|
|
|
if (implicitWidth() <= 0) {
|
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
|
|
|
}
|
2012-11-27 13:33:50 +01:00
|
|
|
|
2014-09-17 20:21:34 +02:00
|
|
|
if (implicitHeight() <= 0) {
|
|
|
|
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();
|
2015-03-30 13:42:40 +02:00
|
|
|
m_fixedMargins->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;
|
|
|
|
}
|
|
|
|
|
2015-03-19 11:20:01 +01:00
|
|
|
void FrameSvgItem::setColorGroup(Plasma::Theme::ColorGroup group)
|
|
|
|
{
|
|
|
|
if (m_frameSvg->colorGroup() == group) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frameSvg->setColorGroup(group);
|
|
|
|
|
|
|
|
emit colorGroupChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Theme::ColorGroup FrameSvgItem::colorGroup() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->colorGroup();
|
|
|
|
}
|
|
|
|
|
2014-10-10 17:36:44 +02:00
|
|
|
bool FrameSvgItem::fromCurrentTheme() const
|
|
|
|
{
|
|
|
|
return m_frameSvg->fromCurrentTheme();
|
|
|
|
}
|
|
|
|
|
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;
|
2015-03-30 13:42:40 +02:00
|
|
|
m_margins->update();
|
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()
|
|
|
|
{
|
2014-09-17 20:21:34 +02:00
|
|
|
if (implicitWidth() <= 0) {
|
|
|
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
|
|
|
}
|
2012-11-27 13:33:50 +01:00
|
|
|
|
2014-09-17 20:21:34 +02:00
|
|
|
if (implicitHeight() <= 0) {
|
|
|
|
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
|
|
|
|
}
|
2012-11-27 13:33:50 +01:00
|
|
|
|
2014-07-21 15:44:25 +02:00
|
|
|
QString prefix = m_frameSvg->actualPrefix();
|
2015-11-27 20:03:48 +00:00
|
|
|
bool hasOverlay = !prefix.startsWith(QLatin1String("mask-")) && m_frameSvg->hasElement(prefix % QLatin1String("overlay"));
|
|
|
|
bool hasComposeOverBorder = m_frameSvg->hasElement(prefix % QLatin1String("hint-compose-over-border")) &&
|
|
|
|
m_frameSvg->hasElement(QLatin1String("mask-") % prefix % QLatin1String("center"));
|
2014-07-22 16:24:32 +02:00
|
|
|
m_fastPath = !hasOverlay && !hasComposeOverBorder;
|
2014-07-16 13:51:53 +02:00
|
|
|
m_textureChanged = true;
|
2014-07-25 12:42:31 +02:00
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
update();
|
2015-03-30 13:42:40 +02:00
|
|
|
m_margins->update();
|
|
|
|
m_fixedMargins->update();
|
|
|
|
emit repaintNeeded();
|
2010-10-12 19:51:57 +00: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
|
|
|
{
|
2014-10-13 14:13:58 +02:00
|
|
|
if (!window() || !m_frameSvg ||
|
|
|
|
(!m_frameSvg->hasElementPrefix(m_frameSvg->actualPrefix()) && !m_frameSvg->hasElementPrefix(m_prefix))) {
|
2014-03-05 12:14:40 +01:00
|
|
|
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) {
|
2014-07-21 15:44:25 +02:00
|
|
|
QString prefix = m_frameSvg->actualPrefix();
|
2014-07-22 03:14:26 +02:00
|
|
|
oldNode = new FrameNode(prefix, m_frameSvg);
|
|
|
|
|
2015-11-27 20:03:48 +00:00
|
|
|
bool tileCenter = (m_frameSvg->hasElement(QStringLiteral("hint-tile-center"))
|
|
|
|
|| m_frameSvg->hasElement(prefix % QLatin1String("hint-tile-center")));
|
|
|
|
bool stretchBorders = (m_frameSvg->hasElement(QStringLiteral("hint-stretch-borders"))
|
|
|
|
|| m_frameSvg->hasElement(prefix % QLatin1String("hint-stretch-borders")));
|
2014-07-21 15:44:25 +02:00
|
|
|
FrameItemNode::FitMode borderFitMode = stretchBorders ? FrameItemNode::Stretch : FrameItemNode::Tile;
|
|
|
|
FrameItemNode::FitMode centerFitMode = tileCenter ? FrameItemNode::Tile: FrameItemNode::Stretch;
|
2014-07-16 17:36:59 +02:00
|
|
|
|
2014-07-22 16:24:32 +02:00
|
|
|
new FrameItemNode(this, FrameSvg::NoBorder, centerFitMode, oldNode);
|
2014-07-16 22:51:29 +02:00
|
|
|
new FrameItemNode(this, FrameSvg::TopBorder | FrameSvg::LeftBorder, FrameItemNode::FastStretch, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::TopBorder | FrameSvg::RightBorder, FrameItemNode::FastStretch, oldNode);
|
2014-07-16 17:36:59 +02:00
|
|
|
new FrameItemNode(this, FrameSvg::TopBorder, borderFitMode, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::BottomBorder, borderFitMode, oldNode);
|
2014-07-16 22:51:29 +02:00
|
|
|
new FrameItemNode(this, FrameSvg::BottomBorder | FrameSvg::LeftBorder, FrameItemNode::FastStretch, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::BottomBorder | FrameSvg::RightBorder, FrameItemNode::FastStretch, oldNode);
|
2014-07-16 17:36:59 +02:00
|
|
|
new FrameItemNode(this, FrameSvg::LeftBorder, borderFitMode, oldNode);
|
|
|
|
new FrameItemNode(this, FrameSvg::RightBorder, borderFitMode, oldNode);
|
2014-07-16 17:01:05 +02:00
|
|
|
|
|
|
|
m_sizeChanged = true;
|
|
|
|
m_textureChanged = false;
|
|
|
|
}
|
2014-07-15 16:28:41 +02:00
|
|
|
|
2014-07-16 20:40:12 +02:00
|
|
|
if (m_sizeChanged) {
|
2014-07-22 03:14:26 +02:00
|
|
|
FrameNode* frameNode = static_cast<FrameNode*>(oldNode);
|
2014-07-21 15:44:25 +02:00
|
|
|
QSize frameSize(width(), height());
|
2014-07-22 03:14:26 +02:00
|
|
|
QRect geometry = frameNode->contentsRect(frameSize);
|
2014-07-16 17:01:05 +02:00
|
|
|
for(int i = 0; i<oldNode->childCount(); ++i) {
|
|
|
|
FrameItemNode* it = static_cast<FrameItemNode*>(oldNode->childAtIndex(i));
|
2014-07-21 15:44:25 +02:00
|
|
|
it->reposition(geometry, frameSize);
|
2014-07-16 17:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_sizeChanged = false;
|
|
|
|
}
|
|
|
|
} else {
|
2014-10-15 13:22:27 +02:00
|
|
|
ManagedTextureNode *textureNode = dynamic_cast<ManagedTextureNode *>(oldNode);
|
2014-07-16 17:01:05 +02:00
|
|
|
if (!textureNode) {
|
|
|
|
delete oldNode;
|
2014-10-15 13:22:27 +02:00
|
|
|
textureNode = new ManagedTextureNode;
|
2014-07-16 17:01:05 +02:00
|
|
|
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();
|
2014-10-15 13:22:27 +02:00
|
|
|
textureNode->setTexture(s_cache->loadTexture(window(), image));
|
2014-07-16 17:01:05 +02:00
|
|
|
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)
|
2015-03-10 18:02:15 +01:00
|
|
|
if (window()) {
|
|
|
|
m_frameSvg->setDevicePixelRatio(qMax<qreal>(1.0, floor(window()->devicePixelRatio())));
|
|
|
|
} else {
|
|
|
|
m_frameSvg->setDevicePixelRatio(qMax<qreal>(1.0, floor(qApp->devicePixelRatio())));
|
|
|
|
}
|
|
|
|
m_frameSvg->setScaleFactor(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
|
|
|
}
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
} // Plasma namespace
|
|
|
|
|