diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 1772719a30ba29180ccaef479af83d4b8bc4d320..b1ee3d094729b6f7fdd6b362cadb9908f644df23 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -659,6 +659,8 @@ HEADERS += \ src/QmlControls/RCToParamDialogController.h \ src/QmlControls/ScreenToolsController.h \ src/QmlControls/TerrainProfile.h \ + src/QmlControls/ToolStripAction.h \ + src/QmlControls/ToolStripActionList.h \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \ src/Settings/ADSBVehicleManagerSettings.h \ src/Settings/AppSettings.h \ @@ -867,6 +869,8 @@ SOURCES += \ src/QmlControls/RCToParamDialogController.cc \ src/QmlControls/ScreenToolsController.cc \ src/QmlControls/TerrainProfile.cc \ + src/QmlControls/ToolStripAction.cc \ + src/QmlControls/ToolStripActionList.cc \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc \ src/Settings/ADSBVehicleManagerSettings.cc \ src/Settings/AppSettings.cc \ diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 1d2f9aaa3c35df87c1805a48d2ed948d85268699..bdf6dfecf134a52602776d30b3d358923b123a33 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -203,12 +203,19 @@ src/FlightDisplay/FlyViewMissionCompleteDialog.qml src/FlightDisplay/FlyViewPreFlightChecklistPopup.qml src/FlightDisplay/FlyViewToolStrip.qml + src/FlightDisplay/FlyViewToolStripActionList.qml src/FlightDisplay/FlyViewVideo.qml src/FlightDisplay/FlyViewWidgetLayer.qml + src/FlightDisplay/GuidedActionActionList.qml src/FlightDisplay/GuidedActionConfirm.qml - src/FlightDisplay/GuidedActionList.qml src/FlightDisplay/GuidedActionsController.qml + src/FlightDisplay/GuidedActionLand.qml + src/FlightDisplay/GuidedActionList.qml + src/FlightDisplay/GuidedActionTakeoff.qml + src/FlightDisplay/GuidedActionPause.qml + src/FlightDisplay/GuidedActionRTL.qml src/FlightDisplay/GuidedAltitudeSlider.qml + src/FlightDisplay/GuidedToolStripAction.qml src/FlightDisplay/MultiVehicleList.qml src/FlightDisplay/MultiVehiclePanel.qml src/FlightDisplay/PreFlightBatteryCheck.qml @@ -216,6 +223,7 @@ src/FlightDisplay/PreFlightRCCheck.qml src/FlightDisplay/PreFlightSensorsHealthCheck.qml src/FlightDisplay/PreFlightSoundCheck.qml + src/FlightDisplay/PreFlightCheckListShowAction.qml src/FlightDisplay/TerrainProgress.qml src/FlightDisplay/VehicleWarnings.qml src/QmlControls/QGroundControl/FlightDisplay/qmldir diff --git a/src/FlightDisplay/FlyViewCustomLayer.qml b/src/FlightDisplay/FlyViewCustomLayer.qml index a123f475bc7addf30bd8f5ed7b2aab88328d49f3..a8ead7d3fd1b4b7e8758a32df9d64d3b2f853f67 100644 --- a/src/FlightDisplay/FlyViewCustomLayer.qml +++ b/src/FlightDisplay/FlyViewCustomLayer.qml @@ -34,8 +34,8 @@ import QGroundControl.Vehicle 1.0 Item { id: _root - property var parentToolInsets // These insets tell you what screen real estate is available for positioning the controls in your overlay - property var toolInsets: _toolInsets // These are the insets for your custom overlay additions + property var parentToolInsets // These insets tell you what screen real estate is available for positioning the controls in your overlay + property var totalToolInsets: _toolInsets // These are the insets for your custom overlay additions property var mapControl QGCToolInsets { diff --git a/src/FlightDisplay/FlyViewPreFlightChecklistPopup.qml b/src/FlightDisplay/FlyViewPreFlightChecklistPopup.qml index 22c4ba05c324056d701a721e8a3a8725ed913fc1..697d6047cc873825efabb7a27e7a6ed4320f9c54 100644 --- a/src/FlightDisplay/FlyViewPreFlightChecklistPopup.qml +++ b/src/FlightDisplay/FlyViewPreFlightChecklistPopup.qml @@ -27,10 +27,9 @@ Popup { clip: true } - property bool useChecklist: QGroundControl.settingsManager.appSettings.useChecklist.rawValue && QGroundControl.corePlugin.options.preFlightChecklistUrl.toString().length - property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle - property bool _enforceChecklist: useChecklist && QGroundControl.settingsManager.appSettings.enforceChecklist.rawValue + property bool _useChecklist: QGroundControl.settingsManager.appSettings.useChecklist.rawValue && QGroundControl.corePlugin.options.preFlightChecklistUrl.toString().length + property bool _enforceChecklist: _useChecklist && QGroundControl.settingsManager.appSettings.enforceChecklist.rawValue property bool _checklistComplete: _activeVehicle && (_activeVehicle.checkListState === Vehicle.CheckListPassed) on_ActiveVehicleChanged: _showPreFlightChecklistIfNeeded() diff --git a/src/FlightDisplay/FlyViewToolStrip.qml b/src/FlightDisplay/FlyViewToolStrip.qml index 674dd31271e37fd0c76a44f747220c80296ba2b3..c2b151f60ae44811a2dcd02a62a987155365a0f0 100644 --- a/src/FlightDisplay/FlyViewToolStrip.qml +++ b/src/FlightDisplay/FlyViewToolStrip.qml @@ -7,103 +7,26 @@ * ****************************************************************************/ -import QGroundControl 1.0 -import QGroundControl.Controls 1.0 +import QtQml.Models 2.12 + +import QGroundControl 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.FlightDisplay 1.0 ToolStrip { - title: qsTr("Fly") + id: _root + title: qsTr("Fly") property var guidedActionsController property var guidedActionList - property bool usePreFlightChecklist signal displayPreFlightChecklist - property bool _anyActionAvailable: guidedActionsController.showStartMission || guidedActionsController.showResumeMission || guidedActionsController.showChangeAlt || guidedActionsController.showLandAbort - property var _actionModel: [ - { - title: guidedActionsController.startMissionTitle, - text: guidedActionsController.startMissionMessage, - action: guidedActionsController.actionStartMission, - visible: guidedActionsController.showStartMission - }, - { - title: guidedActionsController.continueMissionTitle, - text: guidedActionsController.continueMissionMessage, - action: guidedActionsController.actionContinueMission, - visible: guidedActionsController.showContinueMission - }, - { - title: guidedActionsController.changeAltTitle, - text: guidedActionsController.changeAltMessage, - action: guidedActionsController.actionChangeAlt, - visible: guidedActionsController.showChangeAlt - }, - { - title: guidedActionsController.landAbortTitle, - text: guidedActionsController.landAbortMessage, - action: guidedActionsController.actionLandAbort, - visible: guidedActionsController.showLandAbort - } - ] - - model: [ - { - name: "Checklist", - iconSource: "/qmlimages/check.svg", - buttonVisible: usePreFlightChecklist, - buttonEnabled: usePreFlightChecklist && activeVehicle && !activeVehicle.armed, - }, - { - name: guidedActionsController.takeoffTitle, - iconSource: "/res/takeoff.svg", - buttonVisible: guidedActionsController.showTakeoff || !guidedActionsController.showLand, - buttonEnabled: guidedActionsController.showTakeoff, - action: guidedActionsController.actionTakeoff - }, - { - name: guidedActionsController.landTitle, - iconSource: "/res/land.svg", - buttonVisible: guidedActionsController.showLand && !guidedActionsController.showTakeoff, - buttonEnabled: guidedActionsController.showLand, - action: guidedActionsController.actionLand - }, - { - name: guidedActionsController.rtlTitle, - iconSource: "/res/rtl.svg", - buttonVisible: true, - buttonEnabled: guidedActionsController.showRTL, - action: guidedActionsController.actionRTL - }, - { - name: guidedActionsController.pauseTitle, - iconSource: "/res/pause-mission.svg", - buttonVisible: guidedActionsController.showPause, - buttonEnabled: guidedActionsController.showPause, - action: guidedActionsController.actionPause - }, - { - name: qsTr("Action"), - iconSource: "/res/action.svg", - buttonVisible: _anyActionAvailable, - buttonEnabled: true, - action: -1 - } - ] - - onClicked: { - if(index === 0) { - displayPreFlightChecklist() - } else { - guidedActionsController.closeAll() - var action = model[index].action - if (action === -1) { - guidedActionList.model = _actionModel - guidedActionList.visible = true - } else { - guidedActionsController.confirmAction(action) - } - } + FlyViewToolStripActionList { + id: flyViewToolStripActionList + onDisplayPreFlightChecklist: _root.displayPreFlightChecklist() } + + model: flyViewToolStripActionList.model } diff --git a/src/FlightDisplay/FlyViewToolStripActionList.qml b/src/FlightDisplay/FlyViewToolStripActionList.qml new file mode 100644 index 0000000000000000000000000000000000000000..e08227e3f70182553fef77d7f3e5ba4a09e57843 --- /dev/null +++ b/src/FlightDisplay/FlyViewToolStripActionList.qml @@ -0,0 +1,38 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QtQml.Models 2.12 + +import QGroundControl 1.0 +import QGroundControl.Controls 1.0 + +ToolStripActionList { + signal displayPreFlightChecklist + + model: [ + PreFlightCheckListShowAction { + onTriggered: displayPreFlightChecklist() + }, + GuidedActionTakeoff { + guidedController: guidedActionsController + }, + GuidedActionLand { + guidedController: guidedActionsController + }, + GuidedActionRTL { + guidedController: guidedActionsController + }, + GuidedActionPause { + guidedController: guidedActionsController + }, + GuidedActionActionList { + guidedController: guidedActionsController + } + ] +} diff --git a/src/FlightDisplay/FlyViewWidgetLayer.qml b/src/FlightDisplay/FlyViewWidgetLayer.qml index 99f4a4d2118da9b14ed08c725c7b34ed5438250f..2d0067e82cd6154667e8ffd1fe97e6c8c1cee7e9 100644 --- a/src/FlightDisplay/FlyViewWidgetLayer.qml +++ b/src/FlightDisplay/FlyViewWidgetLayer.qml @@ -38,7 +38,7 @@ Item { property var mapControl property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle - property var _planMasterController: mainWindow.planMasterControllerPlanView + property var _planMasterController: mainWindow.planMasterControllerFlyView property var _missionController: _planMasterController.missionController property var _geoFenceController: _planMasterController.geoFenceController property var _rallyPointController: _planMasterController.rallyPointController @@ -115,7 +115,6 @@ Item { maxHeight: parent.height - y - parentToolInsets.leftEdgeBottomInset - _toolsMargin guidedActionsController: _guidedController guidedActionList: _guidedActionList - usePreFlightChecklist: preFlightChecklistPopup.useChecklist visible: !QGroundControl.videoManager.fullScreen onDisplayPreFlightChecklist: preFlightChecklistPopup.open() diff --git a/src/FlightDisplay/GuidedActionActionList.qml b/src/FlightDisplay/GuidedActionActionList.qml new file mode 100644 index 0000000000000000000000000000000000000000..383e8a920e7c0ffd385dde5b09c46662e5b919d7 --- /dev/null +++ b/src/FlightDisplay/GuidedActionActionList.qml @@ -0,0 +1,18 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl.FlightDisplay 1.0 + +GuidedToolStripAction { + text: guidedController.actionListTitle + iconSource: "/res/action.svg" + visible: guidedController.showActionList + enabled: true + actionID: guidedController.actionActionList +} diff --git a/src/FlightDisplay/GuidedActionLand.qml b/src/FlightDisplay/GuidedActionLand.qml new file mode 100644 index 0000000000000000000000000000000000000000..164598bc7dae3c16417a0b38213eb620474e7f69 --- /dev/null +++ b/src/FlightDisplay/GuidedActionLand.qml @@ -0,0 +1,19 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl.FlightDisplay 1.0 + +GuidedToolStripAction { + text: guidedController.landTitle + message: guidedController.landMessage + iconSource: "/res/land.svg" + visible: guidedController.showLand && !guidedController.showTakeoff + enabled: guidedController.showLand + actionID: guidedController.actionLand +} diff --git a/src/FlightDisplay/GuidedActionList.qml b/src/FlightDisplay/GuidedActionList.qml index c4a43e734db8e04f18fa061d0394cfdb597cdd97..f72e2532e09bcbb18f6e1d89cd08a13fe4b3b0e5 100644 --- a/src/FlightDisplay/GuidedActionList.qml +++ b/src/FlightDisplay/GuidedActionList.qml @@ -14,6 +14,7 @@ import QtQuick.Layouts 1.2 import QGroundControl 1.0 import QGroundControl.ScreenTools 1.0 import QGroundControl.Controls 1.0 +import QGroundControl.FlightDisplay 1.0 import QGroundControl.Palette 1.0 /// Dialog showing list of available guided actions @@ -28,12 +29,41 @@ Rectangle { property var guidedController property var altitudeSlider - property alias model: actionRepeater.model + + function show() { + visible = true + } property real _margins: Math.round(ScreenTools.defaultFontPixelHeight * 0.66) property real _actionWidth: ScreenTools.defaultFontPixelWidth * 25 property real _actionHorizSpacing: ScreenTools.defaultFontPixelHeight * 2 + property var _model: [ + { + title: guidedController.startMissionTitle, + text: guidedController.startMissionMessage, + action: guidedController.actionStartMission, + visible: guidedController.showStartMission + }, + { + title: guidedController.continueMissionTitle, + text: guidedController.continueMissionMessage, + action: guidedController.actionContinueMission, + visible: guidedController.showContinueMission + }, + { + title: guidedController.changeAltTitle, + text: guidedController.changeAltMessage, + action: guidedController.actionChangeAlt, + visible: guidedController.showChangeAlt + }, + { + title: guidedController.landAbortTitle, + text: guidedController.landAbortMessage, + action: guidedController.actionLandAbort, + visible: guidedController.showLandAbort + } + ] QGCPalette { id: qgcPal } @@ -67,7 +97,8 @@ Rectangle { spacing: _actionHorizSpacing Repeater { - id: actionRepeater + id: actionRepeater + model: _model ColumnLayout { spacing: ScreenTools.defaultFontPixelHeight / 2 diff --git a/src/FlightDisplay/GuidedActionPause.qml b/src/FlightDisplay/GuidedActionPause.qml new file mode 100644 index 0000000000000000000000000000000000000000..ce908040aa0ff535a5dcf7ad34fd1c051b95393b --- /dev/null +++ b/src/FlightDisplay/GuidedActionPause.qml @@ -0,0 +1,18 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl.FlightDisplay 1.0 + +GuidedToolStripAction { + text: guidedController.pauseTitle + iconSource: "/res/pause-mission.svg" + visible: guidedController.showPause + enabled: guidedController.showPause + actionID: guidedController.actionPause +} diff --git a/src/FlightDisplay/GuidedActionRTL.qml b/src/FlightDisplay/GuidedActionRTL.qml new file mode 100644 index 0000000000000000000000000000000000000000..7280edd6eb339506175131a42308229c117276a4 --- /dev/null +++ b/src/FlightDisplay/GuidedActionRTL.qml @@ -0,0 +1,18 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl.FlightDisplay 1.0 + +GuidedToolStripAction { + text: guidedController.rtlTitle + iconSource: "/res/rtl.svg" + visible: true + enabled: guidedController.showRTL + actionID: guidedController.actionRTL +} diff --git a/src/FlightDisplay/GuidedActionTakeoff.qml b/src/FlightDisplay/GuidedActionTakeoff.qml new file mode 100644 index 0000000000000000000000000000000000000000..04805b21c4f55a99766b8e059f8b6e5cc9a50089 --- /dev/null +++ b/src/FlightDisplay/GuidedActionTakeoff.qml @@ -0,0 +1,18 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl.FlightDisplay 1.0 + +GuidedToolStripAction { + text: guidedController.takeoffTitle + iconSource: "/res/takeoff.svg" + visible: guidedController.showTakeoff || !guidedController.showLand + enabled: guidedController.showTakeoff + actionID: guidedController.actionTakeoff +} diff --git a/src/FlightDisplay/GuidedActionsController.qml b/src/FlightDisplay/GuidedActionsController.qml index 1179b66e6778af75a47ba24a97054e9c1ecf1cac..9d52930a30de0bca6b55e171d6a5b89a00d57d11 100644 --- a/src/FlightDisplay/GuidedActionsController.qml +++ b/src/FlightDisplay/GuidedActionsController.qml @@ -52,6 +52,7 @@ Item { readonly property string gotoTitle: qsTr("Go To Location") readonly property string vtolTransitionTitle: qsTr("VTOL Transition") readonly property string roiTitle: qsTr("ROI") + readonly property string actionListTitle: qsTr("Action") readonly property string armMessage: qsTr("Arm the vehicle.") readonly property string disarmMessage: qsTr("Disarm the vehicle") @@ -95,6 +96,7 @@ Item { readonly property int actionVtolTransitionToFwdFlight: 20 readonly property int actionVtolTransitionToMRFlight: 21 readonly property int actionROI: 22 + readonly property int actionActionList: 23 property bool _useChecklist: QGroundControl.settingsManager.appSettings.useChecklist.rawValue && QGroundControl.corePlugin.options.preFlightChecklistUrl.toString().length property bool _enforceChecklist: _useChecklist && QGroundControl.settingsManager.appSettings.enforceChecklist.rawValue @@ -114,6 +116,7 @@ Item { property bool showROI: _guidedActionsEnabled && !_hideROI && _vehicleFlying && activeVehicle.roiModeSupported && !_missionActive property bool showLandAbort: _guidedActionsEnabled && _vehicleFlying && _fixedWingOnApproach property bool showGotoLocation: _guidedActionsEnabled && _vehicleFlying + property bool showActionList: _guidedActionsEnabled && (showStartMission || showResumeMission || showChangeAlt || showLandAbort) // Note: The '_missionItemCount - 2' is a hack to not trigger resume mission when a mission ends with an RTL item property bool showResumeMission: activeVehicle && !_vehicleArmed && _vehicleWasFlying && _missionAvailable && _resumeMissionIndex > 0 && (_resumeMissionIndex < _missionItemCount - 2) @@ -412,6 +415,9 @@ Item { confirmDialog.message = roiMessage confirmDialog.hideTrigger = Qt.binding(function() { return !showROI }) break; + case actionActionList: + actionList.show() + return default: console.warn("Unknown actionCode", actionCode) return diff --git a/src/FlightDisplay/GuidedToolStripAction.qml b/src/FlightDisplay/GuidedToolStripAction.qml new file mode 100644 index 0000000000000000000000000000000000000000..3b76dcfb9d890b828abac02785af259b1983e8fe --- /dev/null +++ b/src/FlightDisplay/GuidedToolStripAction.qml @@ -0,0 +1,27 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl.Controls 1.0 + +ToolStripAction { + property var guidedController + property int actionID + property string message + + onTriggered: { + guidedActionsController.closeAll() + if (actionID === -1) { + // FIXME: NYI + guidedActionList.model = _actionModel + guidedActionList.visible = true + } else { + guidedController.confirmAction(actionID) + } + } +} diff --git a/src/FlightDisplay/PreFlightCheckListShowAction.qml b/src/FlightDisplay/PreFlightCheckListShowAction.qml new file mode 100644 index 0000000000000000000000000000000000000000..8626a06fea8fc5f0ccdf083f74bb85d1c42f85f1 --- /dev/null +++ b/src/FlightDisplay/PreFlightCheckListShowAction.qml @@ -0,0 +1,21 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +import QGroundControl 1.0 +import QGroundControl.Controls 1.0 + +ToolStripAction { + text: qsTr("Checklist") + iconSource: "/qmlimages/check.svg" + visible: _useChecklist + enabled: _useChecklist && _activeVehicle && !_activeVehicle.armed + + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + property bool _useChecklist: QGroundControl.settingsManager.appSettings.useChecklist.rawValue && QGroundControl.corePlugin.options.preFlightChecklistUrl.toString().length +} diff --git a/src/PlanView/PlanView.qml b/src/PlanView/PlanView.qml index 2a71bb7bd1f11ed88b0b82d06ff58e72f74bce0e..560697f62498f35921f8d116f054eb56e313f685 100644 --- a/src/PlanView/PlanView.qml +++ b/src/PlanView/PlanView.qml @@ -277,13 +277,11 @@ Item { function insertROIAfterCurrent(coordinate) { var nextIndex = _missionController.currentPlanViewVIIndex + 1 _missionController.insertROIMissionItem(coordinate, nextIndex, true /* makeCurrentItem */) - _addROIOnClick = false } function insertCancelROIAfterCurrent() { var nextIndex = _missionController.currentPlanViewVIIndex + 1 _missionController.insertCancelROIMissionItem(nextIndex, true /* makeCurrentItem */) - _addROIOnClick = false } function insertComplexItemAfterCurrent(complexItemName) { @@ -421,8 +419,8 @@ Item { if (_addWaypointOnClick) { insertSimpleItemAfterCurrent(coordinate) } else if (_addROIOnClick) { - _addROIOnClick = false insertROIAfterCurrent(coordinate) + _addROIOnClick = false } break @@ -589,117 +587,95 @@ Item { property bool _isRallyLayer: _editingLayer == _layerRallyPoints property bool _isMissionLayer: _editingLayer == _layerMission - model: [ - /*{ - name: qsTr("Fly"), - iconSource: "/qmlimages/PaperPlane.svg", - buttonEnabled: true, - buttonVisible: true, - },*/ - { - name: qsTr("File"), - iconSource: "/qmlimages/MapSync.svg", - buttonEnabled: !_planMasterController.syncInProgress, - buttonVisible: true, - showAlternateIcon: _planMasterController.dirty, - alternateIconSource:"/qmlimages/MapSyncChanged.svg", - dropPanelComponent: syncDropPanel - }, - { - name: qsTr("Takeoff"), - iconSource: "/res/takeoff.svg", - buttonEnabled: _missionController.isInsertTakeoffValid, - buttonVisible: _isMissionLayer - }, - { - name: _editingLayer == _layerRallyPoints ? qsTr("Rally Point") : qsTr("Waypoint"), - iconSource: "/qmlimages/MapAddMission.svg", - buttonEnabled: _isRallyLayer ? true : _missionController.flyThroughCommandsAllowed, - buttonVisible: _isRallyLayer || _isMissionLayer, - toggle: true, - checked: _addWaypointOnClick - }, - { - name: _missionController.isROIActive ? qsTr("Cancel ROI") : qsTr("ROI"), - iconSource: "/qmlimages/MapAddMission.svg", - buttonEnabled: !_missionController.onlyInsertTakeoffValid, - buttonVisible: _isMissionLayer && _planMasterController.controllerVehicle.roiModeSupported, - toggle: !_missionController.isROIActive - }, - { - name: _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern"), - iconSource: "/qmlimages/MapDrawShape.svg", - buttonEnabled: _missionController.flyThroughCommandsAllowed, - buttonVisible: _isMissionLayer, - dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel - }, - { - name: _planMasterController.controllerVehicle.multiRotor ? qsTr("Return") : qsTr("Land"), - iconSource: "/res/rtl.svg", - buttonEnabled: _missionController.isInsertLandValid, - buttonVisible: _isMissionLayer - }, - { - name: qsTr("Center"), - iconSource: "/qmlimages/MapCenter.svg", - buttonEnabled: true, - buttonVisible: true, - dropPanelComponent: centerMapDropPanel - } - ] + ToolStripActionList { + id: toolStripActionList + model: [ + ToolStripAction { + text: qsTr("File") + enabled: !_planMasterController.syncInProgress + visible: true + showAlternateIcon: _planMasterController.dirty + iconSource: "/qmlimages/MapSync.svg" + alternateIconSource: "/qmlimages/MapSyncChanged.svg" + dropPanelComponent: syncDropPanel + }, + ToolStripAction { + text: qsTr("Takeoff") + iconSource: "/res/takeoff.svg" + enabled: _missionController.isInsertTakeoffValid + visible: toolStrip._isMissionLayer + onTriggered: { + toolStrip.allAddClickBoolsOff() + insertTakeItemAfterCurrent() + } + }, + ToolStripAction { + text: _editingLayer == _layerRallyPoints ? qsTr("Rally Point") : qsTr("Waypoint") + iconSource: "/qmlimages/MapAddMission.svg" + enabled: toolStrip._isRallyLayer ? true : _missionController.flyThroughCommandsAllowed + visible: toolStrip._isRallyLayer || toolStrip._isMissionLayer + checkable: true + onCheckedChanged: _addWaypointOnClick = checked + property bool myAddWaypointOnClick: _addWaypointOnClick + onMyAddWaypointOnClickChanged: checked = _addWaypointOnClick + }, + ToolStripAction { + text: _missionController.isROIActive ? qsTr("Cancel ROI") : qsTr("ROI") + iconSource: "/qmlimages/MapAddMission.svg" + enabled: !_missionController.onlyInsertTakeoffValid + visible: toolStrip._isMissionLayer && _planMasterController.controllerVehicle.roiModeSupported + checkable: !_missionController.isROIActive + onCheckedChanged: _addROIOnClick = checked + onTriggered: { + if (_missionController.isROIActive) { + toolStrip.allAddClickBoolsOff() + insertCancelROIAfterCurrent() + } + } + property bool myAddROIOnClick: _addROIOnClick + onMyAddROIOnClickChanged: checked = _addROIOnClick + }, + ToolStripAction { + text: _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern") + iconSource: "/qmlimages/MapDrawShape.svg" + enabled: _missionController.flyThroughCommandsAllowed + visible: toolStrip._isMissionLayer + dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel + onTriggered: { + toolStrip.allAddClickBoolsOff() + if (_singleComplexItem) { + insertComplexItemAfterCurrent(_missionController.complexMissionItemNames[0]) + } + } + }, + ToolStripAction { + text: _planMasterController.controllerVehicle.multiRotor ? qsTr("Return") : qsTr("Land") + iconSource: "/res/rtl.svg" + enabled: _missionController.isInsertLandValid + visible: toolStrip._isMissionLayer + onTriggered: { + toolStrip.allAddClickBoolsOff() + insertLandItemAfterCurrent() + } + }, + ToolStripAction { + text: qsTr("Center") + iconSource: "/qmlimages/MapCenter.svg" + enabled: true + visible: true + dropPanelComponent: centerMapDropPanel + } + ] + } + + model: toolStripActionList.model function allAddClickBoolsOff() { _addROIOnClick = false _addWaypointOnClick = false } - onClicked: { - switch (index) { - /*case flyButtonIndex: - mainWindow.showFlyView() - break*/ - case takeoffButtonIndex: - allAddClickBoolsOff() - insertTakeItemAfterCurrent() - break - case waypointButtonIndex: - if (_addWaypointOnClick) { - allAddClickBoolsOff() - setChecked(index, false) - } else { - allAddClickBoolsOff() - _addWaypointOnClick = checked - } - break - case roiButtonIndex: - if (_addROIOnClick) { - allAddClickBoolsOff() - setChecked(index, false) - } else { - allAddClickBoolsOff() - if (_missionController.isROIActive) { - insertCancelROIAfterCurrent() - } else { - _addROIOnClick = checked - } - } - break - case patternButtonIndex: - allAddClickBoolsOff() - if (_singleComplexItem) { - insertComplexItemAfterCurrent(_missionController.complexMissionItemNames[0]) - } - break - case landButtonIndex: - allAddClickBoolsOff() - insertLandItemAfterCurrent() - break - } - } - - onDropped: { - allAddClickBoolsOff() - } + onDropped: allAddClickBoolsOff() } //----------------------------------------------------------- @@ -879,26 +855,6 @@ Item { } } - /*MissionItemStatus { - id: waypointValuesDisplay - anchors.margins: _toolsMargin - anchors.left: toolStrip.right - anchors.bottom: mapScale.top - height: ScreenTools.defaultFontPixelHeight * 7 - maxWidth: rightPanel.x - x - anchors.margins - missionController: _missionController - visible: _internalVisible && _editingLayer === _layerMission && QGroundControl.corePlugin.options.showMissionStatus - - onSetCurrentSeqNum: _missionController.setCurrentPlanViewSeqNum(seqNum, true) - - property bool _internalVisible: _planViewSettings.showMissionItemStatus.rawValue - - function toggleVisible() { - _internalVisible = !_internalVisible - _planViewSettings.showMissionItemStatus.rawValue = _internalVisible - } - }*/ - TerrainStatus { id: terrainStatus anchors.margins: _toolsMargin @@ -929,7 +885,6 @@ Item { buttonsOnLeft: true terrainButtonVisible: _editingLayer === _layerMission terrainButtonChecked: terrainStatus.visible - //z: QGroundControl.zOrderMapItems onTerrainButtonClicked: terrainStatus.toggleVisible() } } diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 249062a8bf1ab7e29f7fd8f3343b6d969dd4a584..526fab0aabc868c89b48a47c243b3ae283edf6d0 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -106,6 +106,8 @@ #include "RCToParamDialogController.h" #include "QGCImageProvider.h" #include "TerrainProfile.h" +#include "ToolStripAction.h" +#include "ToolStripActionList.h" #if defined(QGC_ENABLE_PAIRING) #include "PairingManager.h" @@ -559,6 +561,8 @@ void QGCApplication::_initCommon() qmlRegisterType (kQGCControllers, 1, 0, "RCToParamDialogController"); qmlRegisterType ("QGroundControl.Controls", 1, 0, "TerrainProfile"); + qmlRegisterType ("QGroundControl.Controls", 1, 0, "ToolStripAction"); + qmlRegisterType ("QGroundControl.Controls", 1, 0, "ToolStripActionList"); #ifndef __mobile__ #ifndef NO_SERIAL_LINK diff --git a/src/QmlControls/DropPanel.qml b/src/QmlControls/DropPanel.qml index 2137ccc6803e482048cc63af54a84ff8e52695b7..068fe55679034d28853cd1729ea35080a248cb7e 100644 --- a/src/QmlControls/DropPanel.qml +++ b/src/QmlControls/DropPanel.qml @@ -40,8 +40,10 @@ Item { property real _viewportMaxBottom: parent.parent.height - parent.y property real _viewportMaxHeight: _viewportMaxBottom - _viewportMaxTop property var _dropPanelCancel + property var _parentButton - function show(panelEdgeTopPoint, panelComponent) { + function show(panelEdgeTopPoint, panelComponent, parentButton) { + _parentButton = parentButton _dropEdgeTopPoint = panelEdgeTopPoint _dropDownComponent = panelComponent _calcPositions() @@ -52,13 +54,9 @@ Item { function hide() { if (_dropPanelCancel) { _dropPanelCancel.destroy() - } - if (visible) { + _parentButton.checked = false visible = false _dropDownComponent = undefined - if (toolStrip.lastClickedButton) { - toolStrip.lastClickedButton.checked = false - } } } diff --git a/src/QmlControls/QGroundControl/FlightDisplay/qmldir b/src/QmlControls/QGroundControl/FlightDisplay/qmldir index 073474cb854a6e5b242712ea3e579da90433de46..662b1b19011e8febbfd51242e67dc8a33e5086a3 100644 --- a/src/QmlControls/QGroundControl/FlightDisplay/qmldir +++ b/src/QmlControls/QGroundControl/FlightDisplay/qmldir @@ -9,12 +9,19 @@ FlyViewMap 1.0 FlyViewMap.qml FlyViewMissionCompleteDialog 1.0 FlyViewMissionCompleteDialog.qml FlyViewPreFlightChecklistPopup 1.0 FlyViewPreFlightChecklistPopup.qml FlyViewToolStrip 1.0 FlyViewToolStrip.qml +FlyViewToolStripActionList 1.0 FlyViewToolStripActionList.qml FlyViewVideo 1.0 FlyViewVideo.qml FlyViewWidgetLayer 1.0 FlyViewWidgetLayer.qml +GuidedActionActionList 1.0 GuidedActionActionList.qml GuidedActionConfirm 1.0 GuidedActionConfirm.qml -GuidedActionList 1.0 GuidedActionList.qml GuidedActionsController 1.0 GuidedActionsController.qml +GuidedActionLand 1.0 GuidedActionLand.qml +GuidedActionList 1.0 GuidedActionList.qml +GuidedActionPause 1.0 GuidedActionPause.qml +GuidedActionRTL 1.0 GuidedActionRTL.qml GuidedAltitudeSlider 1.0 GuidedAltitudeSlider.qml +GuidedActionTakeoff 1.0 GuidedActionTakeoff.qml +GuidedToolStripAction 1.0 GuidedToolStripAction.qml MultiVehicleList 1.0 MultiVehicleList.qml MultiVehiclePanel 1.0 MultiVehiclePanel.qml PreFlightBatteryCheck 1.0 PreFlightBatteryCheck.qml diff --git a/src/QmlControls/ToolStrip.qml b/src/QmlControls/ToolStrip.qml index 249d7318f030fda568c091974878bec56a7e67ea..4740836b77b32c429e0310141a4c78378b2fbbcd 100644 --- a/src/QmlControls/ToolStrip.qml +++ b/src/QmlControls/ToolStrip.qml @@ -26,35 +26,16 @@ Rectangle { property real maxHeight ///< Maximum height for control, determines whether text is hidden to make control shorter property alias title: titleLabel.text - property AbstractButton lastClickedButton: null - function simulateClick(buttonIndex) { buttonIndex = buttonIndex + 1 // skip over title - if (!toolStripColumn.children[buttonIndex].checked) { - toolStripColumn.children[buttonIndex].checked = true - toolStripColumn.children[buttonIndex].clicked() - } + toolStripColumn.children[buttonIndex].clicked() } // Ensure we don't get narrower than content property real _idealWidth: (ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 8) + toolStripColumn.anchors.margins * 2 - signal clicked(int index, bool checked) signal dropped(int index) - function setChecked(idx, check) { - repeater.itemAt(idx).checked = check - } - - function getChecked(idx) { - return repeater.itemAt(idx).checked - } - - ButtonGroup { - id: buttonGroup - buttons: toolStripColumn.children - } - DeadMouseArea { anchors.fill: parent } @@ -98,27 +79,25 @@ Rectangle { fontPointSize: ScreenTools.smallFontPointSize autoExclusive: true - enabled: modelData.buttonEnabled - visible: modelData.buttonVisible + enabled: modelData.enabled + visible: modelData.visible imageSource: modelData.showAlternateIcon ? modelData.alternateIconSource : modelData.iconSource - text: modelData.name - checked: modelData.checked !== undefined ? modelData.checked : checked + text: modelData.text + checked: modelData.checked + checkable: modelData.dropPanelComponent || modelData.checkable - ButtonGroup.group: buttonGroup - // Only drop panel and toggleable are checkable - checkable: modelData.dropPanelComponent !== undefined || (modelData.toggle !== undefined && modelData.toggle) + onCheckedChanged: modelData.checked = checked onClicked: { - dropPanel.hide() // DropPanel will call hide on "lastClickedButton" - if (modelData.dropPanelComponent === undefined) { - _root.clicked(index, checked) + dropPanel.hide() + if (!modelData.dropPanelComponent) { + modelData.triggered(this) } else if (checked) { var panelEdgeTopPoint = mapToItem(_root, width, 0) - dropPanel.show(panelEdgeTopPoint, modelData.dropPanelComponent) + dropPanel.show(panelEdgeTopPoint, modelData.dropPanelComponent, this) + checked = true _root.dropped(index) } - if(_root && buttonTemplate) - _root.lastClickedButton = buttonTemplate } } } diff --git a/src/QmlControls/ToolStripAction.cc b/src/QmlControls/ToolStripAction.cc new file mode 100644 index 0000000000000000000000000000000000000000..97fd27cc45bff609beee2a8aba602ee197e5a784 --- /dev/null +++ b/src/QmlControls/ToolStripAction.cc @@ -0,0 +1,92 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#include "ToolStripAction.h" + +ToolStripAction::ToolStripAction(QObject* parent) + : QObject(parent) +{ + +} + +void ToolStripAction::setEnabled(bool enabled) +{ + if (enabled != _enabled) { + _enabled = enabled; + emit enabledChanged(enabled); + } +} + +void ToolStripAction::setVisible(bool visible) +{ + if (visible != _visible) { + _visible = visible; + emit visibleChanged(visible); + } + +} + +void ToolStripAction::setCheckable(bool checkable) +{ + if (checkable != _checkable) { + _checkable = checkable; + emit checkableChanged(checkable); + } + +} + +void ToolStripAction::setChecked(bool checked) +{ + if (checked != _checked) { + _checked = checked; + emit checkedChanged(checked); + } + +} + +void ToolStripAction::setShowAlternateIcon(bool showAlternateIcon) +{ + if (showAlternateIcon != _showAlternateIcon) { + _showAlternateIcon = showAlternateIcon; + emit showAlternateIconChanged(showAlternateIcon); + } + +} + +void ToolStripAction::setText(const QString& text) +{ + if (text != _text) { + _text = text; + emit textChanged(text); + } + +} + +void ToolStripAction::setIconSource(const QString& iconSource) +{ + if (iconSource != _iconSource) { + _iconSource = iconSource; + emit iconSourceChanged(iconSource); + } + +} + +void ToolStripAction::setAlternateIconSource(const QString& alternateIconSource) +{ + if (alternateIconSource != _alternateIconSource) { + _alternateIconSource = alternateIconSource; + emit alternateIconSourceChanged(alternateIconSource); + } +} + +void ToolStripAction::setDropPanelComponent(QQmlComponent* dropPanelComponent) +{ + _dropPanelComponent = dropPanelComponent; + emit dropPanelComponentChanged(); +} diff --git a/src/QmlControls/ToolStripAction.h b/src/QmlControls/ToolStripAction.h new file mode 100644 index 0000000000000000000000000000000000000000..8fb3098899a34467c54c32f2321b29228460b8fb --- /dev/null +++ b/src/QmlControls/ToolStripAction.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#pragma once + +#include +#include +#include + +class ToolStripAction : public QObject +{ + Q_OBJECT + +public: + ToolStripAction(QObject* parent = nullptr); + + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged) + Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged) + Q_PROPERTY(bool showAlternateIcon READ showAlternateIcon WRITE setShowAlternateIcon NOTIFY showAlternateIconChanged) + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QString iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged) + Q_PROPERTY(QString alternateIconSource READ alternateIconSource WRITE setAlternateIconSource NOTIFY alternateIconSourceChanged) + Q_PROPERTY(QQmlComponent* dropPanelComponent READ dropPanelComponent WRITE setDropPanelComponent NOTIFY dropPanelComponentChanged) + + bool enabled (void) const { return _enabled; } + bool visible (void) const { return _visible; } + bool checkable (void) const { return _checkable; } + bool checked (void) const { return _checked; } + bool showAlternateIcon (void) const { return _showAlternateIcon; } + QString text (void) const { return _text; } + QString iconSource (void) const { return _iconSource; } + QString alternateIconSource (void) const { return _alternateIconSource; } + QQmlComponent* dropPanelComponent (void) const { return _dropPanelComponent; } + + void setEnabled (bool enabled); + void setVisible (bool visible); + void setCheckable (bool checkable); + void setChecked (bool checked); + void setShowAlternateIcon (bool showAlternateIcon); + void setText (const QString& text); + void setIconSource (const QString& iconSource); + void setAlternateIconSource (const QString& alternateIconSource); + void setDropPanelComponent (QQmlComponent* dropPanelComponent); + +signals: + void enabledChanged (bool enabled); + void visibleChanged (bool visible); + void checkableChanged (bool checkable); + void checkedChanged (bool checked); + void showAlternateIconChanged (bool showAlternateIcon); + void textChanged (QString text); + void iconSourceChanged (QString iconSource); + void alternateIconSourceChanged (QString alternateIconSource); + void triggered (QObject* source); + void dropPanelComponentChanged (void); + +protected: + bool _enabled = true; + bool _visible = true; + bool _checkable = false; + bool _checked = false; + bool _showAlternateIcon = false; + QString _text; + QString _iconSource; + QString _alternateIconSource; + QQmlComponent* _dropPanelComponent = nullptr; +}; diff --git a/src/QmlControls/ToolStripActionList.cc b/src/QmlControls/ToolStripActionList.cc new file mode 100644 index 0000000000000000000000000000000000000000..842530567cfe1cdf9d326956cb1e65c91d83e58a --- /dev/null +++ b/src/QmlControls/ToolStripActionList.cc @@ -0,0 +1,41 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#include "ToolStripActionList.h" + +ToolStripActionList::ToolStripActionList(QObject* parent) + : QObject(parent) +{ + +} + +QQmlListProperty ToolStripActionList::model(void) +{ + return QQmlListProperty(this, this, + &ToolStripActionList::append, + &ToolStripActionList::count, + &ToolStripActionList::at, + &ToolStripActionList::clear); +} + +void ToolStripActionList::append(QQmlListProperty* qmlListProperty, QObject* value) { + reinterpret_cast(qmlListProperty->data)->_objectList.append(value); +} + +void ToolStripActionList::clear(QQmlListProperty* qmlListProperty) { + reinterpret_cast(qmlListProperty->data)->_objectList.clear(); +} + +QObject* ToolStripActionList::at(QQmlListProperty* qmlListProperty, int index) { + return reinterpret_cast(qmlListProperty->data)->_objectList[index]; +} + +int ToolStripActionList::count(QQmlListProperty* qmlListProperty) { + return reinterpret_cast(qmlListProperty->data)->_objectList.count(); +} diff --git a/src/QmlControls/ToolStripActionList.h b/src/QmlControls/ToolStripActionList.h new file mode 100644 index 0000000000000000000000000000000000000000..ac01765c1cb04d0e64220f63396fb3575aec1a0f --- /dev/null +++ b/src/QmlControls/ToolStripActionList.h @@ -0,0 +1,36 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#pragma once + +#include +#include + +class ToolStripActionList : public QObject +{ + Q_OBJECT + +public: + ToolStripActionList(QObject* parent = nullptr); + + Q_PROPERTY(QQmlListProperty model READ model NOTIFY modelChanged) + + QQmlListProperty model(); + +signals: + void modelChanged(void); + +private: + static void append (QQmlListProperty* qmlListProperty, QObject* value); + static int count (QQmlListProperty* qmlListProperty); + static QObject* at (QQmlListProperty*, int index); + static void clear (QQmlListProperty* qmlListProperty); + + QList _objectList; +};