diff --git a/CMakeLists.txt b/CMakeLists.txt index 616603005..2542e9c49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,7 @@ endif() add_subdirectory(doc) add_subdirectory(libkworkspace) add_subdirectory(libtaskmanager) +add_subdirectory(components) if(dbusmenu-qt5_FOUND) add_subdirectory(appmenu) diff --git a/applets/batterymonitor/contents/ui/BatteryItem.qml b/applets/batterymonitor/contents/ui/BatteryItem.qml index c94e1aa2b..90b753c86 100644 --- a/applets/batterymonitor/contents/ui/BatteryItem.qml +++ b/applets/batterymonitor/contents/ui/BatteryItem.qml @@ -24,6 +24,7 @@ import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.workspace.components 2.0 import org.kde.kcoreaddons 1.0 as KCoreAddons import "plasmapackage:/code/logic.js" as Logic diff --git a/applets/batterymonitor/contents/ui/CompactRepresentation.qml b/applets/batterymonitor/contents/ui/CompactRepresentation.qml index 0febbeac1..4632c183a 100755 --- a/applets/batterymonitor/contents/ui/CompactRepresentation.qml +++ b/applets/batterymonitor/contents/ui/CompactRepresentation.qml @@ -23,6 +23,7 @@ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as Components +import org.kde.plasma.workspace.components 2.0 import "plasmapackage:/code/logic.js" as Logic Item { diff --git a/applets/batterymonitor/contents/ui/BatteryIcon.qml b/components/BatteryIcon.qml similarity index 100% rename from applets/batterymonitor/contents/ui/BatteryIcon.qml rename to components/BatteryIcon.qml diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt new file mode 100644 index 000000000..07c487456 --- /dev/null +++ b/components/CMakeLists.txt @@ -0,0 +1 @@ +install(DIRECTORY . DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/workspace/components) diff --git a/components/qmldir b/components/qmldir new file mode 100644 index 000000000..5d450f31e --- /dev/null +++ b/components/qmldir @@ -0,0 +1,4 @@ +module org.kde.plasma.workspace.components + +BatteryIcon 2.0 BatteryIcon.qml + diff --git a/lookandfeel/contents/components/BatteryIcon.qml b/lookandfeel/contents/components/BatteryIcon.qml deleted file mode 100644 index 308eaf85c..000000000 --- a/lookandfeel/contents/components/BatteryIcon.qml +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2011 Viranch Mehta - * Copyright 2013 Kai Uwe Broulik - * - * 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. - */ - -import QtQuick 2.0 -import org.kde.plasma.core 2.0 as PlasmaCore - -Item { - property bool hasBattery - property int percent - property bool pluggedIn - - PlasmaCore.Svg { - id: svg - imagePath: "icons/battery" - } - - PlasmaCore.SvgItem { - id: batterySvg - anchors.fill: parent - svg: svg - elementId: "Battery" - } - - PlasmaCore.SvgItem { - id: fillSvg - anchors.fill: parent - svg: svg - elementId: hasBattery ? fillElement(percent) : "Unavailable" - visible: elementId != "" - } - - function fillElement(p) { - // We switched from having steps of 20 for the battery percentage to a more accurate - // step of 10. This means we break other and older themes. - // If the Fill10 element is not found, it is likely that the theme doesn't support - // that and we use the older method of obtaining the fill element. - if (!svg.hasElement("Fill10")) { - print("No Fill10 element found in your theme's battery.svg - Using legacy 20% steps for battery icon"); - if (p >= 90) { - return "Fill100"; - } else if (p >= 70) { - return "Fill80"; - } else if (p >= 50) { - return "Fill60"; - } else if (p > 20) { - return "Fill40"; - } else if (p >= 10) { - return "Fill20"; - } - return ""; - } else { - if (p >= 95) { - return "Fill100"; - } else if (p >= 85) { - return "Fill90"; - } else if (p >= 75) { - return "Fill90"; - } else if (p >= 65) { - return "Fill80"; - } else if (p >= 55) { - return "Fill60"; - } else if (p >= 45) { - return "Fill50"; - } else if (p >= 35) { - return "Fill40"; - } else if (p >= 25) { - return "Fill30"; - } else if (p >= 15) { - return "Fill20"; - } else if (p > 5) { - return "Fill10"; - } - return ""; - } - } - - PlasmaCore.SvgItem { - anchors.fill: parent - svg: svg - elementId: "AcAdapter" - visible: pluggedIn - } -} diff --git a/lookandfeel/contents/components/InfoPane.qml b/lookandfeel/contents/components/InfoPane.qml index 818cb280f..3236d9300 100644 --- a/lookandfeel/contents/components/InfoPane.qml +++ b/lookandfeel/contents/components/InfoPane.qml @@ -23,6 +23,7 @@ import QtQuick.Layouts 1.1 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.workspace.components 2.0 as PW ColumnLayout { BreezeLabel { //should be a heading but we want it _loads_ bigger @@ -45,7 +46,7 @@ ColumnLayout { Layout.alignment: Qt.AlignRight visible: pmSource.connectedSources != "" - BatteryIcon { + PW.BatteryIcon { hasBattery: true percent: pmSource.data["Battery0"]["Percent"] pluggedIn: pmSource.data["AC Adapter"]["Plugged in"]