From 7a4998046e25c35261c11fbfc9b8b2de03e0c7c7 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 15 Oct 2014 13:22:27 +0200 Subject: [PATCH] Adopt QuickAddons in plasma-framework Removes the code that was moved to QuickAddons REVIEW: 120596 --- src/declarativeimports/core/CMakeLists.txt | 4 +- src/declarativeimports/core/framesvgitem.cpp | 36 ++++---------- src/declarativeimports/core/framesvgitem.h | 1 - src/declarativeimports/core/iconitem.cpp | 6 +-- src/declarativeimports/core/svgitem.cpp | 6 +-- src/declarativeimports/core/svgtexturenode.h | 51 -------------------- src/plasmaquick/CMakeLists.txt | 1 + 7 files changed, 19 insertions(+), 86 deletions(-) delete mode 100644 src/declarativeimports/core/svgtexturenode.h diff --git a/src/declarativeimports/core/CMakeLists.txt b/src/declarativeimports/core/CMakeLists.txt index 9aba91920..6016397f1 100644 --- a/src/declarativeimports/core/CMakeLists.txt +++ b/src/declarativeimports/core/CMakeLists.txt @@ -44,7 +44,9 @@ target_link_libraries(corebindingsplugin KF5::Service #for kplugininfo.h KF5::WindowSystem KF5::Plasma - KF5::PlasmaQuick) + KF5::PlasmaQuick + KF5::QuickAddons +) if(HAVE_X11) target_link_libraries(corebindingsplugin ${X11_LIBRARIES} ${XCB_XCB_LIBRARY} ) diff --git a/src/declarativeimports/core/framesvgitem.cpp b/src/declarativeimports/core/framesvgitem.cpp index bb4dc695b..459a0636a 100644 --- a/src/declarativeimports/core/framesvgitem.cpp +++ b/src/declarativeimports/core/framesvgitem.cpp @@ -30,33 +30,15 @@ #include #include -#include "svgtexturenode.h" +#include +#include #include //floor() namespace Plasma { -typedef QHash > > TexturesCache; -Q_GLOBAL_STATIC(TexturesCache, s_cache) - -QSharedPointer loadTexture(QQuickWindow *window, const QImage &image) -{ - qint64 id = image.cacheKey(); - QSharedPointer texture = s_cache->value(id).value(window).toStrongRef(); - if (!texture) { - auto cleanAndDelete = [window, id](QSGTexture* texture) { - QHash >& textures = (*s_cache)[id]; - textures.remove(window); - if (textures.isEmpty()) - s_cache->remove(id); - delete texture; - }; - texture = QSharedPointer(window->createTextureFromImage(image), cleanAndDelete); - (*s_cache)[id][window] = texture.toWeakRef(); - } - return texture; -} +Q_GLOBAL_STATIC(ImageTexturesCache, s_cache) class FrameNode : public QSGNode { @@ -92,7 +74,7 @@ private: int bottomHeight; }; -class FrameItemNode : public SVGTextureNode +class FrameItemNode : public ManagedTextureNode { public: enum FitMode { @@ -104,7 +86,7 @@ public: }; FrameItemNode(FrameSvgItem* frameSvg, FrameSvg::EnabledBorders borders, FitMode fitMode, QSGNode* parent) - : SVGTextureNode() + : ManagedTextureNode() , m_frameSvg(frameSvg) , m_border(borders) , m_lastParent(parent) @@ -139,7 +121,7 @@ public: void updateTexture(const QSize &size, const QString &elementId) { - setTexture(loadTexture(m_frameSvg->window(), m_frameSvg->frameSvg()->image(size, elementId))); + setTexture(s_cache->loadTexture(m_frameSvg->window(), m_frameSvg->frameSvg()->image(size, elementId))); } void reposition(const QRect& frameGeometry, QSize& fullSize) @@ -460,10 +442,10 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint m_sizeChanged = false; } } else { - SVGTextureNode *textureNode = dynamic_cast(oldNode); + ManagedTextureNode *textureNode = dynamic_cast(oldNode); if (!textureNode) { delete oldNode; - textureNode = new SVGTextureNode; + textureNode = new ManagedTextureNode; textureNode->setFiltering(QSGTexture::Nearest); m_textureChanged = true; //force updating the texture on our newly created node oldNode = textureNode; @@ -471,7 +453,7 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint if ((m_textureChanged || m_sizeChanged) || textureNode->texture()->textureSize() != m_frameSvg->size()) { QImage image = m_frameSvg->framePixmap().toImage(); - textureNode->setTexture(loadTexture(window(), image)); + textureNode->setTexture(s_cache->loadTexture(window(), image)); textureNode->setRect(0, 0, width(), height()); m_textureChanged = false; diff --git a/src/declarativeimports/core/framesvgitem.h b/src/declarativeimports/core/framesvgitem.h index 73494d444..8abe1b874 100644 --- a/src/declarativeimports/core/framesvgitem.h +++ b/src/declarativeimports/core/framesvgitem.h @@ -31,7 +31,6 @@ namespace Plasma { class FrameSvg; -class SVGTextureNode; /** * @class FrameSvgItemMargins diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 4f3d5d63f..10c0cdeee 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -33,7 +33,7 @@ #include #include "fadingnode_p.h" -#include "svgtexturenode.h" +#include #include "units.h" IconItem::IconItem(QQuickItem *parent) @@ -249,11 +249,11 @@ QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update return animatingNode; } else { - Plasma::SVGTextureNode *textureNode = dynamic_cast(oldNode); + ManagedTextureNode *textureNode = dynamic_cast(oldNode); if (!textureNode || m_textureChanged) { delete oldNode; - textureNode = new Plasma::SVGTextureNode; + textureNode = new ManagedTextureNode; textureNode->setTexture(QSharedPointer(window()->createTextureFromImage(m_iconPixmap.toImage()))); m_sizeChanged = true; m_textureChanged = false; diff --git a/src/declarativeimports/core/svgitem.cpp b/src/declarativeimports/core/svgitem.cpp index 50807d4f0..73af29345 100644 --- a/src/declarativeimports/core/svgitem.cpp +++ b/src/declarativeimports/core/svgitem.cpp @@ -27,7 +27,7 @@ #include "plasma/svg.h" -#include "svgtexturenode.h" +#include #include //floor() @@ -144,9 +144,9 @@ QSGNode *SvgItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updateP return Q_NULLPTR; } - SVGTextureNode *textureNode = static_cast(oldNode); + ManagedTextureNode *textureNode = static_cast(oldNode); if (!textureNode) { - textureNode = new SVGTextureNode; + textureNode = new ManagedTextureNode; textureNode->setFiltering(QSGTexture::Linear); m_textureChanged = true; } diff --git a/src/declarativeimports/core/svgtexturenode.h b/src/declarativeimports/core/svgtexturenode.h deleted file mode 100644 index 8cc7bb35b..000000000 --- a/src/declarativeimports/core/svgtexturenode.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright 2014 David Edmundson * - * * - * 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 * - * the Free Software Foundation; either version 2 of the License, 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 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 . * - ***************************************************************************/ - -#ifndef SVGTEXTURENODE_H -#define SVGTEXTURENODE_H - -#include - -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(QSharedPointer texture) - { - m_texture = texture; - QSGSimpleTextureNode::setTexture(texture.data()); - } -private: - QSharedPointer m_texture; -}; - -} -#endif // SVGTextureNode diff --git a/src/plasmaquick/CMakeLists.txt b/src/plasmaquick/CMakeLists.txt index a10beab49..659df1413 100644 --- a/src/plasmaquick/CMakeLists.txt +++ b/src/plasmaquick/CMakeLists.txt @@ -49,6 +49,7 @@ target_link_libraries(KF5PlasmaQuick KF5::CoreAddons KF5::XmlGui KF5::Declarative + KF5::QuickAddons ) if(HAVE_X11)