57 lines
1.8 KiB
QML
57 lines
1.8 KiB
QML
import Quickshell.Services.UPower
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import QtQuick.Effects
|
|
import qs
|
|
import qs.widgets
|
|
import qs.settings
|
|
|
|
Rectangle {
|
|
id: root
|
|
layer.enabled: true
|
|
layer.effect: MultiEffect {
|
|
id: dropShadow
|
|
source: root
|
|
shadowEnabled: true
|
|
shadowHorizontalOffset: 4
|
|
shadowVerticalOffset: 2
|
|
shadowOpacity: 0.5
|
|
shadowColor: "#020202"
|
|
}
|
|
clip: true
|
|
color: Colors.base02
|
|
visible: UPower.displayDevice.isLaptopBattery
|
|
property double percent: UPower.displayDevice.percentage * 100
|
|
property bool hasBattery: UPower.displayDevice.isLaptopBattery
|
|
property bool charging: UPower.displayDevice.state === UPowerDeviceState.Charging
|
|
required property double moduleHeight
|
|
implicitHeight: moduleHeight
|
|
implicitWidth: batLayout.implicitWidth + 16
|
|
radius: Config.rounding
|
|
|
|
function batteryIcon(percent, charging) {
|
|
if (percent <= 15)
|
|
return charging ? "battery_charging_20" : "battery_alert";
|
|
if (percent <= 30)
|
|
return charging ? "battery_charging_30" : "battery_2_bar";
|
|
if (percent <= 50)
|
|
return charging ? "battery_charging_50" : "battery_3_bar";
|
|
if (percent <= 70)
|
|
return charging ? "battery_charging_60" : "battery_4_bar";
|
|
if (percent <= 85)
|
|
return charging ? "battery_charging_80" : "battery_5_bar";
|
|
if (percent <= 95)
|
|
return charging ? "battery_charging_90" : "battery_6_bar";
|
|
return charging ? "battery_charging_full" : "battery_full";
|
|
}
|
|
RowLayout {
|
|
id: batLayout
|
|
anchors.centerIn: root
|
|
MaterialIcon {
|
|
text: root.batteryIcon(root.percent, root.charging)
|
|
}
|
|
StyledText {
|
|
text: Math.floor(root.percent) + "%"
|
|
}
|
|
}
|
|
}
|