View Single Post
Posts: 1,548 | Thanked: 7,510 times | Joined on Apr 2010 @ Czech Republic
#96
Originally Posted by rinigus View Post
I would like to ask for help from QML experts. For interaction with the widget, we need mouse interaction area that would support:
  • panning
  • pinch to zoom
  • flicking
  • report single click
  • report double click

I have composed something on the basis of demo code that was given by Nokia (if I am not mistaken) which uses PinchArea/MouseArea combination.
This is how modRana does it - seems to be the same principle:
https://github.com/M4rtinK/modrana/b...chMap.qml#L691

Originally Posted by rinigus View Post
This is lacking flicking support.
I *think* that if you want flick support in your custom widget and the use case does not fit a built-in container (Flickable, ListView, etc.) you are supposed to implement that yourself.

The general idea is to detect the velocity of the pan (generally in pixels/second) and move the widget accordingly, using an animation (NumberAnimation, SmoothedAnimation, CoordinateAnimation, etc.).

The velocity is the absolute position change in an axis between the start and end of the pan, divided by pan duration. Looks like using a MultiTouchPointArea might give you the velocity for free (just read the value at end of pan).

Let's say (an arbitrary number example) the user panned for 500 pixels at 200 pixels/second in each axis (a perfect diagonal flick I guess ?). We can arbitrarily decide we want the flick to continue for another 500 pixels at the same speed, which can be achieved by using two SmoothedAnimations (grouped in ParallelAnimation), one for X and the other for Y with the detected velocity set to move the map 500 pixels in each direction.

You can use an appropriate easing so that the flick does not come to an abrupt halt but rather gradually slows down. Also if another pan is detected, the animation should be stopped, so that the user can drag the map as expected and restarted with a new set of values once the pan ends.

Originally Posted by rinigus View Post
In addition, I get "false positive" clicks sometimes when panning and (probably always) when double clicking.
You need to filter out clicks from pans by comparing the position change against a threshold.

This is how modRana does it:
https://github.com/M4rtinK/modrana/b...chMap.qml#L792

There is a threshold of 100 pixels, multiplied by a hi-DPI multiplier (standard-DPI == 1, hi-DPI = 2) that the position changes is compared to. Once the position change is over the threshold, the even is classified as a pan and will no longer be considered a click once the user lifts their finger. The same thing for a pan - it's not recognized as a pan until the threshold is crossed. This prevents the map from "jumping" when the user clicks/double-clicks it.

Also, one thing to watch for is that the mouse event coordinates are floats and you should convert them to integers as soon as possible before using them for other things. Otherwise bad things will happen - for example if you use them to move two different elements/layers during the pan by adding he position difference to x/y coordinates, the two elements/layers will gradually "float apart" due to floating point errors. All should be fine if you convert the mouse event numbers to integers first.

Originally Posted by rinigus View Post
If there is a brave soul that could look into current implementation at https://github.com/rinigus/mapbox-de...pMouseArea.qml and improve it, it will be very much appreciated.
How do I build & run the demo app on desktop (Fedora 26 in my case)? Just load it to a recent QtCreator or is there more ? Don't really want to promise anything just now though - I'm already working on quite many things in modRana at the same time (routing overlay, making it possible to switch between different map element implementations, general stabilization so that a new modRana release can be made in a reasonably near future, etc.).

Originally Posted by rinigus View Post
Ideally, I would like to have this code MIT-licensed, so everyone could just reuse it in their projects regardless of their license. Don't know the original license of Nokia-based demo code though ...
Sounds like a good idea & could be pretty useful.

Originally Posted by rinigus View Post
Other than mouse interaction, I am making steady progress with porting Poor Maps over to this map widget. The widget's API is developed to make this and future ports easier, as was expected.
Sounds good!
__________________
modRana: a flexible GPS navigation system
Mieru: a flexible manga and comic book reader
Universal Components - a solution for native looking yet component set independent QML appliactions (QtQuick Controls 2 & Silica supported as backends)
 

The Following 4 Users Say Thank You to MartinK For This Useful Post: