From 234fa611cb5ced5f3e10756e11dfb11737d47d04 Mon Sep 17 00:00:00 2001 From: Nick Exton Date: Tue, 14 Mar 2023 12:46:03 +1100 Subject: [PATCH] Add Custom Action settings to GeneralSettings UI page --- src/ui/preferences/GeneralSettings.qml | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index e915c58..5b081bb 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -188,6 +188,70 @@ Rectangle { property Fact _updateHomePosition: QGroundControl.settingsManager.flyViewSettings.updateHomePosition } + FactCheckBox { + text: qsTr("Enable Custom Actions") + visible: _enableCustomActions.visible + fact: _enableCustomActions + + property Fact _enableCustomActions: QGroundControl.settingsManager.flyViewSettings.enableCustomActions + } + + //----------------------------------------------------------------- + //-- CustomAction definition path + GridLayout { + id: customActions + + columns: 2 + visible: QGroundControl.settingsManager.flyViewSettings.enableCustomActions.rawValue + + onVisibleChanged: { + if (jsonFile.rawValue === "" && ScreenTools.isMobile) { + jsonFile.rawValue = _defaultFile + } + } + + property Fact jsonFile: QGroundControl.settingsManager.flyViewSettings.customActionDefinitions + property string _defaultDir: QGroundControl.settingsManager.appSettings.customActionsSavePath + property string _defaultFile: _defaultDir + "/CustomActions.json" + + QGCLabel { + text: qsTr("Custom Action Definitions") + + Layout.columnSpan: 2 + Layout.alignment: Qt.AlignHCenter + } + + QGCTextField { + Layout.fillWidth: true + readOnly: true + text: customActions.jsonFile.rawValue === "" ? qsTr("") : customActions.jsonFile.rawValue + } + QGCButton { + visible: !ScreenTools.isMobile + text: qsTr("Browse") + onClicked: customActionPathBrowseDialog.openForLoad() + QGCFileDialog { + id: customActionPathBrowseDialog + title: qsTr("Choose the Custom Action Definitions file") + folder: customActions.jsonFile.rawValue + selectExisting: true + selectFolder: false + onAcceptedForLoad: customActions.jsonFile.rawValue = file + nameFilters: ["JSON files (*.json)"] + } + } + // The file loader on Android doesn't work, so we hard code the path to the + // JSON file. However, we need a button to force a refresh if the JSON file + // is changed. + QGCButton { + visible: ScreenTools.isMobile + text: qsTr("Reload") + onClicked: { + customActions.jsonFile.valueChanged(customActions.jsonFile.rawValue) + } + } + } + GridLayout { columns: 2