summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Martin <[email protected]>2016-12-07 12:55:36 +0100
committerMarco Martin <[email protected]>2016-12-07 12:55:56 +0100
commit27ac0b760855bc5adfe85baed621bcf1efcc9194 (patch)
tree8eb4acf748376d36a18b65541456a094000a271a
parentf5cc14478cf137a65f94e6c38b664d4313657dd7 (diff)
Option to show percentage charge in the icon
Summary: add an option to show a text label with the percentage value in the battery icon. text will be shown bottom-right of the icon with a background for readability, similar to unread count for IM or email apps. code was already there but effectively dead code Test Plan: tried both with and without label Reviewers: broulik, #plasma Reviewed By: broulik, #plasma Subscribers: broulik, plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D3603
-rw-r--r--applets/batterymonitor/package/contents/config/config.qml30
-rw-r--r--applets/batterymonitor/package/contents/config/main.xml16
-rw-r--r--applets/batterymonitor/package/contents/ui/BadgeOverlay.qml55
-rwxr-xr-xapplets/batterymonitor/package/contents/ui/CompactRepresentation.qml33
-rw-r--r--applets/batterymonitor/package/contents/ui/ConfigGeneral.qml42
-rwxr-xr-xapplets/batterymonitor/package/contents/ui/batterymonitor.qml1
6 files changed, 156 insertions, 21 deletions
diff --git a/applets/batterymonitor/package/contents/config/config.qml b/applets/batterymonitor/package/contents/config/config.qml
new file mode 100644
index 0000000..5b73038
--- /dev/null
+++ b/applets/batterymonitor/package/contents/config/config.qml
@@ -0,0 +1,30 @@
+/***************************************************************************
+ * Copyright 2016 Marco Martin <[email protected]> *
+ * *
+ * 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 . *
+ ***************************************************************************/
+
+import QtQuick 2.0
+
+import org.kde.plasma.configuration 2.0
+
+ConfigModel {
+ ConfigCategory {
+ name: i18n("General")
+ icon: "battery"
+ source: "ConfigGeneral.qml"
+ }
+}
diff --git a/applets/batterymonitor/package/contents/config/main.xml b/applets/batterymonitor/package/contents/config/main.xml
new file mode 100644
index 0000000..31dff08
--- /dev/null
+++ b/applets/batterymonitor/package/contents/config/main.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+ <kcfgfile name=""/>
+
+ <group name="General">
+ <entry name="showPercentage" type="bool">
+ <label>If true, the battery will display a little charge percentage label inside.</label>
+ <default>false</default>
+ </entry>
+ </group>
+
+</kcfg>
+
diff --git a/applets/batterymonitor/package/contents/ui/BadgeOverlay.qml b/applets/batterymonitor/package/contents/ui/BadgeOverlay.qml
new file mode 100644
index 0000000..cbe5954
--- /dev/null
+++ b/applets/batterymonitor/package/contents/ui/BadgeOverlay.qml
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (C) 2016 Kai Uwe Broulik <[email protected]> *
+ * Copyright (C) 2016 Marco Martin <[email protected]> *
+ * *
+ * 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 . *
+ ***************************************************************************/
+
+import QtQuick 2.4
+import QtGraphicalEffects 1.0
+import org.kde.plasma.components 2.0 as PlasmaComponents
+
+Item {
+ property alias text: label.text
+ property Item icon
+
+ Rectangle {
+ id: badgeRect
+ anchors {
+ right: parent.right
+ bottom: parent.bottom
+ }
+ color: theme.backgroundColor
+ width: label.width + units.devicePixelRatio * 2
+ height: label.height
+ radius: units.devicePixelRatio * 3
+
+ PlasmaComponents.Label {
+ id: label
+ anchors.centerIn: parent
+ height: paintedHeight
+ font.pixelSize: Math.max(icon.height/4, theme.smallestFont.pixelSize*0.8)
+ }
+ }
+ layer.enabled: true
+ layer.effect: DropShadow {
+ horizontalOffset: 0
+ verticalOffset: 0
+ radius: units.devicePixelRatio * 2
+ samples: radius*2
+ color: Qt.rgba(0, 0, 0, 0.5)
+ }
+}
diff --git a/applets/batterymonitor/package/contents/ui/CompactRepresentation.qml b/applets/batterymonitor/package/contents/ui/CompactRepresentation.qml
index 90d3792..95cd77e 100755
--- a/applets/batterymonitor/package/contents/ui/CompactRepresentation.qml
+++ b/applets/batterymonitor/package/contents/ui/CompactRepresentation.qml
@@ -59,28 +59,21 @@ MouseArea {
property real iconSize: Math.min(width, height)
- Column {
+ BatteryIcon {
+ id: batteryIcon
anchors.centerIn: parent
+ hasBattery: batteryContainer.hasBattery
+ percent: batteryContainer.percent
+ pluggedIn: batteryContainer.pluggedIn
+ height: isConstrained ? batteryContainer.iconSize : batteryContainer.iconSize - batteryLabel.height
+ width: height
+ }
- BatteryIcon {
- id: batteryIcon
- anchors.horizontalCenter: isConstrained ? undefined : parent.horizontalCenter
- hasBattery: batteryContainer.hasBattery
- percent: batteryContainer.percent
- pluggedIn: batteryContainer.pluggedIn
- height: isConstrained ? batteryContainer.iconSize : batteryContainer.iconSize - batteryLabel.height
- width: height
- }
-
- Components.Label {
- id: batteryLabel
- width: parent.width
- height: visible ? paintedHeight : 0
- horizontalAlignment: Text.AlignHCenter
- text: i18nc("battery percentage below battery icon", "%1%", percent)
- font.pixelSize: Math.max(batteryContainer.iconSize/8, theme.mSize(theme.smallestFont).height)
- visible: false//!isConstrained()
- }
+ BadgeOverlay {
+ anchors.fill: batteryIcon
+ text: i18nc("battery percentage below battery icon", "%1%", percent)
+ icon: batteryIcon
+ visible: plasmoid.configuration.showPercentage
}
}
}
diff --git a/applets/batterymonitor/package/contents/ui/ConfigGeneral.qml b/applets/batterymonitor/package/contents/ui/ConfigGeneral.qml
new file mode 100644
index 0000000..369fb8a
--- /dev/null
+++ b/applets/batterymonitor/package/contents/ui/ConfigGeneral.qml
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 Marco Martin <[email protected]>
+ *
+ * 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 2.010-1301, USA.
+ */
+
+import QtQuick 2.0
+import QtQuick.Controls 1.0 as QtControls
+import QtQuick.Layouts 1.0 as QtLayouts
+
+import org.kde.plasma.core 2.0 as PlasmaCore
+
+Item {
+ id: root
+
+ implicitWidth: pageColumn.implicitWidth
+ implicitHeight: pageColumn.implicitHeight
+
+ property alias cfg_showPercentage: showPercentage.checked
+
+ QtLayouts.ColumnLayout {
+ id: pageColumn
+ anchors.left: parent.left
+
+ QtControls.CheckBox {
+ id: showPercentage
+ text: i18n("Show percentage")
+ }
+ }
+}
diff --git a/applets/batterymonitor/package/contents/ui/batterymonitor.qml b/applets/batterymonitor/package/contents/ui/batterymonitor.qml
index e715212..1872cfc 100755
--- a/applets/batterymonitor/package/contents/ui/batterymonitor.qml
+++ b/applets/batterymonitor/package/contents/ui/batterymonitor.qml
@@ -130,7 +130,6 @@ Item {
Component.onCompleted: {
Logic.updateBrightness(batterymonitor, pmSource);
- plasmoid.removeAction("configure");
Logic.updateInhibitions(batterymonitor, pmSource)
if (batterymonitor.kcmsAuthorized) {