From 532bac92d2f137edea7b4c1a50ca0cd0d34c3f17 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 10 Feb 2025 11:42:34 -0800 Subject: [PATCH] Switch to new DropPanel control --- src/FlightDisplay/FlyViewMap.qml | 267 +++++++++++++---------------- src/PlanView/MissionItemEditor.qml | 143 +++++++++------ src/PlanView/PlanView.qml | 2 +- 3 files changed, 204 insertions(+), 208 deletions(-) diff --git a/src/FlightDisplay/FlyViewMap.qml b/src/FlightDisplay/FlyViewMap.qml index 5aabb6db1018..f4ca80762f96 100644 --- a/src/FlightDisplay/FlyViewMap.qml +++ b/src/FlightDisplay/FlyViewMap.qml @@ -500,10 +500,12 @@ FlightMap { MouseArea { anchors.fill: parent onClicked: (position) => { - var roiEditMenu = popupMenuComponent.createObject(_root, { coord: roiLocationItem.coordinate, contentItemComponent: roiEditMenuComponent }) - var clickPoint = mapToItem(_root, position.x, position.y) - roiEditMenu.setPosition(clickPoint.x, clickPoint.y) - roiEditMenu.open() + position = Qt.point(position.x, position.y) + var clickCoord = _root.toCoordinate(position, false /* clipToViewPort */) + // For some strange reason using mainWindow in mapToItem doesn't work, so we use globals.parent instead which also gets us mainWindow + position = mapToItem(globals.parent, position) + var dropPanel = roiEditDropPanelComponent.createObject(mainWindow, { clickRect: Qt.rect(position.x, position.y, 0, 0) }) + dropPanel.open() } } @@ -542,171 +544,129 @@ FlightMap { } Component { - id: popupMenuComponent - - Popup { - id: mapClickMenu - modal: true - - property var coord - property var contentItemComponent - - function setPosition(mouseX, mouseY) { - var newX = mouseX - var newY = mouseY - - // Filtering coordinates - if (newX + mapClickMenu.width > _root.width) { - newX = _root.width - mapClickMenu.width - } - if (newY + mapClickMenu.height > _root.height) { - newY = _root.height - mapClickMenu.height - } - - // Set coordiantes - x = newX - y = newY - } - - background: Rectangle { - radius: ScreenTools.defaultFontPixelHeight * 0.5 - color: qgcPal.window - border.color: qgcPal.text - } - - contentItem: Loader { - sourceComponent: contentItemComponent + id: roiEditPositionDialogComponent - property var mapClickCoord: mapClickMenu.coord - property var popup: mapClickMenu + EditPositionDialog { + title: qsTr("Edit ROI Position") + coordinate: roiLocationItem.coordinate + onCoordinateChanged: { + roiLocationItem.coordinate = coordinate + _activeVehicle.guidedModeROI(coordinate) } } } Component { - id: mapClickMenuComponent - - ColumnLayout { - id: mainLayout - spacing: ScreenTools.defaultFontPixelWidth / 2 - - QGCButton { - Layout.fillWidth: true - text: qsTr("Go to location") - visible: globals.guidedControllerFlyView.showGotoLocation - onClicked: { - if (popup.opened) { - popup.close() + id: roiEditDropPanelComponent + + DropPanel { + id: roiEditDropPanel + + sourceComponent: Component { + ColumnLayout { + spacing: ScreenTools.defaultFontPixelWidth / 2 + + QGCButton { + Layout.fillWidth: true + text: qsTr("Cancel ROI") + onClicked: { + _activeVehicle.stopGuidedModeROI() + roiEditDropPanel.close() + } } - gotoLocationItem.show(mapClickCoord) - globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionGoto, mapClickCoord, gotoLocationItem) - } - } - QGCButton { - Layout.fillWidth: true - text: qsTr("Orbit at location") - visible: globals.guidedControllerFlyView.showOrbit - onClicked: { - if (popup.opened) { - popup.close() + QGCButton { + Layout.fillWidth: true + text: qsTr("Edit Position") + onClicked: { + roiEditPositionDialogComponent.createObject(mainWindow, { showSetPositionFromVehicle: false }).open() + roiEditDropPanel.close() + } } - orbitMapCircle.show(mapClickCoord) - globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionOrbit, mapClickCoord, orbitMapCircle) } } + } + } - QGCButton { - Layout.fillWidth: true - text: qsTr("ROI at location") - visible: globals.guidedControllerFlyView.showROI - onClicked: { - if (popup.opened) { - popup.close() + Component { + id: mapClickDropPanelComponent + + DropPanel { + id: mapClickDropPanel + + property var mapClickCoord + + sourceComponent: Component { + ColumnLayout { + spacing: ScreenTools.defaultFontPixelWidth / 2 + + QGCButton { + Layout.fillWidth: true + text: qsTr("Go to location") + visible: globals.guidedControllerFlyView.showGotoLocation + onClicked: { + mapClickDropPanel.close() + gotoLocationItem.show(mapClickCoord) + globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionGoto, mapClickCoord, gotoLocationItem) + } } - globals.guidedControllerFlyView.executeAction(globals.guidedControllerFlyView.actionROI, mapClickCoord, 0, false) - } - } - QGCButton { - Layout.fillWidth: true - text: qsTr("Set home here") - visible: globals.guidedControllerFlyView.showSetHome - onClicked: { - if (popup.opened) { - popup.close() + QGCButton { + Layout.fillWidth: true + text: qsTr("Orbit at location") + visible: globals.guidedControllerFlyView.showOrbit + onClicked: { + mapClickDropPanel.close() + orbitMapCircle.show(mapClickCoord) + globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionOrbit, mapClickCoord, orbitMapCircle) + } } - globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionSetHome, mapClickCoord) - } - } - QGCButton { - Layout.fillWidth: true - text: qsTr("Set Estimator Origin") - visible: globals.guidedControllerFlyView.showSetEstimatorOrigin - onClicked: { - if (popup.opened) { - popup.close() + QGCButton { + Layout.fillWidth: true + text: qsTr("ROI at location") + visible: globals.guidedControllerFlyView.showROI + onClicked: { + mapClickDropPanel.close() + globals.guidedControllerFlyView.executeAction(globals.guidedControllerFlyView.actionROI, mapClickCoord, 0, false) + } } - globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionSetEstimatorOrigin, mapClickCoord) - } - } - QGCButton { - Layout.fillWidth: true - text: qsTr("Set Heading") - visible: globals.guidedControllerFlyView.showChangeHeading - onClicked: { - if (popup.opened) { - popup.close() + QGCButton { + Layout.fillWidth: true + text: qsTr("Set home here") + visible: globals.guidedControllerFlyView.showSetHome + onClicked: { + mapClickDropPanel.close() + globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionSetHome, mapClickCoord) + } } - globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionChangeHeading, mapClickCoord) - } - } - - ColumnLayout { - spacing: 0 - QGCLabel { text: qsTr("Lat: %1").arg(mapClickCoord.latitude.toFixed(6)) } - QGCLabel { text: qsTr("Lon: %1").arg(mapClickCoord.longitude.toFixed(6)) } - } - } - } - - Component { - id: roiEditPositionDialogComponent - EditPositionDialog { - title: qsTr("Edit ROI Position") - coordinate: roiLocationItem.coordinate - onCoordinateChanged: { - roiLocationItem.coordinate = coordinate - _activeVehicle.guidedModeROI(coordinate) - } - } - } + QGCButton { + Layout.fillWidth: true + text: qsTr("Set Estimator Origin") + visible: globals.guidedControllerFlyView.showSetEstimatorOrigin + onClicked: { + mapClickDropPanel.close() + globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionSetEstimatorOrigin, mapClickCoord) + } + } - Component { - id: roiEditMenuComponent - - ColumnLayout { - id: mainLayout - spacing: ScreenTools.defaultFontPixelWidth / 2 - - QGCButton { - Layout.fillWidth: true - text: qsTr("Cancel ROI") - onClicked: { - _activeVehicle.stopGuidedModeROI() - popup.close() - } - } + QGCButton { + Layout.fillWidth: true + text: qsTr("Set Heading") + visible: globals.guidedControllerFlyView.showChangeHeading + onClicked: { + mapClickDropPanel.close() + globals.guidedControllerFlyView.confirmAction(globals.guidedControllerFlyView.actionChangeHeading, mapClickCoord) + } + } - QGCButton { - Layout.fillWidth: true - text: qsTr("Edit Position") - onClicked: { - roiEditPositionDialogComponent.createObject(mainWindow, { showSetPositionFromVehicle: false }).open() - popup.close() + ColumnLayout { + spacing: 0 + QGCLabel { text: qsTr("Lat: %1").arg(mapClickCoord.latitude.toFixed(6)) } + QGCLabel { text: qsTr("Lon: %1").arg(mapClickCoord.longitude.toFixed(6)) } + } } } } @@ -714,13 +674,16 @@ FlightMap { onMapClicked: (position) => { if (!globals.guidedControllerFlyView.guidedUIVisible && - (globals.guidedControllerFlyView.showGotoLocation || globals.guidedControllerFlyView.showOrbit || globals.guidedControllerFlyView.showROI || globals.guidedControllerFlyView.showSetHome || globals.guidedControllerFlyView.showSetEstimatorOrigin)) { + (globals.guidedControllerFlyView.showGotoLocation || globals.guidedControllerFlyView.showOrbit || globals.guidedControllerFlyView.showROI || globals.guidedControllerFlyView.showSetHome || globals.guidedControllerFlyView.showSetEstimatorOrigin)) { orbitMapCircle.hide() gotoLocationItem.hide() - var clickCoord = _root.toCoordinate(Qt.point(position.x, position.y), false /* clipToViewPort */) - var mapClickMenu = popupMenuComponent.createObject(_root, { coord: clickCoord, contentItemComponent: mapClickMenuComponent }) - mapClickMenu.setPosition(position.x, position.y) - mapClickMenu.open() + + position = Qt.point(position.x, position.y) + var clickCoord = _root.toCoordinate(position, false /* clipToViewPort */) + // For some strange reason using mainWindow in mapToItem doesn't work, so we use globals.parent instead which also gets us mainWindow + position = _root.mapToItem(globals.parent, position) + var dropPanel = mapClickDropPanelComponent.createObject(mainWindow, { mapClickCoord: clickCoord, clickRect: Qt.rect(position.x, position.y, 0, 0) }) + dropPanel.open() } } diff --git a/src/PlanView/MissionItemEditor.qml b/src/PlanView/MissionItemEditor.qml index e0f362a2a02f..726f177300d5 100644 --- a/src/PlanView/MissionItemEditor.qml +++ b/src/PlanView/MissionItemEditor.qml @@ -181,81 +181,114 @@ Rectangle { } } - QGCColoredImage { - id: hamburger - anchors.margins: _margin - anchors.right: parent.right - anchors.verticalCenter: topRowLayout.verticalCenter - width: _hamburgerSize - height: _hamburgerSize - sourceSize.height: _hamburgerSize - source: "qrc:/qmlimages/Hamburger.svg" - visible: missionItem.isCurrentItem && missionItem.sequenceNumber !== 0 - color: qgcPal.text + Component { + id: hamburgerMenuDropPanelComponent - QGCMouseArea { - fillItem: hamburger - onClicked: { - currentItemScope.focus = true - hamburgerMenu.popup() - } + DropPanel { + id: hamburgerMenuDropPanel - QGCMenu { - id: hamburgerMenu + sourceComponent: Component { + ColumnLayout { + spacing: ScreenTools.defaultFontPixelHeight / 2 - QGCMenuItem { - text: qsTr("Move to vehicle position") - enabled: _activeVehicle && missionItem.specifiesCoordinate - onTriggered: missionItem.coordinate = _activeVehicle.coordinate + QGCButton { + Layout.fillWidth: true + text: qsTr("Move to vehicle position") + enabled: _activeVehicle && missionItem.specifiesCoordinate - property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle - } + onClicked: { + missionItem.coordinate = _activeVehicle.coordinate + hamburgerMenuDropPanel.close() + } - QGCMenuItem { - text: qsTr("Move to previous item position") - enabled: _missionController.previousCoordinate.isValid - onTriggered: missionItem.coordinate = _missionController.previousCoordinate - } + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + } - QGCMenuItem { - text: qsTr("Edit position...") - enabled: missionItem.specifiesCoordinate - onTriggered: editPositionDialog.createObject(mainWindow).open() - } + QGCButton { + Layout.fillWidth: true + text: qsTr("Move to previous item position") + enabled: _missionController.previousCoordinate.isValid + onClicked: { + missionItem.coordinate = _missionController.previousCoordinate + hamburgerMenuDropPanel.close() + } + } - QGCMenuSeparator { - //visible: missionItem.isSimpleItem && !_waypointsOnlyMode - } + QGCButton { + Layout.fillWidth: true + text: qsTr("Edit position...") + enabled: missionItem.specifiesCoordinate + onClicked: { + editPositionDialog.createObject(mainWindow).open() + hamburgerMenuDropPanel.close() + } + } - QGCMenuItem { - text: qsTr("Show all values") - visible: QGroundControl.corePlugin.showAdvancedUI - checkable: true - checked: missionItem.isSimpleItem ? missionItem.rawEdit : false - enabled: missionItem.isSimpleItem && !_waypointsOnlyMode + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 1 + color: qgcPal.groupBorder + } + + QGCCheckBoxSlider { + Layout.fillWidth: true + text: qsTr("Show all values") + visible: QGroundControl.corePlugin.showAdvancedUI + checked: missionItem.isSimpleItem ? missionItem.rawEdit : false + enabled: missionItem.isSimpleItem && !_waypointsOnlyMode - onTriggered: { - if (missionItem.rawEdit) { - if (missionItem.friendlyEditAllowed) { + onClicked: { + missionItem.rawEdit = checked + if (missionItem.rawEdit && !missionItem.friendlyEditAllowed) { missionItem.rawEdit = false - } else { + checked = false mainWindow.showMessageDialog(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode")) } - } else { - missionItem.rawEdit = true + hamburgerMenuDropPanel.close() } - checked = missionItem.rawEdit } - } - QGCMenuItem { - text: qsTr("Item #%1").arg(missionItem.sequenceNumber) - enabled: false + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 1 + color: qgcPal.groupBorder + } + + QGCLabel { + text: qsTr("Item #%1").arg(missionItem.sequenceNumber) + enabled: false + } } } } } + + QGCColoredImage { + id: hamburger + anchors.margins: _margin + anchors.right: parent.right + anchors.verticalCenter: topRowLayout.verticalCenter + width: _hamburgerSize + height: _hamburgerSize + sourceSize.height: _hamburgerSize + source: "qrc:/qmlimages/Hamburger.svg" + visible: missionItem.isCurrentItem && missionItem.sequenceNumber !== 0 + color: qgcPal.text + + QGCMouseArea { + fillItem: hamburger + onClicked: (position) => { + currentItemScope.focus = true + position = Qt.point(position.x, position.y) + // For some strange reason using mainWindow in mapToItem doesn't work, so we use globals.parent instead which also gets us mainWindow + position = mapToItem(globals.parent, position) + var dropPanel = hamburgerMenuDropPanelComponent.createObject(mainWindow, { clickRect: Qt.rect(position.x, position.y, 0, 0) }) + dropPanel.open() + } + } + } + /* QGCLabel { id: notReadyForSaveLabel diff --git a/src/PlanView/PlanView.qml b/src/PlanView/PlanView.qml index bc25e8317544..12cc2e3a27a3 100644 --- a/src/PlanView/PlanView.qml +++ b/src/PlanView/PlanView.qml @@ -910,7 +910,7 @@ Item { UTMSPStateStorage.currentStateIndex = 0}}) } - //- ToolStrip DropPanel Components + //- ToolStrip ToolStripDropPanel Components Component { id: centerMapDropPanel