mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
[battery]: support multiple batteries in shell's top panel
This change make Plasma Mobile show multiple batteries in the top panel in case the system has more than one. Signed-off-by: Sebastian Kügler <sebas@kde.org>
This commit is contained in:
parent
ab957a84f9
commit
f21c55953c
1 changed files with 48 additions and 15 deletions
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Sebastian Kügler <sebas@kde.org>
|
||||
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
|
||||
*
|
||||
|
|
@ -13,30 +14,62 @@ import org.kde.kirigami 2.20 as Kirigami
|
|||
import org.kde.plasma.components 3.0 as PlasmaComponents
|
||||
import org.kde.plasma.workspace.components 2.0 as PW
|
||||
import org.kde.plasma.private.mobileshell as MobileShell
|
||||
import org.kde.plasma.private.battery // needed for charging state
|
||||
|
||||
RowLayout {
|
||||
property real textPixelSize: Kirigami.Units.gridUnit * 0.6
|
||||
|
||||
visible: MobileShell.BatteryInfo.isVisible
|
||||
|
||||
PW.BatteryIcon {
|
||||
id: battery
|
||||
Layout.preferredWidth: height
|
||||
Layout.fillHeight: true
|
||||
hasBattery: true
|
||||
percent: MobileShell.BatteryInfo.percent
|
||||
pluggedIn: MobileShell.BatteryInfo.pluggedIn
|
||||
ListView {
|
||||
id: batteryRepeater
|
||||
|
||||
height: batteryLabel.height
|
||||
width: batteryLabel.height
|
||||
}
|
||||
property int batteryWidth: 0
|
||||
|
||||
spacing: root.elementSpacing
|
||||
model: MobileShell.BatteryInfo.batteries
|
||||
orientation: ListView.Horizontal
|
||||
|
||||
PlasmaComponents.Label {
|
||||
id: batteryLabel
|
||||
text: i18n("%1%", MobileShell.BatteryInfo.percent)
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
Layout.preferredWidth: (batteryRepeater.batteryWidth + root.elementSpacing) * batteryRepeater.count
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: false
|
||||
|
||||
color: Kirigami.Theme.textColor
|
||||
font.pixelSize: textPixelSize
|
||||
delegate: RowLayout {
|
||||
|
||||
Layout.preferredWidth: batteryRepeater.batteryWidth
|
||||
Layout.fillHeight: false
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
|
||||
height: batteryRepeater.height
|
||||
width: childrenRect.width
|
||||
|
||||
PW.BatteryIcon {
|
||||
id: battery
|
||||
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
height: batteryLabel.height
|
||||
width: batteryLabel.height
|
||||
|
||||
hasBattery: PluggedIn
|
||||
percent: Percent
|
||||
pluggedIn: ChargeState === BatteryControlModel.Charging
|
||||
}
|
||||
|
||||
PlasmaComponents.Label {
|
||||
id: batteryLabel
|
||||
text: i18n("%1%", Percent)
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
|
||||
color: Kirigami.Theme.textColor
|
||||
font.pixelSize: textPixelSize
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
// ListView & RowLayout have problems with childrenRect size,
|
||||
// set it here so it propagates up nicely
|
||||
batteryRepeater.batteryWidth = batteryLabel.width + battery.width
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue