From a3bcebf50143133c751daf58b53d3f1c509bc16d Mon Sep 17 00:00:00 2001 From: Stefan Alexander van Heijningen Date: Sat, 23 Nov 2024 10:59:54 +0100 Subject: [PATCH] Make scrolling wheel on actuator test not be a significant increment --- .../PX4/ActuatorComponent.qml | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/ActuatorComponent.qml b/src/AutoPilotPlugins/PX4/ActuatorComponent.qml index 6c5fd7ec0e1..a462d2661c3 100644 --- a/src/AutoPilotPlugins/PX4/ActuatorComponent.qml +++ b/src/AutoPilotPlugins/PX4/ActuatorComponent.qml @@ -257,6 +257,25 @@ SetupPage { } } } + WheelHandler { + onWheel: (event) => { // Capture the event object + let minimum = sliderRepeater.itemAt(0).channel.min; + let maximum = sliderRepeater.itemAt(0).channel.max; + let stepSize = (maximum - minimum) * 0.01; + + const NAN_THRESHOLD = -0.1; + if (value < NAN_THRESHOLD && event.angleDelta.y > 0) { + value = stepSize; + } else { + let newValue = value + event.angleDelta.y / 120 * stepSize; + if (newValue < 0) { + value = NaN; + } else { + value = Math.min(maximum, newValue); + } + } + } + } } } @@ -264,10 +283,9 @@ SetupPage { Repeater { id: sliderRepeater model: actuators.actuatorTest.actuators - ActuatorSlider { channel: object - onActuatorValueChanged: (value) =>{ + onActuatorValueChanged: (value) => { if (isNaN(value)) { actuators.actuatorTest.stopControl(index); stop(); @@ -275,6 +293,25 @@ SetupPage { actuators.actuatorTest.setChannelTo(index, value); } } + WheelHandler { + onWheel: (event) => { + let minimum = channel.min; + let maximum = channel.max; + let stepSize = (maximum - minimum) * 0.01; + + const NAN_THRESHOLD = -0.1; + if (value < NAN_THRESHOLD && event.angleDelta.y > 0) { + value = stepSize; + } else { + let newValue = value + event.angleDelta.y / 120 * stepSize; + if (newValue < 0) { + value = NaN; + } else { + value = Math.min(maximum, newValue); + } + } + } + } } } // Repeater } // Row