How it works…

When a finger touches the screen of the device, the multi-point touch area widget triggers the onPressed event and registers the position of each of the touch points in an internal array. We can get this data by telling Qt which touch point you want to get access to. The first touch will bear the index number of 0, the second touch will be 1, and so on. We will then save this data into variables so that we can retrieve it later to calculate the scaling of the penguin image.

When one or more fingers remain in contact with the screen while moving, a multi-point touch area will trigger the onUpdated event. We will then check how many touches there are—if only one touch is found, we will just move the penguin image based on how much our finger has moved. If there is more than one touch, we will compare the distance between the two touches and compare this with the previous variables we have saved to determine how much we should rescale the image.

The diagram shows tapping your finger on the screen will trigger the onPressed event, while swiping your finger on screen will trigger the onUpdated event:

We must also check whether the first touch is on the left side of the second touch or the right side. This way we can prevent the image from being scaled in the inverse direction of the finger movement and producing an inaccurate result. As for the movement of the penguin, we will just get the difference between the current touch position and the previous one, add that to the coordinate of the penguin, and it's done. A single touch event is usually a lot simpler and more straightforward than a multi-touch event.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset