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

@ -161,6 +161,8 @@ Singleton {
} }
readonly property QtObject services: QtObject { readonly property QtObject services: QtObject {
readonly property real batteryWarning: 0.15
readonly property string weatherLocation: "" readonly property string weatherLocation: ""
readonly property bool useFahrenheit: [Locale.ImperialUSSystem, Locale.ImperialSystem].includes(Qt.locale().measurementSystem) readonly property bool useFahrenheit: [Locale.ImperialUSSystem, Locale.ImperialSystem].includes(Qt.locale().measurementSystem)

View file

@ -95,7 +95,7 @@ Container {
readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery readonly property bool hasBattery: UPower.displayDevice.isLaptopBattery
readonly property real percentage: UPower.displayDevice.percentage readonly property real percentage: UPower.displayDevice.percentage
readonly property bool charging: !UPower.onBattery && batteryText.text !== "100" readonly property bool charging: !UPower.onBattery && batteryText.text !== "100"
readonly property bool warning: UPower.onBattery && percentage < 0.15 readonly property bool warning: UPower.onBattery && percentage < Config.services.batteryWarning + 0.01
text: { text: {
if (!hasBattery) { if (!hasBattery) {
@ -142,7 +142,7 @@ Container {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 0.5 anchors.verticalCenterOffset: 0.5
text: Math.round(battery.percentage * 100) text: Math.floor(battery.percentage * 100)
color: battery.warning ? Config.colors.batteryWarning : Config.colors.bg color: battery.warning ? Config.colors.batteryWarning : Config.colors.bg
font.family: Config.font.family.mono font.family: Config.font.family.mono
font.pointSize: 6 font.pointSize: 6

View file

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

View file

@ -67,7 +67,7 @@ Item {
name: "battery" name: "battery"
source: "Battery.qml" source: "Battery.qml"
color: UPower.displayDevice.isLaptopBattery && 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.batteryWarning :
Config.colors.battery Config.colors.battery
} }