From cd00c7b0decd24471e94e99356f6fafa9b4d120b Mon Sep 17 00:00:00 2001 From: terrabladex Date: Tue, 16 Jul 2024 17:10:13 +0300 Subject: [PATCH 1/2] Add option to reverse the virtual joystick layout for left-handed users --- src/FlightDisplay/FlyViewWidgetLayer.qml | 1 + src/FlightDisplay/VirtualJoystick.qml | 6 ++++-- src/Settings/App.SettingsGroup.json | 7 +++++++ src/Settings/AppSettings.cc | 1 + src/Settings/AppSettings.h | 1 + src/UI/preferences/FlyViewSettings.qml | 11 ++++++++++- 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/FlightDisplay/FlyViewWidgetLayer.qml b/src/FlightDisplay/FlyViewWidgetLayer.qml index ec80b860afa..16544cb2bca 100644 --- a/src/FlightDisplay/FlyViewWidgetLayer.qml +++ b/src/FlightDisplay/FlyViewWidgetLayer.qml @@ -128,6 +128,7 @@ Item { property real bottomEdgeLeftInset: parent.height-y property bool autoCenterThrottle: QGroundControl.settingsManager.appSettings.virtualJoystickAutoCenterThrottle.rawValue + property bool leftHandedMode: QGroundControl.settingsManager.appSettings.virtualJoystickLeftHandedMode.rawValue property bool _virtualJoystickEnabled: QGroundControl.settingsManager.appSettings.virtualJoystick.rawValue property real bottomEdgeRightInset: parent.height-y property var _pipViewMargin: _pipView.visible ? parentToolInsets.bottomEdgeLeftInset + ScreenTools.defaultFontPixelHeight * 2 : diff --git a/src/FlightDisplay/VirtualJoystick.qml b/src/FlightDisplay/VirtualJoystick.qml index f0642673670..51067229788 100644 --- a/src/FlightDisplay/VirtualJoystick.qml +++ b/src/FlightDisplay/VirtualJoystick.qml @@ -19,6 +19,7 @@ import QGroundControl.Vehicle Item { // The following properties must be passed in from the Loader // property bool autoCenterThrottle - true: throttle will snap back to center when released + // property bool leftHandedMode - true: virtual joystick layout will be reversed id: virtualJoysticks @@ -33,7 +34,7 @@ Item { repeat: true onTriggered: { if (_activeVehicle && _initialConnectComplete) { - _activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, rightStick.yAxis, leftStick.xAxis, leftStick.yAxis) + leftHandedMode ? _activeVehicle.virtualTabletJoystickValue(leftStick.xAxis, leftStick.yAxis, rightStick.xAxis, rightStick.yAxis) : _activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, rightStick.yAxis, leftStick.xAxis, leftStick.yAxis) } leftYAxisValue = leftStick.yAxis // We keep Y axis value from the throttle stick for using it while there is a resize } @@ -72,7 +73,7 @@ Item { anchors.bottom: parent.bottom width: parent.height height: parent.height - yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover + yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && !leftHandedMode yAxisReCenter: autoCenterThrottle } @@ -84,6 +85,7 @@ Item { anchors.bottom: parent.bottom width: parent.height height: parent.height + yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && leftHandedMode yAxisReCenter: true } } diff --git a/src/Settings/App.SettingsGroup.json b/src/Settings/App.SettingsGroup.json index e691c2b58ff..9307af9a547 100644 --- a/src/Settings/App.SettingsGroup.json +++ b/src/Settings/App.SettingsGroup.json @@ -114,6 +114,13 @@ "type": "bool", "default": true }, +{ + "name": "virtualJoystickLeftHandedMode", + "shortDesc": "Left Handed Mode", + "longDesc": "If this option is enabled the virtual joystick layout will be reversed", + "type": "bool", + "default": false +}, { "name": "gstDebugLevel", "shortDesc": "Video streaming debug", diff --git a/src/Settings/AppSettings.cc b/src/Settings/AppSettings.cc index bbb470d0994..fec04f7025d 100644 --- a/src/Settings/AppSettings.cc +++ b/src/Settings/AppSettings.cc @@ -127,6 +127,7 @@ DECLARE_SETTINGSFACT(AppSettings, telemetrySaveNotArmed) DECLARE_SETTINGSFACT(AppSettings, audioMuted) DECLARE_SETTINGSFACT(AppSettings, virtualJoystick) DECLARE_SETTINGSFACT(AppSettings, virtualJoystickAutoCenterThrottle) +DECLARE_SETTINGSFACT(AppSettings, virtualJoystickLeftHandedMode) DECLARE_SETTINGSFACT(AppSettings, appFontPointSize) DECLARE_SETTINGSFACT(AppSettings, showLargeCompass) DECLARE_SETTINGSFACT(AppSettings, savePath) diff --git a/src/Settings/AppSettings.h b/src/Settings/AppSettings.h index 09f2726134f..9569cbcea46 100644 --- a/src/Settings/AppSettings.h +++ b/src/Settings/AppSettings.h @@ -37,6 +37,7 @@ class AppSettings : public SettingsGroup DEFINE_SETTINGFACT(audioMuted) DEFINE_SETTINGFACT(virtualJoystick) DEFINE_SETTINGFACT(virtualJoystickAutoCenterThrottle) + DEFINE_SETTINGFACT(virtualJoystickLeftHandedMode) DEFINE_SETTINGFACT(appFontPointSize) DEFINE_SETTINGFACT(indoorPalette) DEFINE_SETTINGFACT(showLargeCompass) diff --git a/src/UI/preferences/FlyViewSettings.qml b/src/UI/preferences/FlyViewSettings.qml index ab2dadf7789..ae8c2daa091 100644 --- a/src/UI/preferences/FlyViewSettings.qml +++ b/src/UI/preferences/FlyViewSettings.qml @@ -28,6 +28,7 @@ SettingsPage { property var _customMavlinkActionsSettings: _settingsManager.customMavlinkActionsSettings property Fact _virtualJoystick: _settingsManager.appSettings.virtualJoystick property Fact _virtualJoystickAutoCenterThrottle: _settingsManager.appSettings.virtualJoystickAutoCenterThrottle + property Fact _virtualJoystickLeftHandedMode: _settingsManager.appSettings.virtualJoystickLeftHandedMode property Fact _showAdditionalIndicatorsCompass: _flyViewSettings.showAdditionalIndicatorsCompass property Fact _lockNoseUpCompass: _flyViewSettings.lockNoseUpCompass property Fact _guidedMinimumAltitude: _flyViewSettings.guidedMinimumAltitude @@ -163,7 +164,7 @@ SettingsPage { SettingsGroupLayout { Layout.fillWidth: true heading: qsTr("Virtual Joystick") - visible: _virtualJoystick.visible || _virtualJoystickAutoCenterThrottle.visible + visible: _virtualJoystick.visible || _virtualJoystickAutoCenterThrottle.visible || _virtualJoystickLeftHandedMode.visible FactCheckBoxSlider { Layout.fillWidth: true @@ -179,6 +180,14 @@ SettingsPage { enabled: _virtualJoystick.rawValue fact: _virtualJoystickAutoCenterThrottle } + + FactCheckBoxSlider { + Layout.fillWidth: true + text: qsTr("Left-Handed Mode") + visible: _virtualJoystickLeftHandedMode.visible + enabled: _virtualJoystick.rawValue + fact: _virtualJoystickLeftHandedMode + } } SettingsGroupLayout { From c028eafa6079334ded07b46499ef6ff1dec40767 Mon Sep 17 00:00:00 2001 From: Ahmet Kaan Demirci Date: Sun, 6 Oct 2024 18:26:54 +0300 Subject: [PATCH 2/2] improve the text of the setting --- src/UI/preferences/FlyViewSettings.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UI/preferences/FlyViewSettings.qml b/src/UI/preferences/FlyViewSettings.qml index 33c1f30537a..e7021e7c241 100644 --- a/src/UI/preferences/FlyViewSettings.qml +++ b/src/UI/preferences/FlyViewSettings.qml @@ -184,7 +184,7 @@ SettingsPage { FactCheckBoxSlider { Layout.fillWidth: true - text: qsTr("Left-Handed Mode") + text: qsTr("Left-Handed Mode (swap sticks)") visible: _virtualJoystickLeftHandedMode.visible enabled: _virtualJoystick.rawValue fact: _virtualJoystickLeftHandedMode