Skip to content

Commit

Permalink
Add distance threshold for double click gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasMizera committed Oct 19, 2023
1 parent 0448b19 commit e77cc52
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions app/qml/map/MMMapCanvas.qml
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,26 @@ Item {
clickDifferentiatorTimer.clickedPoint = Qt.point( mouse.x, mouse.y )
}
else {
//
// n-th click in a row (second, third,..)
// this can be double click if it is in a reasonable
// distance from the previous click
//

// do not emit clicked signal for the second click
mouse.accepted = true
let isDoubleClick = false
let previousTapPosition = clickDifferentiatorTimer.clickedPoint

clickDifferentiatorTimer.invalidate = true
if ( previousTapPosition ) {
let tapDistance = rendererPrivate.vectorDistance( clickPosition, previousTapPosition )
isDoubleClick = tapDistance < mouseArea.drag.threshold
}

if ( isDoubleClick ) {
// do not emit clicked signal when zooming
clickDifferentiatorTimer.invalidate = true

mapRenderer.zoom( Qt.point( mouse.x, mouse.y ), 0.4 )
mapRenderer.zoom( Qt.point( mouse.x, mouse.y ), 0.4 )
}
}

if ( !isDragging ) {
Expand Down Expand Up @@ -231,7 +243,9 @@ Item {
previousPosition = target

let dragDistance = rendererPrivate.vectorDistance( initialPosition, target )
if ( dragDistance > drag.threshold ) {

// TODO: we need a high-precision mode here
if ( dragDistance > mouseArea.drag.threshold ) {
isDragging = true

// do not emit click after drag
Expand All @@ -256,7 +270,7 @@ Item {
Timer {
id: clickDifferentiatorTimer

property point clickedPoint
property var clickedPoint
property bool invalidate

interval: mapRoot.doubleClickThresholdMilis
Expand All @@ -267,6 +281,7 @@ Item {
mapRoot.clicked( clickedPoint )
}
invalidate = false
clickedPoint = null
}

function reset() {
Expand Down

1 comment on commit e77cc52

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.10.471011 just submitted!

Please sign in to comment.