From 16ee189f8543c40952f00d94e67e927609468a3b Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Wed, 10 Apr 2024 11:01:39 +0700 Subject: [PATCH] Refinements to improved map canvas handlers --- src/qml/DashBoard.qml | 2 +- src/qml/MapCanvas.qml | 137 +++++++++++++++++++------------------- src/qml/qgismobileapp.qml | 14 +++- 3 files changed, 79 insertions(+), 74 deletions(-) diff --git a/src/qml/DashBoard.qml b/src/qml/DashBoard.qml index c6d20013c3..6a1bd72e03 100644 --- a/src/qml/DashBoard.qml +++ b/src/qml/DashBoard.qml @@ -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") diff --git a/src/qml/MapCanvas.qml b/src/qml/MapCanvas.qml index ef5f52deb9..c295b05f74 100644 --- a/src/qml/MapCanvas.qml +++ b/src/qml/MapCanvas.qml @@ -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 @@ -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 @@ -238,7 +175,7 @@ Item { onActiveChanged: { if (active) { - if (mouseArea.doublePressed) { + if (mainTapHandler.doublePressed) { oldTranslationY = 0 zoomCenter = centroid.position isZooming = true @@ -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 @@ -287,7 +284,7 @@ Item { onActiveChanged: { if (active) { - if (mouseArea.doublePressed) { + if (mainTapHandler.doublePressed) { oldTranslationY = 0 zoomCenter = centroid.position isZooming = true diff --git a/src/qml/qgismobileapp.qml b/src/qml/qgismobileapp.qml index 5c9455b5e7..68d803b3f3 100644 --- a/src/qml/qgismobileapp.qml +++ b/src/qml/qgismobileapp.qml @@ -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 @@ -3447,7 +3455,7 @@ ApplicationWindow { } if (cloudProjectsModel.layerObserver.deltaFileWrapper.hasError()) { - cloudPopup.show() + qfieldCloudPopup.show() } if (cloudConnection.status === QFieldCloudConnection.LoggedIn) { @@ -3781,7 +3789,7 @@ ApplicationWindow { } QFieldCloudPopup { - id: cloudPopup + id: qfieldCloudPopup visible: false focus: visible parent: Overlay.overlay