Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: Option to reverse the virtual joystick layout for left-handed users #11681

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions src/FlightDisplay/FlyViewWidgetLayer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
6 changes: 4 additions & 2 deletions src/FlightDisplay/VirtualJoystick.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -35,7 +36,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
}
Expand Down Expand Up @@ -74,7 +75,7 @@ Item {
anchors.bottom: parent.bottom
width: parent.height
height: parent.height
yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover
yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && !leftHandedMode
yAxisReCenter: autoCenterThrottle
}

Expand All @@ -86,6 +87,7 @@ Item {
anchors.bottom: parent.bottom
width: parent.height
height: parent.height
yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && leftHandedMode
yAxisReCenter: true
}
}
7 changes: 7 additions & 0 deletions src/Settings/App.SettingsGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Settings/AppSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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, savePath)
DECLARE_SETTINGSFACT(AppSettings, androidSaveToSDCard)
Expand Down
1 change: 1 addition & 0 deletions src/Settings/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(savePath)
Expand Down
11 changes: 10 additions & 1 deletion src/UI/preferences/FlyViewSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -164,7 +165,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
Expand All @@ -180,6 +181,14 @@ SettingsPage {
enabled: _virtualJoystick.rawValue
fact: _virtualJoystickAutoCenterThrottle
}

FactCheckBoxSlider {
Layout.fillWidth: true
text: qsTr("Left-Handed Mode (swap sticks)")
visible: _virtualJoystickLeftHandedMode.visible
enabled: _virtualJoystick.rawValue
fact: _virtualJoystickLeftHandedMode
}
}

SettingsGroupLayout {
Expand Down
Loading