diff --git a/app/view/CMakeLists.txt b/app/view/CMakeLists.txt index b7511c780..201f51f21 100644 --- a/app/view/CMakeLists.txt +++ b/app/view/CMakeLists.txt @@ -4,6 +4,7 @@ set(lattedock-app_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/effects.cpp ${CMAKE_CURRENT_SOURCE_DIR}/indicator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/indicatorinfo.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/indicatorresources.cpp ${CMAKE_CURRENT_SOURCE_DIR}/panelshadows.cpp ${CMAKE_CURRENT_SOURCE_DIR}/positioner.cpp ${CMAKE_CURRENT_SOURCE_DIR}/screenedgeghostwindow.cpp diff --git a/app/view/indicator.cpp b/app/view/indicator.cpp index 6661d5d65..0db46420d 100644 --- a/app/view/indicator.cpp +++ b/app/view/indicator.cpp @@ -41,7 +41,8 @@ namespace ViewPart { Indicator::Indicator(Latte::View *parent) : QObject(parent), m_view(parent), - m_info(new IndicatorPart::Info(this)) + m_info(new IndicatorPart::Info(this)), + m_resources(new IndicatorPart::Resources(this)) { m_corona = qobject_cast<Latte::Corona *>(m_view->corona()); loadConfig(); @@ -225,6 +226,11 @@ IndicatorPart::Info *Indicator::info() const return m_info; } +IndicatorPart::Resources *Indicator::resources() const +{ + return m_resources; +} + QQmlComponent *Indicator::component() const { return m_component; diff --git a/app/view/indicator.h b/app/view/indicator.h index cd5459a39..d3723ea30 100644 --- a/app/view/indicator.h +++ b/app/view/indicator.h @@ -22,6 +22,7 @@ // local #include "indicatorinfo.h" +#include "indicatorresources.h" // Qt #include <QObject> @@ -81,6 +82,12 @@ class Indicator: public QObject */ Q_PROPERTY(Latte::ViewPart::IndicatorPart::Info *info READ info NOTIFY infoChanged) + /** + * Resources provided from the indicator itself + */ + Q_PROPERTY(Latte::ViewPart::IndicatorPart::Resources *resources READ resources NOTIFY resourcesChanged) + + public: Indicator(Latte::View *parent); virtual ~Indicator(); @@ -110,6 +117,7 @@ public: QStringList customLocalPluginIds() const; IndicatorPart::Info *info() const; + IndicatorPart::Resources *resources() const; QObject *configuration() const; QQmlComponent *component() const; @@ -136,6 +144,7 @@ signals: void pluginChanged(); void pluginIsReadyChanged(); void providesConfigUiChanged(); + void resourcesChanged(); private: void loadConfig(); @@ -172,6 +181,7 @@ private: KPluginMetaData m_metadata; QPointer<IndicatorPart::Info> m_info; + QPointer<IndicatorPart::Resources> m_resources; QPointer<KDeclarative::ConfigPropertyMap> m_configuration; QPointer<KDeclarative::QmlObjectSharedEngine> m_lastCreatedConfigUi; diff --git a/app/view/indicatorinfo.cpp b/app/view/indicatorinfo.cpp index 64cc9979c..3a2887bae 100644 --- a/app/view/indicatorinfo.cpp +++ b/app/view/indicatorinfo.cpp @@ -19,6 +19,11 @@ #include "indicatorinfo.h" +// Qt +#include <QDebug> + +// Plasma +#include <Plasma/Svg> namespace Latte { namespace ViewPart { diff --git a/app/view/indicatorresources.cpp b/app/view/indicatorresources.cpp new file mode 100644 index 000000000..446464fdb --- /dev/null +++ b/app/view/indicatorresources.cpp @@ -0,0 +1,71 @@ +/* +* Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com> +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "indicatorresources.h" + +// Qt +#include <QDebug> + +// Plasma +#include <Plasma/Svg> + +namespace Latte { +namespace ViewPart { +namespace IndicatorPart { + +Resources::Resources(QObject *parent) : + QObject(parent) +{ +} + +Resources::~Resources() +{ +} + +QList<QObject *> Resources::svgs() const +{ + return m_svgs; +} + +void Resources::setSvgImagePaths(QStringList paths) +{ + if (m_svgImagePaths == paths) { + return; + } + + while (!m_svgs.isEmpty()) { + auto svg = m_svgs[0]; + m_svgs.removeFirst(); + svg->deleteLater(); + } + + for(const auto &path : paths) { + if (!path.isEmpty()) { + Plasma::Svg *svg = new Plasma::Svg(this); + svg->setImagePath(path); + m_svgs << svg; + } + } + + emit svgsChanged(); +} + +} +} +} diff --git a/app/view/indicatorresources.h b/app/view/indicatorresources.h new file mode 100644 index 000000000..e21d0ff1a --- /dev/null +++ b/app/view/indicatorresources.h @@ -0,0 +1,61 @@ +/* +* Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com> +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef VIEWINDICATORRESOURCES_H +#define VIEWINDICATORRESOURCES_H + +// Qt +#include <QObject> + +namespace Latte { +namespace ViewPart { +namespace IndicatorPart { + +/** + * Resources requested from indicator in order to reduce consumption + **/ + +class Resources: public QObject +{ + Q_OBJECT + Q_PROPERTY(QList<QObject *> svgs READ svgs NOTIFY svgsChanged) + +public: + Resources(QObject *parent); + virtual ~Resources(); + + QList<QObject *> svgs() const; + +public slots: + Q_INVOKABLE void setSvgImagePaths(QStringList paths); + +signals: + void svgsChanged(); + +private: + QStringList m_svgImagePaths; + + QList<QObject *> m_svgs; +}; + +} +} +} + +#endif diff --git a/containment/package/contents/ui/applet/indicator/Bridge.qml b/containment/package/contents/ui/applet/indicator/Bridge.qml index 03728fe54..eccf1fc43 100644 --- a/containment/package/contents/ui/applet/indicator/Bridge.qml +++ b/containment/package/contents/ui/applet/indicator/Bridge.qml @@ -90,4 +90,5 @@ Item{ //! grouped options readonly property Item shared: indicators readonly property QtObject configuration: indicators.configuration + readonly property QtObject resources: indicators.resources } diff --git a/containment/package/contents/ui/indicators/Manager.qml b/containment/package/contents/ui/indicators/Manager.qml index 3e531fdbd..d45838539 100644 --- a/containment/package/contents/ui/indicators/Manager.qml +++ b/containment/package/contents/ui/indicators/Manager.qml @@ -30,11 +30,12 @@ Item{ id: managerIndicator readonly property QtObject configuration: latteView && latteView.indicator ? latteView.indicator.configuration : null + readonly property QtObject resources: latteView && latteView.indicator ? latteView.indicator.resources : null readonly property bool isEnabled: latteView && latteView.indicator ? (latteView.indicator.enabled && latteView.indicator.pluginIsReady) : false readonly property bool enabledForApplets: latteView && latteView.indicator ? latteView.indicator.enabledForApplets : true readonly property real padding: Math.max(info.minLengthPadding, latteView && latteView.indicator ? latteView.indicator.padding : 0.08) - readonly property string type: latteView && latteView.indicator ? latteView.indicator.type : "org.kde.latte.default" + readonly property string type: latteView && latteView.indicator ? latteView.indicator.type : "org.kde.latte.default" readonly property Component plasmaStyleComponent: latteView && latteView.indicator ? latteView.indicator.plasmaComponent : null readonly property Component indicatorComponent: latteView && latteView.indicator ? latteView.indicator.component : null @@ -44,7 +45,7 @@ Item{ && metricsLoader.item.needsIconColors readonly property bool needsMouseEventCoordinates: metricsLoader.active && metricsLoader.item && metricsLoader.item.hasOwnProperty("needsMouseEventCoordinates") - && metricsLoader.item.needsMouseEventCoordinates + && metricsLoader.item.needsMouseEventCoordinates readonly property bool providesFrontLayer: metricsLoader.active && metricsLoader.item && metricsLoader.item.hasOwnProperty("providesFrontLayer") && metricsLoader.item.providesFrontLayer @@ -78,8 +79,14 @@ Item{ return 0; } + + readonly property variant svgPaths: metricsLoader.active && metricsLoader.item && metricsLoader.item.hasOwnProperty("svgImagePaths") ? + metricsLoader.item.svgImagePaths : [] + + onSvgPathsChanged: latteView.indicator.resources.setSvgImagePaths(svgPaths); } + //! Metrics and values provided from an invisible indicator Loader{ id: metricsLoader diff --git a/declarativeimports/components/IndicatorItem.qml b/declarativeimports/components/IndicatorItem.qml index bd1ab4e31..efdae841a 100644 --- a/declarativeimports/components/IndicatorItem.qml +++ b/declarativeimports/components/IndicatorItem.qml @@ -48,4 +48,9 @@ Item { //! Values below the specified value are ignored. This value is a percentage, //! e.g 0.06 -> 6% property real minLengthPadding: 0 + + + //! svg image paths either from plasma theme or local files relevant to indicator "ui" directory + //! in order to reduce resources usage + property var svgImagePaths: [] } diff --git a/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml b/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml index c2a7d9907..9e2977212 100644 --- a/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml +++ b/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml @@ -189,11 +189,6 @@ Item { sourceComponent: Item{ anchors.fill: parent - PlasmaCore.Svg { - id: taskSvg - imagePath: "widgets/tasks" - } - Item { id: iconBox anchors.centerIn: parent @@ -207,9 +202,10 @@ Item { implicitWidth: 0.25 * iconBox.width implicitHeight: implicitWidth - svg: taskSvg + svg: groupSvg elementId: elementForLocation(plasmoid.location) + readonly property QtObject groupSvg: indicator.resources.svgs.length > 0 ? indicator.resources.svgs[0] : null function elementForLocation(location) { switch (location) { diff --git a/indicators/org.kde.latte.plasma/package/ui/main.qml b/indicators/org.kde.latte.plasma/package/ui/main.qml index 9ce9abd28..b5c7d650c 100644 --- a/indicators/org.kde.latte.plasma/package/ui/main.qml +++ b/indicators/org.kde.latte.plasma/package/ui/main.qml @@ -31,6 +31,7 @@ LatteComponents.IndicatorItem { providesClickedAnimation: clickedAnimationEnabled providesHoveredAnimation: true providesFrontLayer: true + svgImagePaths: ["widgets/tasks"] //! config options readonly property bool clickedAnimationEnabled: indicator && indicator.configuration diff --git a/plasmoid/package/contents/ui/indicators/Manager.qml b/plasmoid/package/contents/ui/indicators/Manager.qml index efdb066e0..1362ce2b1 100644 --- a/plasmoid/package/contents/ui/indicators/Manager.qml +++ b/plasmoid/package/contents/ui/indicators/Manager.qml @@ -32,6 +32,8 @@ Item{ id: managerIndicator readonly property Item configuration: explicitOptions + readonly property QtObject resources: null + readonly property bool isEnabled: true readonly property string type: "org.kde.latte.default" diff --git a/plasmoid/package/contents/ui/task/indicator/Bridge.qml b/plasmoid/package/contents/ui/task/indicator/Bridge.qml index e970e560f..f3993ee00 100644 --- a/plasmoid/package/contents/ui/task/indicator/Bridge.qml +++ b/plasmoid/package/contents/ui/task/indicator/Bridge.qml @@ -71,6 +71,8 @@ Item { readonly property bool usePlasmaTabsStyle: false + readonly property variant svgs: indicators ? indicators.svgs : [] + readonly property QtObject palette: enforceLattePalette ? latteBridge.palette.applyTheme : theme //!icon colors @@ -80,6 +82,7 @@ Item { //! grouped options readonly property Item shared: indicators ? indicators : emptyOptions readonly property QtObject configuration: indicators ? indicators.configuration : null + readonly property QtObject resources: indicators ? indicators.resources : null Item{id: emptyOptions} }