Bar/Battery: improved tooltip and handle negative charging rate
- Also slightly tweaked StyledTooltip minimum size to avoid inconsistencies (Tooltip with a single line looked like pills instead of rounded rectangles)
This commit is contained in:
parent
de94d94265
commit
7639900f38
3 changed files with 51 additions and 12 deletions
|
|
@ -4,6 +4,7 @@ import Quickshell.Services.UPower
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import qs.Components
|
import qs.Components
|
||||||
import qs.Settings
|
import qs.Settings
|
||||||
|
import "../../Helpers/Time.js" as Time
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: batteryWidget
|
id: batteryWidget
|
||||||
|
|
@ -76,17 +77,37 @@ Item {
|
||||||
positionAbove: false
|
positionAbove: false
|
||||||
text: {
|
text: {
|
||||||
let lines = [];
|
let lines = [];
|
||||||
if (batteryWidget.isReady) {
|
if (!batteryWidget.isReady) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (batteryWidget.battery.timeToEmpty > 0) {
|
||||||
|
lines.push("Time left: " + Time.formatVagueHumanReadableTime(batteryWidget.battery.timeToEmpty));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (batteryWidget.battery.timeToFull > 0) {
|
||||||
|
lines.push("Time until full: " + Time.formatVagueHumanReadableTime(batteryWidget.battery.timeToFull));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (batteryWidget.battery.changeRate !== undefined) {
|
||||||
|
const rate = batteryWidget.battery.changeRate;
|
||||||
|
if (rate > 0) {
|
||||||
|
lines.push(batteryWidget.charging ? "Charging rate: " + rate.toFixed(2) + " W" : "Discharging rate: " + rate.toFixed(2) + " W");
|
||||||
|
}
|
||||||
|
else if (rate < 0) {
|
||||||
|
lines.push("Discharging rate: " + Math.abs(rate).toFixed(2) + " W");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lines.push("Estimating...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
lines.push(batteryWidget.charging ? "Charging" : "Discharging");
|
lines.push(batteryWidget.charging ? "Charging" : "Discharging");
|
||||||
lines.push(Math.round(batteryWidget.percent) + "%");
|
}
|
||||||
if (batteryWidget.battery.changeRate !== undefined)
|
|
||||||
lines.push("Rate: " + batteryWidget.battery.changeRate.toFixed(2) + " W");
|
|
||||||
if (batteryWidget.battery.timeToEmpty > 0)
|
if (batteryWidget.battery.healthPercentage !== undefined && batteryWidget.battery.healthPercentage > 0) {
|
||||||
lines.push("Time left: " + Math.floor(batteryWidget.battery.timeToEmpty / 60) + " min");
|
lines.push("Health: " + Math.round(batteryWidget.battery.healthPercentage) + "%");
|
||||||
if (batteryWidget.battery.timeToFull > 0)
|
|
||||||
lines.push("Time to full: " + Math.floor(batteryWidget.battery.timeToFull / 60) + " min");
|
|
||||||
if (batteryWidget.battery.healthPercentage !== undefined)
|
|
||||||
lines.push("Health: " + Math.round(batteryWidget.battery.healthPercentage) + "%");
|
|
||||||
}
|
}
|
||||||
return lines.join("\n");
|
return lines.join("\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ Window {
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
visible: false
|
visible: false
|
||||||
|
|
||||||
minimumWidth: tooltipText.implicitWidth + 24
|
minimumWidth: Math.max(50, tooltipText.implicitWidth + 24)
|
||||||
minimumHeight: tooltipText.implicitHeight + 16
|
minimumHeight: Math.max(50, tooltipText.implicitHeight + 16)
|
||||||
property var _timerObj: null
|
property var _timerObj: null
|
||||||
|
|
||||||
onTooltipVisibleChanged: {
|
onTooltipVisibleChanged: {
|
||||||
|
|
|
||||||
18
Helpers/Time.js
Normal file
18
Helpers/Time.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
function formatVagueHumanReadableTime(totalSeconds) {
|
||||||
|
const hours = Math.floor(totalSeconds / 3600);
|
||||||
|
const minutes = Math.floor((totalSeconds - (hours * 3600)) / 60);
|
||||||
|
const seconds = totalSeconds - (hours * 3600) - (minutes * 60);
|
||||||
|
|
||||||
|
var str = "";
|
||||||
|
if (hours) {
|
||||||
|
str += hours.toString() + "h";
|
||||||
|
}
|
||||||
|
if (minutes) {
|
||||||
|
str += minutes.toString() + "m";
|
||||||
|
}
|
||||||
|
if (!hours && !minutes) {
|
||||||
|
str += seconds.toString() + "s";
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue