bar: show power profile if no battery
This commit is contained in:
parent
2f714ff604
commit
d37b3926c8
2 changed files with 23 additions and 20 deletions
|
|
@ -14,7 +14,7 @@ Item {
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
implicitWidth: Math.max(network.implicitWidth, bluetooth.implicitWidth, devices.implicitWidth, battery.implicitWidth)
|
implicitWidth: Math.max(network.implicitWidth, bluetooth.implicitWidth, devices.implicitWidth, battery.implicitWidth)
|
||||||
implicitHeight: network.implicitHeight + bluetooth.implicitHeight + bluetooth.anchors.topMargin + (repeater.count > 0 ? devices.implicitHeight + devices.anchors.topMargin : 0) + (battery.active ? battery.implicitHeight + battery.anchors.topMargin : 0)
|
implicitHeight: network.implicitHeight + bluetooth.implicitHeight + bluetooth.anchors.topMargin + (repeater.count > 0 ? devices.implicitHeight + devices.anchors.topMargin : 0) + battery.implicitHeight + battery.anchors.topMargin
|
||||||
|
|
||||||
MaterialIcon {
|
MaterialIcon {
|
||||||
id: network
|
id: network
|
||||||
|
|
@ -62,30 +62,34 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
MaterialIcon {
|
||||||
id: battery
|
id: battery
|
||||||
|
|
||||||
anchors.horizontalCenter: devices.horizontalCenter
|
anchors.horizontalCenter: devices.horizontalCenter
|
||||||
anchors.top: repeater.count > 0 ? devices.bottom : bluetooth.bottom
|
anchors.top: repeater.count > 0 ? devices.bottom : bluetooth.bottom
|
||||||
anchors.topMargin: Appearance.spacing.small
|
anchors.topMargin: Appearance.spacing.small
|
||||||
|
|
||||||
active: UPower.displayDevice.isLaptopBattery
|
animate: true
|
||||||
asynchronous: true
|
text: {
|
||||||
|
if (!UPower.displayDevice.isLaptopBattery) {
|
||||||
sourceComponent: MaterialIcon {
|
if (PowerProfiles.profile === PowerProfile.PowerSaver)
|
||||||
text: {
|
return "energy_savings_leaf";
|
||||||
const perc = UPower.displayDevice.percentage;
|
if (PowerProfiles.profile === PowerProfile.Performance)
|
||||||
const charging = !UPower.onBattery;
|
return "rocket_launch";
|
||||||
if (perc === 1)
|
return "balance";
|
||||||
return charging ? "battery_charging_full" : "battery_full";
|
|
||||||
let level = Math.floor(perc * 7);
|
|
||||||
if (charging && (level === 4 || level === 1))
|
|
||||||
level--;
|
|
||||||
return charging ? `battery_charging_${(level + 3) * 10}` : `battery_${level}_bar`;
|
|
||||||
}
|
}
|
||||||
color: !UPower.onBattery || UPower.displayDevice.percentage > 0.2 ? root.colour : Colours.palette.m3error
|
|
||||||
fill: 1
|
const perc = UPower.displayDevice.percentage;
|
||||||
|
const charging = !UPower.onBattery;
|
||||||
|
if (perc === 1)
|
||||||
|
return charging ? "battery_charging_full" : "battery_full";
|
||||||
|
let level = Math.floor(perc * 7);
|
||||||
|
if (charging && (level === 4 || level === 1))
|
||||||
|
level--;
|
||||||
|
return charging ? `battery_charging_${(level + 3) * 10}` : `battery_${level}_bar`;
|
||||||
}
|
}
|
||||||
|
color: !UPower.onBattery || UPower.displayDevice.percentage > 0.2 ? root.colour : Colours.palette.m3error
|
||||||
|
fill: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on implicitWidth {
|
Behavior on implicitWidth {
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,10 @@ Column {
|
||||||
spacing: Appearance.spacing.normal
|
spacing: Appearance.spacing.normal
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
text: qsTr("Remaining: %1%").arg(Math.round(UPower.displayDevice.percentage * 100))
|
text: UPower.displayDevice.isLaptopBattery ? qsTr("Remaining: %1%").arg(Math.round(UPower.displayDevice.percentage * 100)) : qsTr("No battery detected")
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|
||||||
function formatSeconds(s: int, fallback: string): string {
|
function formatSeconds(s: int, fallback: string): string {
|
||||||
const day = Math.floor(s / 86400);
|
const day = Math.floor(s / 86400);
|
||||||
const hr = Math.floor(s / 3600) % 60;
|
const hr = Math.floor(s / 3600) % 60;
|
||||||
|
|
@ -33,7 +32,7 @@ Column {
|
||||||
return comps.join(", ") || fallback;
|
return comps.join(", ") || fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
text: qsTr("Time %1: %2").arg(UPower.onBattery ? "remaining" : "until charged").arg(UPower.onBattery ? formatSeconds(UPower.displayDevice.timeToEmpty, "Calculating...") : formatSeconds(UPower.displayDevice.timeToFull, "Fully charged!"))
|
text: UPower.displayDevice.isLaptopBattery ? qsTr("Time %1: %2").arg(UPower.onBattery ? "remaining" : "until charged").arg(UPower.onBattery ? formatSeconds(UPower.displayDevice.timeToEmpty, "Calculating...") : formatSeconds(UPower.displayDevice.timeToFull, "Fully charged!")) : qsTr("Power profile: %1").arg(PowerProfile.toString(PowerProfiles.profile))
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledRect {
|
StyledRect {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue