add percentage for the battery

battery shows percentage in the panel, panel
suports rectangular items
This commit is contained in:
Marco Martin 2016-01-25 11:08:25 +01:00
parent 1c8a653b1d
commit 8cef8fe532
2 changed files with 42 additions and 11 deletions

View file

@ -23,6 +23,7 @@ import QtQuick 2.2
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.workspace.components 2.0 import org.kde.plasma.workspace.components 2.0
@ -115,15 +116,45 @@ Item {
return status; return status;
} }
Plasmoid.compactRepresentation: BatteryIcon { Plasmoid.compactRepresentation: MouseArea {
id: batteryIcon Layout.minimumWidth: batteryLayout.implicitWidth
Layout.minimumHeight: units.iconSizes.small Layout.minimumHeight: batteryLayout.implicitHeight
anchors.horizontalCenter: parent.horizontalCenter
hasBattery: true property bool wasExpanded: false
percent: pmSource.data["Battery"]["Percent"] onPressed: {
//pluggedIn: batteryContainer.pluggedIn if (mouse.button == Qt.LeftButton) {
// height: batteryContainer.iconSize wasExpanded = plasmoid.expanded;
// width: height } else if (mouse.button == Qt.MiddleButton) {
muteVolume();
}
}
onClicked: {
if (mouse.button == Qt.LeftButton) {
plasmoid.expanded = !wasExpanded;
}
}
RowLayout {
id: batteryLayout
anchors.fill: parent
PlasmaComponents.Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: pmSource.data["Battery"]["Percent"]
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
}
BatteryIcon {
id: batteryIcon
Layout.minimumWidth: height
Layout.maximumWidth: height
Layout.fillHeight: true
hasBattery: true
percent: pmSource.data["Battery"]["Percent"]
//pluggedIn: batteryContainer.pluggedIn
// height: batteryContainer.iconSize
// width: height
}
}
} }
Plasmoid.fullRepresentation: ExpandedRepresentation { Plasmoid.fullRepresentation: ExpandedRepresentation {

View file

@ -90,8 +90,8 @@ PlasmaCore.ColorScope {
property bool animationsEnabled: false property bool animationsEnabled: false
property Item applet property Item applet
Layout.fillHeight: true Layout.fillHeight: true
Layout.minimumWidth: appletIconsRow.height Layout.minimumWidth: applet && applet.compactRepresentationItem ? Math.max(applet.compactRepresentationItem.Layout.minimumWidth, appletIconsRow.height) : appletIconsRow.height
Layout.maximumWidth: appletIconsRow.height Layout.maximumWidth: Layout.minimumWidth
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent