feat: show battery status in Bluetooth popout (#1130)
* Display bluetooth battery in popout when possible Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com> * Actually return the alert icon if battery status can't be determined Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com> * Fix lint error Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com> * move icon to right + static popout width --------- Signed-off-by: Dan Griffiths <dgriffiths@widgitlabs.com> Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
parent
dfc5bcf8b9
commit
f924dbfbbb
2 changed files with 29 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ ColumnLayout {
|
||||||
|
|
||||||
required property PopoutState popouts
|
required property PopoutState popouts
|
||||||
|
|
||||||
|
width: 300
|
||||||
spacing: Appearance.spacing.small
|
spacing: Appearance.spacing.small
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|
@ -99,6 +100,13 @@ ColumnLayout {
|
||||||
Layout.rightMargin: Appearance.spacing.small / 2
|
Layout.rightMargin: Appearance.spacing.small / 2
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
text: device.modelData.name
|
text: device.modelData.name
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialIcon {
|
||||||
|
visible: device.modelData.state === BluetoothDeviceState.Connected // qmllint disable unresolved-type
|
||||||
|
text: Icons.getBatteryIcon(device.modelData.batteryAvailable ? device.modelData.battery * 100 : -1)
|
||||||
|
color: device.modelData.battery < 0.2 ? Colours.palette.m3error : Colours.palette.m3onSurfaceVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledRect {
|
StyledRect {
|
||||||
|
|
@ -141,6 +149,7 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
|
visible: status === Loader.Ready
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
active: device.modelData.bonded
|
active: device.modelData.bonded
|
||||||
sourceComponent: Item {
|
sourceComponent: Item {
|
||||||
|
|
|
||||||
|
|
@ -240,4 +240,24 @@ Singleton {
|
||||||
}
|
}
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBatteryIcon(charge: int): string {
|
||||||
|
if (charge > 0 && charge < 5)
|
||||||
|
return "battery_0_bar";
|
||||||
|
if (charge >= 5 && charge < 20)
|
||||||
|
return "battery_1_bar";
|
||||||
|
if (charge >= 20 && charge < 35)
|
||||||
|
return "battery_2_bar";
|
||||||
|
if (charge >= 35 && charge < 50)
|
||||||
|
return "battery_3_bar";
|
||||||
|
if (charge >= 50 && charge < 65)
|
||||||
|
return "battery_4_bar";
|
||||||
|
if (charge >= 65 && charge < 80)
|
||||||
|
return "battery_5_bar";
|
||||||
|
if (charge >= 80 && charge < 95)
|
||||||
|
return "battery_6_bar";
|
||||||
|
if (charge >= 95)
|
||||||
|
return "battery_full";
|
||||||
|
return "battery_alert";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue