Skip to content

Commit

Permalink
Switch to new DropPanel control
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Feb 11, 2025
1 parent d78f6d8 commit cfd7f34
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 208 deletions.
267 changes: 115 additions & 152 deletions src/FlightDisplay/FlyViewMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -542,185 +544,146 @@ 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)) }
}
}
}
}
}

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()
}
}

Expand Down
Loading

0 comments on commit cfd7f34

Please sign in to comment.