Skip to content

Commit

Permalink
Refinements to improved map canvas handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Apr 10, 2024
1 parent 04e8d34 commit 16ee189
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/qml/DashBoard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Drawer {
clip: true

onShowMenu: mainMenu.popup(settingsButton.x + 2, mainWindow.sceneTopMargin + settingsButton.y + 2)
onShowCloudMenu: cloudPopup.show()
onShowCloudMenu: qfieldCloudPopup.show()

onActiveLayerChanged: {
if (activeLayer && activeLayer.readOnly && stateMachine.state == "digitize")
Expand Down
137 changes: 67 additions & 70 deletions src/qml/MapCanvas.qml
Original file line number Diff line number Diff line change
Expand Up @@ -122,74 +122,11 @@ Item {
rotationTresholdReached = true
}
}


MouseArea {
id: mouseArea
enabled: interactive && !hovered && !pinchArea.isDragging
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton

property bool longPressActive: false
property bool doublePressed: false

Timer {
id: timer
interval: 350
repeat: false

property var tapPoint

onTriggered: {
confirmedClicked(tapPoint)
}
}

onClicked: (mouse) => {
if (mouse.button === Qt.RightButton)
{
mapArea.rightClicked(Qt.point(mouse.x, mouse.y), "touch")
}
else
{
timer.tapPoint = Qt.point(mouse.x, mouse.y)
timer.restart()
}
}

onPressAndHold: (mouse) => {
mapArea.longPressed(Qt.point(mouse.x, mouse.y), "touch")
longPressActive = true
}

onPressed: (mouse) => {
if (mouse.button !== Qt.RightButton) {
if (timer.running) {
timer.stop()
doublePressed = true
} else {
doublePressed = false
}
}
}

onReleased: (mouse) => {
if (mouse.button !== Qt.RightButton) {
if (doublePressed) {
mapCanvasWrapper.zoom(Qt.point(mouse.x, mouse.y), 0.8)
}
}
}

onCanceled: {
timer.stop()
}
}
}

// stylus clicks
TapHandler {
enabled: interactive && hovered && !pinchArea.isDragging
id: stylusTapHandler
enabled: interactive && !pinchArea.isDragging
grabPermissions: PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByAnything | PointerHandler.ApprovesCancellation
acceptedDevices: !qfieldSettings.mouseAsTouchScreen ? PointerDevice.Stylus | PointerDevice.Mouse : PointerDevice.Stylus
acceptedButtons: Qt.LeftButton | Qt.RightButton
Expand Down Expand Up @@ -225,7 +162,7 @@ Item {
enabled: interactive && !freehandDigitizing && !pinchArea.isDragging
target: null
grabPermissions: PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByHandlersOfDifferentType
acceptedDevices: PointerDevice.Stylus | PointerDevice.Mouse
acceptedDevices: !qfieldSettings.mouseAsTouchScreen ? PointerDevice.Stylus | PointerDevice.Mouse : PointerDevice.Stylus
acceptedButtons: Qt.NoButton | Qt.LeftButton
dragThreshold: 5

Expand All @@ -238,7 +175,7 @@ Item {

onActiveChanged: {
if (active) {
if (mouseArea.doublePressed) {
if (mainTapHandler.doublePressed) {
oldTranslationY = 0
zoomCenter = centroid.position
isZooming = true
Expand Down Expand Up @@ -270,12 +207,72 @@ Item {
}
}

Timer {
id: timer
interval: 350
repeat: false

property var tapPoint

onTriggered: {
mainTapHandler.doublePressed = false
confirmedClicked(tapPoint)
}
}

TapHandler {
id: mainTapHandler
enabled: interactive && !hovered && !pinchArea.isDragging
acceptedButtons: Qt.NoButton | Qt.LeftButton | Qt.RightButton
grabPermissions: PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByHandlersOfDifferentType
acceptedDevices: !qfieldSettings.mouseAsTouchScreen ? PointerDevice.TouchScreen : PointerDevice.TouchScreen | PointerDevice.Mouse

property bool longPressActive: false
property bool doublePressed: false

onLongPressed: {
mapArea.longPressed(Qt.point(point.position.x, point.position.y), "touch")
longPressActive = true
}

onPressedChanged: {
if (pressed) {
if (point.pressedButtons !== Qt.RightButton) {
if (timer.running) {
timer.stop()
doublePressed = true
} else {
doublePressed = false
}
}
}
}

onTapped: (eventPoint, button) => {
if (button === Qt.RightButton) {
mapArea.rightClicked(Qt.point(mouse.x, mouse.y), "touch")
} else {
if (!doublePressed) {
timer.tapPoint = Qt.point(eventPoint.position.x, eventPoint.position.y)
timer.restart()
} else {
mapCanvasWrapper.zoom(Qt.point(eventPoint.position.x, eventPoint.position.y), 0.8)
}
}
}

onCanceled: {
timer.stop()
}
}

DragHandler {
id: mainDragHandler
enabled: interactive && !freehandDigitizing && !pinchArea.isDragging
enabled: interactive && !hovered && !freehandDigitizing && !pinchArea.isDragging
target: null
acceptedButtons: Qt.NoButton | Qt.LeftButton
acceptedDevices: PointerDevice.TouchScreen
grabPermissions: PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByHandlersOfDifferentType
acceptedDevices: !qfieldSettings.mouseAsTouchScreen ? PointerDevice.TouchScreen : PointerDevice.TouchScreen | PointerDevice.Mouse
dragThreshold: 5

property var oldPos
Expand All @@ -287,7 +284,7 @@ Item {

onActiveChanged: {
if (active) {
if (mouseArea.doublePressed) {
if (mainTapHandler.doublePressed) {
oldTranslationY = 0
zoomCenter = centroid.position
isZooming = true
Expand Down
14 changes: 11 additions & 3 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,15 @@ ApplicationWindow {
/* The map canvas */
MapCanvas {
id: mapCanvasMap
property bool isEnabled: !dashBoard.opened && !welcomeScreen.visible && !qfieldSettings.visible && !qfieldLocalDataPickerScreen.visible && !qfieldCloudScreen.visible && !cloudPopup.visible && !codeReader.visible && !sketcher.visible
property bool isEnabled: !dashBoard.opened &&
!welcomeScreen.visible &&
!qfieldSettings.visible &&
!qfieldLocalDataPickerScreen.visible &&
!qfieldCloudScreen.visible &&
!qfieldCloudPopup.visible &&
!codeReader.visible &&
!sketcher.visible &&
!overlayFeatureFormDrawer.visible
interactive: isEnabled && !screenLocker.enabled
incrementalRendering: true
quality: qfieldSettings.quality
Expand Down Expand Up @@ -3447,7 +3455,7 @@ ApplicationWindow {
}

if (cloudProjectsModel.layerObserver.deltaFileWrapper.hasError()) {
cloudPopup.show()
qfieldCloudPopup.show()
}

if (cloudConnection.status === QFieldCloudConnection.LoggedIn) {
Expand Down Expand Up @@ -3781,7 +3789,7 @@ ApplicationWindow {
}

QFieldCloudPopup {
id: cloudPopup
id: qfieldCloudPopup
visible: false
focus: visible
parent: Overlay.overlay
Expand Down

0 comments on commit 16ee189

Please sign in to comment.