61 lines
1.7 KiB
QML
61 lines
1.7 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Layouts 1.3
|
|
import org.kde.plasma.plasmoid 2.0
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
import org.kde.kirigami 2.14 as Kirigami
|
|
|
|
import "./lib/helper.js" as Helper
|
|
|
|
Item {
|
|
Rectangle { // battery
|
|
id: container
|
|
anchors.fill: parent
|
|
anchors.rightMargin: 1
|
|
anchors.topMargin: 10 - batteryheight
|
|
anchors.bottomMargin: 10 - batteryheight
|
|
color: "transparent"
|
|
border.color: PlasmaCore.Theme.textColor
|
|
radius: 4
|
|
Plasmoid.toolTipMainText: "battery level: " + Helper.batteryLevel(batteryPercent)
|
|
Plasmoid.toolTipSubText: "polling rate: " + pollingrate + " seconds"
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
anchors.margins: 2
|
|
Rectangle { // battery fill
|
|
anchors.left: parent.left
|
|
anchors.top: parent.top
|
|
anchors.bottom: parent.bottom
|
|
color: Helper.interpolateColor(batteryPercent / 100, [ colorEmpty, colorHalf, colorFull ])
|
|
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
|
|
source: Helper.batteryIcon(batteryPercent)
|
|
color: batteryPercent == -1 ? colorFull : PlasmaCore.Theme.textColor
|
|
}
|
|
}
|
|
}
|
|
|
|
Rectangle { // battery cap
|
|
anchors.left: container.right
|
|
anchors.leftMargin: 1
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
radius: 4
|
|
height: parent.height / 3
|
|
width: 2
|
|
color: PlasmaCore.Theme.textColor
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
plasmoid.expanded = !plasmoid.expanded
|
|
}
|
|
}
|
|
}
|