From d51555ee47181195d4242dc3c2bf91befdb815ac Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 20 Jan 2024 03:03:42 +0100 Subject: [PATCH] adjust colors --- package/contents/ui/main.qml | 56 +++++++++--------------------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml index 32ee1bb..ff7a122 100644 --- a/package/contents/ui/main.qml +++ b/package/contents/ui/main.qml @@ -16,8 +16,10 @@ Item { connectedSources: ["headsetcontrol -bc"] interval: pollingrate * 1e3 onNewData: { - if(data['exit_code'] > 0) - return console.log('error lol'); + if(data['exit_code'] > 0) { + batteryPercent = -2; + return; + } batteryPercent = data['stdout']; } } @@ -25,13 +27,13 @@ Item { Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.compactRepresentation: Item { - Layout.minimumWidth: units.iconSizes.large + Layout.minimumWidth: units.iconSizes.medium Layout.alignment: Qt.AlignHCenter Rectangle { // battery id: container anchors.fill: parent - anchors.rightMargin: 15 + anchors.rightMargin: 2 anchors.topMargin: 2 anchors.bottomMargin: 2 color: "transparent" @@ -50,6 +52,14 @@ Item { color: batteryColor() 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: "audio-headphones-symbolic" + } } } Rectangle { // battery cap @@ -61,43 +71,5 @@ Item { width: 2 color: PlasmaCore.Theme.textColor } - Rectangle { // symbol: headset - anchors.fill: parent - anchors.rightMargin: 23 - color: "transparent" - Kirigami.Icon { - anchors.bottom: parent.bottom - anchors.left: parent.right - height: container.height * 0.45 - source: "audio-headset-symbolic" - } - } - - - function batteryColor() { - let color = "red" - if(batteryPercent == -1) // charging - color = "green"; - else if(batteryPercent == -2) // not connected - color = "red"; - else if(batteryPercent > 80) - color = "green"; - else if(batteryPercent > 60) - color = "green"; - else if(batteryPercent > 40) - color = "yellow"; - else if(batteryPercent > 20) - color = "red"; - return color; - } - - function batteryLevel() { - if(batteryPercent == -1) - return "charging"; - else if(batteryPercent == -2) - return "not connected"; - else - return batteryPercent + "%"; - } } }