applets/batterymonitor: fix CompactRepresentation

f9e39815dc introduced a few regressions by
blowing away the custom CompactRepresentation when there are no
batteries. This introduced a race condition that sometimes set the icon
incorrectly and also broke scrolling on the applet to change the volume.

This commit fixes those issues by using the existing infrastructure for
the CompactPepresentation, but simply swapping out its custom battery
icon for normal icon when there are no batteries.
wilder-5.24
Nate Graham 4 years ago
parent 6f5a28665c
commit 471cc3745b
  1. 10
      applets/batterymonitor/package/contents/ui/CompactRepresentation.qml
  2. 6
      applets/batterymonitor/package/contents/ui/main.qml

@ -18,6 +18,7 @@ MouseArea {
property real itemSize: Math.min(root.height, root.width/view.count) property real itemSize: Math.min(root.height, root.width/view.count)
readonly property bool isConstrained: plasmoid.formFactor === PlasmaCore.Types.Vertical || plasmoid.formFactor === PlasmaCore.Types.Horizontal readonly property bool isConstrained: plasmoid.formFactor === PlasmaCore.Types.Vertical || plasmoid.formFactor === PlasmaCore.Types.Horizontal
property real brightnessError: 0 property real brightnessError: 0
property bool hasBatteries: true
onClicked: plasmoid.expanded = !plasmoid.expanded onClicked: plasmoid.expanded = !plasmoid.expanded
@ -44,8 +45,17 @@ MouseArea {
batterymonitor.screenBrightness = Math.max(minimumBrightness, Math.min(maximumBrightness, newBrightness)); batterymonitor.screenBrightness = Math.max(minimumBrightness, Math.min(maximumBrightness, newBrightness));
} }
// "No Batteries" case
PlasmaCore.IconItem {
anchors.fill: parent
visible: !root.hasBatteries
source: plasmoid.icon
}
// We have any batteries; show their status
//Should we consider turning this into a Flow item? //Should we consider turning this into a Flow item?
Row { Row {
visible: root.hasBatteries
anchors.centerIn: parent anchors.centerIn: parent
Repeater { Repeater {
id: view id: view

@ -219,11 +219,9 @@ Item {
} }
} }
Component { Plasmoid.compactRepresentation: CompactRepresentation {
id: batteryCompact hasBatteries: batterymonitor.hasBatteries
CompactRepresentation {}
} }
Plasmoid.compactRepresentation: hasBatteries ? batteryCompact : null
readonly property bool isBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false readonly property bool isBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false

Loading…
Cancel
Save