mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
[quick] do not start moving canvas if the drag distance is too small
Often when users want to click (tap) the map, they still move the cursor position a bit. This would trigger unwanted map pan and map refresh afterwards. A configurable minimum drag distance is introduced in order to prevent that.
This commit is contained in:
parent
130f3edde9
commit
0a0d2e995f
@ -47,6 +47,11 @@ Item {
|
|||||||
*/
|
*/
|
||||||
property alias incrementalRendering: mapCanvasWrapper.incrementalRendering
|
property alias incrementalRendering: mapCanvasWrapper.incrementalRendering
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What is the minimum distance (in pixels) in order to start dragging map
|
||||||
|
*/
|
||||||
|
property real minimumStartDragDistance: 5 * QgsQuick.Utils.dp
|
||||||
|
|
||||||
signal clicked(var mouse)
|
signal clicked(var mouse)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,6 +112,7 @@ Item {
|
|||||||
|
|
||||||
property point __initialPosition
|
property point __initialPosition
|
||||||
property point __lastPosition
|
property point __lastPosition
|
||||||
|
property bool __dragging: false
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
@ -123,7 +129,7 @@ Item {
|
|||||||
var distance = Math.abs(mouse.x - __initialPosition.x) + Math.abs(
|
var distance = Math.abs(mouse.x - __initialPosition.x) + Math.abs(
|
||||||
mouse.y - __initialPosition.y)
|
mouse.y - __initialPosition.y)
|
||||||
|
|
||||||
if (distance < 5 * QgsQuick.Utils.dp)
|
if (distance < minimumStartDragDistance)
|
||||||
mapArea.clicked(mouse)
|
mapArea.clicked(mouse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,6 +137,7 @@ Item {
|
|||||||
onPressed: {
|
onPressed: {
|
||||||
__lastPosition = Qt.point(mouse.x, mouse.y)
|
__lastPosition = Qt.point(mouse.x, mouse.y)
|
||||||
__initialPosition = __lastPosition
|
__initialPosition = __lastPosition
|
||||||
|
__dragging = false
|
||||||
freeze('pan')
|
freeze('pan')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,9 +146,17 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPositionChanged: {
|
onPositionChanged: {
|
||||||
var currentPosition = Qt.point(mouse.x, mouse.y)
|
// are we far enough to start dragging map? (we want to avoid tiny map moves)
|
||||||
mapCanvasWrapper.pan(currentPosition, __lastPosition)
|
var distance = Math.abs(mouse.x - __initialPosition.x) + Math.abs(mouse.y - __initialPosition.y)
|
||||||
__lastPosition = currentPosition
|
if (distance >= minimumStartDragDistance)
|
||||||
|
__dragging = true
|
||||||
|
|
||||||
|
if (__dragging)
|
||||||
|
{
|
||||||
|
var currentPosition = Qt.point(mouse.x, mouse.y)
|
||||||
|
mapCanvasWrapper.pan(currentPosition, __lastPosition)
|
||||||
|
__lastPosition = currentPosition
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onCanceled: {
|
onCanceled: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user