mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-11 13:18:13 +03:00
introduce Resources for Indicators
This commit is contained in:
parent
33962fa1fc
commit
f75605d78d
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -19,6 +19,11 @@
|
||||
|
||||
#include "indicatorinfo.h"
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
|
||||
// Plasma
|
||||
#include <Plasma/Svg>
|
||||
|
||||
namespace Latte {
|
||||
namespace ViewPart {
|
||||
|
71
app/view/indicatorresources.cpp
Normal file
71
app/view/indicatorresources.cpp
Normal file
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
61
app/view/indicatorresources.h
Normal file
61
app/view/indicatorresources.h
Normal file
@ -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
|
@ -90,4 +90,5 @@ Item{
|
||||
//! grouped options
|
||||
readonly property Item shared: indicators
|
||||
readonly property QtObject configuration: indicators.configuration
|
||||
readonly property QtObject resources: indicators.resources
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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: []
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -31,6 +31,7 @@ LatteComponents.IndicatorItem {
|
||||
providesClickedAnimation: clickedAnimationEnabled
|
||||
providesHoveredAnimation: true
|
||||
providesFrontLayer: true
|
||||
svgImagePaths: ["widgets/tasks"]
|
||||
|
||||
//! config options
|
||||
readonly property bool clickedAnimationEnabled: indicator && indicator.configuration
|
||||
|
@ -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"
|
||||
|
@ -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}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user