refactor: make battery indicator more consistent

This commit is contained in:
Kiana Sheibani 2026-01-25 04:39:31 -05:00
parent 608854ba03
commit 984a840a8d
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 12 additions and 9 deletions

View file

@ -13,14 +13,15 @@ ColumnLayout {
spacing: 4
readonly property color color: UPower.onBattery && UPower.displayDevice.percentage < 0.15 ?
Config.colors.batteryWarning :
Config.colors.battery
readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery
readonly property real percentage: UPower.displayDevice.percentage
readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01
readonly property color color: warning ? Config.colors.batteryWarning : Config.colors.battery
Loader {
Layout.alignment: Qt.AlignHCenter
active: UPower.displayDevice.isLaptopBattery
active: root.hasBattery
asynchronous: true
height: active ? (item?.implicitHeight ?? 0) : 0
@ -76,7 +77,7 @@ ColumnLayout {
radiusX: (meter.size + meter.thickness) / 2 + meter.padding
radiusY: radiusX
startAngle: -90 - meter.angle / 2
sweepAngle: meter.angle * UPower.displayDevice.percentage
sweepAngle: meter.angle * root.percentage
}
Behavior on strokeColor {
@ -98,7 +99,7 @@ ColumnLayout {
CustomText {
anchors.horizontalCenter: parent.horizontalCenter
text: Math.round(UPower.displayDevice.percentage * 100) + "%"
text: Math.floor(root.percentage * 100) + "%"
font.pointSize: Config.font.size.largest
}

View file

@ -67,7 +67,7 @@ Item {
name: "battery"
source: "Battery.qml"
color: UPower.displayDevice.isLaptopBattery &&
UPower.onBattery && UPower.displayDevice.percentage < 0.15 ?
UPower.onBattery && UPower.displayDevice.percentage < Config.services.batteryWarning + 0.01 ?
Config.colors.batteryWarning :
Config.colors.battery
}