headsetcontrol-battery-widget/package/contents/ui/CompactRepresentation.qml

51 lines
1.4 KiB
QML
Raw Normal View History

2024-03-07 11:44:01 +00:00
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.plasmoid
import org.kde.kirigami as Kirigami
2024-01-21 18:54:24 +00:00
import "./lib/helper.js" as Helper
Item {
Rectangle { // battery
id: container
anchors.fill: parent
2024-01-25 15:21:39 +00:00
anchors.rightMargin: 1
2024-01-21 18:54:24 +00:00
anchors.topMargin: 10 - batteryheight
anchors.bottomMargin: 10 - batteryheight
color: "transparent"
2024-06-06 23:56:43 +00:00
border.color: Kirigami.Theme.textColor
2024-01-21 18:54:24 +00:00
radius: 4
Item {
anchors.fill: parent
anchors.margins: 2
Rectangle { // battery fill
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
2024-01-22 02:08:25 +00:00
color: Helper.interpolateColor(batteryPercent / 100, [ colorEmpty, colorHalf, colorFull ])
2024-01-21 18:54:24 +00:00
width: parent.width * Math.max(0, Math.min(batteryPercent, 100)) / 100
}
Kirigami.Icon { // headphones icon
anchors.bottom: parent.bottom
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 1
anchors.bottomMargin: 1
2024-06-06 23:56:43 +00:00
source: Helper.batteryIcon(batteryStatus)
2024-06-07 14:33:19 +00:00
color: batteryPercent == -1 ? colorEmpty : Kirigami.Theme.textColor
2024-01-21 18:54:24 +00:00
}
}
}
Rectangle { // battery cap
anchors.left: container.right
anchors.leftMargin: 1
anchors.verticalCenter: parent.verticalCenter
radius: 4
height: parent.height / 3
width: 2
2024-06-06 23:56:43 +00:00
color: Kirigami.Theme.textColor
2024-01-21 18:54:24 +00:00
}
}