current status

This commit is contained in:
Flummi 2024-01-21 19:54:24 +01:00
parent f5ed9d0c64
commit 5b423c2ab7
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
7 changed files with 129 additions and 68 deletions

View File

@ -7,14 +7,10 @@
<group name="General">
<entry name="pollingrate" type="Int">
<default>10.0</default>
<min>2.0</min>
<max>60.0</max>
<default>10</default>
</entry>
<entry name="batteryheight" type="Int">
<default>8.0</default>
<min>1.0</min>
<max>10.0</max>
<default>8</default>
</entry>
<entry name="colorEmpty" type="String">

View File

@ -0,0 +1,63 @@
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 {
Layout.minimumWidth: units.iconSizes.medium
Layout.alignment: Qt.AlignHCenter
Rectangle { // battery
id: container
anchors.fill: parent
anchors.rightMargin: 2
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(parseFloat("." + batteryPercent), [ 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
}
}
}

View File

@ -0,0 +1,44 @@
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 {
id: fullRep
Layout.preferredWidth: 250 * PlasmaCore.Units.devicePixelRatio
Layout.preferredHeight: 250 * PlasmaCore.Units.devicePixelRatio
Layout.minimumWidth: Layout.preferredWidth
Layout.maximumWidth: Layout.preferredWidth
Layout.minimumHeight: Layout.preferredHeight
Layout.maximumHeight: Layout.preferredHeight
clip: true
ColumnLayout {
id: wrapper
anchors.fill: parent
spacing: 0
RowLayout {
spacing: 0
Layout.fillWidth: true
ColumnLayout {
spacing: 0
// Items
Text {
text: "henlo"
color: PlasmaCore.Theme.textColor
}
}
}
Item {
Layout.fillHeight: true
}
}
}

View File

@ -1,13 +1,13 @@
import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.5 as QQC2
import org.kde.plasma.components as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kquickcontrols 2.0 as KQControls
import "./lib/helper.js" as Helper
QQC2.Pane {
PlasmaComponents.Pane {
id: root
property alias cfg_pollingrate: pollingrate.value
@ -30,13 +30,13 @@ QQC2.Pane {
text: "polling rate:"
color: PlasmaCore.Theme.textColor
}
QQC2.Slider {
PlasmaComponents.Slider {
id: pollingrate
value: 10.0
from: 2.0
to: 60.0
stepSize: 2.0
snapMode: QQC2.Slider.SnapAlways
value: 10
from: 2
to: 60
stepSize: 2
snapMode: PlasmaComponents.Slider.SnapAlways
}
Text {
text: cfg_pollingrate + " seconds"
@ -48,13 +48,13 @@ QQC2.Pane {
text: "battery height:"
color: PlasmaCore.Theme.textColor
}
QQC2.Slider {
PlasmaComponents.Slider {
id: batteryheight
value: 8.0
from: 1.0
to: 10.0
minimumValue: 1.0
maximumValue: 10.0
stepSize: 1.0
snapMode: QQC2.Slider.SnapAlways
snapMode: PlasmaComponents.Slider.SnapAlways
}
Text {
text: cfg_batteryheight

View File

@ -5,7 +5,7 @@ const batteryLevel = batteryPercent => ({
const batteryIcon = batteryPercent => ({
"-2": "action-unavailable",
"-1": "battery-ac-adapter"
"-1": "reload"
})[batteryPercent] ?? "audio-headphones-symbolic";
const hex2rgb = (hex, h = hex.replace('#', '0x')) => ({ r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 });

View File

@ -1,4 +1,4 @@
import QtQuick 2.0
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
@ -29,51 +29,6 @@ Item {
}
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.compactRepresentation: Item {
Layout.minimumWidth: units.iconSizes.medium
Layout.alignment: Qt.AlignHCenter
Rectangle { // battery
id: container
anchors.fill: parent
anchors.rightMargin: 2
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(parseFloat("." + batteryPercent), [ 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)
}
}
}
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
}
}
Plasmoid.fullRepresentation: FullRepresentation{}
Plasmoid.compactRepresentation: CompactRepresentation{}
}

View File

@ -7,15 +7,18 @@
"Category": "System Information",
"Dependencies": [
],
"EnabledByDefault": true,
"Icon": "battery",
"Id": "org.kde.plasma.headsetcontrol-battery-widget",
"Name": "Headset Battery Widget",
"ServiceTypes": [
"Plasma/Applet"
],
"Version": "1",
"Version": "1.5",
"Website": "https://git.lat/Flummi/headsetcontrol-battery-widget"
},
"X-Plasma-NotificationArea": true,
"X-Plasma-NotificationAreaCategory": "Hardware",
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml"
}