Battery + NPill working and factorized
This commit is contained in:
parent
408f9a73a6
commit
def932c447
2 changed files with 63 additions and 59 deletions
|
|
@ -62,62 +62,43 @@ Item {
|
||||||
iconCircleColor: Colors.accentPrimary
|
iconCircleColor: Colors.accentPrimary
|
||||||
iconTextColor: Colors.backgroundPrimary
|
iconTextColor: Colors.backgroundPrimary
|
||||||
textColor: charging ? Colors.accentPrimary : Colors.textPrimary
|
textColor: charging ? Colors.accentPrimary : Colors.textPrimary
|
||||||
MouseArea {
|
tooltipText: {
|
||||||
anchors.fill: parent
|
let lines = []
|
||||||
hoverEnabled: true
|
if (!root.isReady) {
|
||||||
onEntered: {
|
return ""
|
||||||
pill.showDelayed()
|
|
||||||
batteryTooltip.show()
|
|
||||||
}
|
}
|
||||||
onExited: {
|
|
||||||
pill.hide()
|
if (root.battery.timeToEmpty > 0) {
|
||||||
batteryTooltip.show()
|
lines.push("Time left: " + Time.formatVagueHumanReadableTime(
|
||||||
|
root.battery.timeToEmpty))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
NTooltip {
|
|
||||||
id: batteryTooltip
|
|
||||||
positionAbove: false
|
|
||||||
target: pill
|
|
||||||
delay: Style.tooltipDelayLong
|
|
||||||
text: {
|
|
||||||
let lines = []
|
|
||||||
if (!root.isReady) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.battery.timeToEmpty > 0) {
|
if (root.battery.timeToFull > 0) {
|
||||||
lines.push("Time left: " + Time.formatVagueHumanReadableTime(
|
lines.push("Time until full: " + Time.formatVagueHumanReadableTime(
|
||||||
root.battery.timeToEmpty))
|
root.battery.timeToFull))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root.battery.timeToFull > 0) {
|
if (root.battery.changeRate !== undefined) {
|
||||||
lines.push("Time until full: " + Time.formatVagueHumanReadableTime(
|
const rate = root.battery.changeRate
|
||||||
root.battery.timeToFull))
|
if (rate > 0) {
|
||||||
}
|
lines.push(
|
||||||
|
root.charging ? "Charging rate: " + rate.toFixed(
|
||||||
if (root.battery.changeRate !== undefined) {
|
2) + " W" : "Discharging rate: " + rate.toFixed(
|
||||||
const rate = root.battery.changeRate
|
2) + " W")
|
||||||
if (rate > 0) {
|
} else if (rate < 0) {
|
||||||
lines.push(
|
lines.push("Discharging rate: " + Math.abs(rate).toFixed(2) + " W")
|
||||||
root.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 {
|
} else {
|
||||||
lines.push(root.charging ? "Charging" : "Discharging")
|
lines.push("Estimating...")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (root.battery.healthPercentage !== undefined
|
lines.push(root.charging ? "Charging" : "Discharging")
|
||||||
&& root.battery.healthPercentage > 0) {
|
|
||||||
lines.push("Health: " + Math.round(
|
|
||||||
root.battery.healthPercentage) + "%")
|
|
||||||
}
|
|
||||||
return lines.join("\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root.battery.healthPercentage !== undefined
|
||||||
|
&& root.battery.healthPercentage > 0) {
|
||||||
|
lines.push("Health: " + Math.round(root.battery.healthPercentage) + "%")
|
||||||
|
}
|
||||||
|
return lines.join("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ Item {
|
||||||
|
|
||||||
property string icon: ""
|
property string icon: ""
|
||||||
property string text: ""
|
property string text: ""
|
||||||
|
property string tooltipText: ""
|
||||||
property color pillColor: Colors.surfaceVariant
|
property color pillColor: Colors.surfaceVariant
|
||||||
property color textColor: Colors.textPrimary
|
property color textColor: Colors.textPrimary
|
||||||
property color iconCircleColor: Colors.accentPrimary
|
property color iconCircleColor: Colors.accentPrimary
|
||||||
|
|
@ -30,6 +31,7 @@ Item {
|
||||||
1, textItem.implicitWidth
|
1, textItem.implicitWidth
|
||||||
+ pillPaddingHorizontal * 2 + pillOverlap)
|
+ pillPaddingHorizontal * 2 + pillOverlap)
|
||||||
|
|
||||||
|
// TBC, do we use those ?
|
||||||
signal shown
|
signal shown
|
||||||
signal hidden
|
signal hidden
|
||||||
|
|
||||||
|
|
@ -165,6 +167,37 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTooltip {
|
||||||
|
id: tooltip
|
||||||
|
positionAbove: false
|
||||||
|
target: pill
|
||||||
|
delay: Style.tooltipDelayLong
|
||||||
|
text: root.tooltipText
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: showTimer
|
||||||
|
interval: Style.pillDelay
|
||||||
|
onTriggered: {
|
||||||
|
if (!showPill) {
|
||||||
|
showAnim.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
onEntered: {
|
||||||
|
showDelayed()
|
||||||
|
tooltip.show()
|
||||||
|
}
|
||||||
|
onExited: {
|
||||||
|
hide()
|
||||||
|
tooltip.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
if (!showPill) {
|
if (!showPill) {
|
||||||
shouldAnimateHide = autoHide
|
shouldAnimateHide = autoHide
|
||||||
|
|
@ -191,14 +224,4 @@ Item {
|
||||||
delayedHideAnim.restart()
|
delayedHideAnim.restart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: showTimer
|
|
||||||
interval: Style.pillDelay
|
|
||||||
onTriggered: {
|
|
||||||
if (!showPill) {
|
|
||||||
showAnim.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue