From 6ad36560a81a16c5247512f81edd1e9f3379832a Mon Sep 17 00:00:00 2001 From: Tim Gromeyer Date: Thu, 17 Apr 2025 08:34:05 +0200 Subject: [PATCH] Split into multible files (dedup code) --- linux/CMakeLists.txt | 1 + linux/Main.qml | 137 +++++++++++-------------------------------- linux/PodColumn.qml | 31 ++++++++++ 3 files changed, 65 insertions(+), 104 deletions(-) create mode 100644 linux/PodColumn.qml diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index ce8d1ab..79ad4a3 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -30,6 +30,7 @@ qt_add_qml_module(applinux Main.qml BatteryIndicator.qml SegmentedControl.qml + PodColumn.qml ) # Add the resource file diff --git a/linux/Main.qml b/linux/Main.qml index 98a4ab1..6b3d21a 100644 --- a/linux/Main.qml +++ b/linux/Main.qml @@ -8,98 +8,46 @@ ApplicationWindow { height: 300 title: "AirPods Settings" - onClosing: function(event) { - mainWindow.visible = false - } + onClosing: mainWindow.visible = false Column { - anchors.left: parent.left - anchors.right: parent.right + anchors.fill: parent spacing: 20 padding: 20 - // Battery Indicator + // Battery Indicator Row Row { - // center the content anchors.horizontalCenter: parent.horizontalCenter spacing: 8 - Column { - spacing: 5 - opacity: airPodsTrayApp.leftPodInEar ? 1 : 0.5 - visible: airPodsTrayApp.battery.leftPodAvailable - - Image { - source: "qrc:/icons/assets/" + airPodsTrayApp.podIcon - width: 72 - height: 72 - fillMode: Image.PreserveAspectFit - smooth: true - antialiasing: true - mipmap: true - anchors.horizontalCenter: parent.horizontalCenter - } - - BatteryIndicator { - batteryLevel: airPodsTrayApp.battery.leftPodLevel - isCharging: airPodsTrayApp.battery.leftPodCharging - darkMode: true - indicator: "L" - } + PodColumn { + isVisible: airPodsTrayApp.battery.leftPodAvailable + inEar: airPodsTrayApp.leftPodInEar + iconSource: "qrc:/icons/assets/" + airPodsTrayApp.podIcon + batteryLevel: airPodsTrayApp.battery.leftPodLevel + isCharging: airPodsTrayApp.battery.leftPodCharging + indicator: "L" } - Column { - spacing: 5 - opacity: airPodsTrayApp.rightPodInEar ? 1 : 0.5 - visible: airPodsTrayApp.battery.rightPodAvailable - - Image { - source: "qrc:/icons/assets/" + airPodsTrayApp.podIcon - mirror: true - width: 72 - height: 72 - fillMode: Image.PreserveAspectFit - smooth: true - antialiasing: true - mipmap: true - anchors.horizontalCenter: parent.horizontalCenter - } - - BatteryIndicator { - batteryLevel: airPodsTrayApp.battery.rightPodLevel - isCharging: airPodsTrayApp.battery.rightPodCharging - darkMode: true - indicator: "R" - } + PodColumn { + isVisible: airPodsTrayApp.battery.rightPodAvailable + inEar: airPodsTrayApp.rightPodInEar + iconSource: "qrc:/icons/assets/" + airPodsTrayApp.podIcon + batteryLevel: airPodsTrayApp.battery.rightPodLevel + isCharging: airPodsTrayApp.battery.rightPodCharging + indicator: "R" } - Column { - spacing: 5 - // hide the case status if battery level is 0 and no pod is in case - visible: airPodsTrayApp.battery.caseAvailable - - Image { - source: "qrc:/icons/assets/" + airPodsTrayApp.caseIcon - width: 92 - height: 72 - fillMode: Image.PreserveAspectFit - smooth: true - antialiasing: true - mipmap: true - anchors.horizontalCenter: parent.horizontalCenter - } - - BatteryIndicator { - batteryLevel: airPodsTrayApp.battery.caseLevel - isCharging: airPodsTrayApp.battery.caseCharging - darkMode: true - } + PodColumn { + isVisible: airPodsTrayApp.battery.caseAvailable + inEar: true + iconSource: "qrc:/icons/assets/" + airPodsTrayApp.caseIcon + batteryLevel: airPodsTrayApp.battery.caseLevel + isCharging: airPodsTrayApp.battery.caseCharging } } SegmentedControl { - id: noiseControlMode - // width: parent.width anchors.horizontalCenter: parent.horizontalCenter model: ["Off", "Noise Cancellation", "Transparency", "Adaptive"] currentIndex: airPodsTrayApp.noiseControlMode @@ -108,48 +56,32 @@ ApplicationWindow { } Text { - id: earDetectionStatus text: "Ear Detection Status: " + airPodsTrayApp.earDetectionStatus color: "#ffffff" } Switch { - id: caToggle text: "Conversational Awareness" checked: airPodsTrayApp.conversationalAwareness onCheckedChanged: airPodsTrayApp.conversationalAwareness = checked } Slider { - id: noiseLevelSlider visible: airPodsTrayApp.adaptiveModeActive from: 0 to: 100 stepSize: 1 value: airPodsTrayApp.adaptiveNoiseLevel - - property Timer debounceTimer: Timer { - interval: 500 // 500ms delay after last change - onTriggered: { - if (!noiseLevelSlider.pressed) { - airPodsTrayApp.setAdaptiveNoiseLevel(noiseLevelSlider.value) - } - } - } - - onPressedChanged: { - if (!pressed) { - debounceTimer.stop() - airPodsTrayApp.setAdaptiveNoiseLevel(value) - } - } - - onValueChanged: { - if (pressed) { - debounceTimer.restart() - } + + Timer { + id: debounceTimer + interval: 500 + onTriggered: if (!parent.pressed) airPodsTrayApp.setAdaptiveNoiseLevel(parent.value) } + onPressedChanged: if (!pressed) airPodsTrayApp.setAdaptiveNoiseLevel(value) + onValueChanged: if (pressed) debounceTimer.restart() + Label { text: "Adaptive Noise Level: " + parent.value color: "#ffffff" @@ -161,17 +93,14 @@ ApplicationWindow { spacing: 10 TextField { - id: newNameField placeholderText: airPodsTrayApp.deviceName maximumLength: 32 } Button { text: "Rename" - onClicked: { - airPodsTrayApp.renameAirPods(newNameField.text) - } + onClicked: airPodsTrayApp.renameAirPods(newNameField.text) } } } -} +} \ No newline at end of file diff --git a/linux/PodColumn.qml b/linux/PodColumn.qml new file mode 100644 index 0000000..fdde48e --- /dev/null +++ b/linux/PodColumn.qml @@ -0,0 +1,31 @@ +import QtQuick 2.15 + +Column { + property bool isVisible: true + property bool inEar: true + property string iconSource + property int batteryLevel: 0 + property bool isCharging: false + property string indicator: "" + + spacing: 5 + opacity: inEar ? 1 : 0.5 + visible: isVisible + + Image { + source: parent.iconSource + width: parent.indicator === "" ? 92 : 72 + height: 72 + fillMode: Image.PreserveAspectFit + mipmap: true + mirror: parent.indicator === "R" + anchors.horizontalCenter: parent.horizontalCenter + } + + BatteryIndicator { + batteryLevel: parent.batteryLevel + isCharging: parent.isCharging + darkMode: true + indicator: parent.indicator + } +} \ No newline at end of file