How to use gestures in Ubuntu to zoom in or out images, and ubuntu gestures
For some applications, we want to use gestures for some actions. For example, you can use gestures to enlarge an image or rotate an image. Pdf reader is also a good way to enlarge your font. In this article, we will introduce how to use gestures.
In QML, there is a PinchArea element. In this article, we will also introduce how to adjust, scale, and rotate Qt Quick events ". Here we will not go into details. We will directly paste our routine:
import QtQuick 2.0import Ubuntu.Components 1.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "pinch.ubuntu" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(50) height: units.gu(75) Page { id:main title: i18n.tr("Simple") Flickable { id: flick anchors.fill: parent contentWidth: 768 contentHeight: 1024 PinchArea { width: Math.max(flick.contentWidth, flick.width) height: Math.max(flick.contentHeight, flick.height) pinch.maximumScale: 20; pinch.minimumScale: 0.2; pinch.minimumRotation: 0; pinch.maximumRotation: 1; property real initialWidth property real initialHeight onPinchStarted: { initialWidth = flick.contentWidth initialHeight = flick.contentHeight } onPinchUpdated: { // adjust content pos due to drag flick.contentX += pinch.previousCenter.x - pinch.center.x flick.contentY += pinch.previousCenter.y - pinch.center.y console.log("rotation: " + pinch.rotation ); if ( pinch.rotation > 0 ) flick.rotation += 0.2; else flick.rotation -= 0.2; // resize content flick.resizeContent(initialWidth * pinch.scale, initialHeight * pinch.scale, pinch.center) } onPinchFinished: { // Move its content within bounds. flick.returnToBounds() } Rectangle { width: flick.contentWidth height: flick.contentHeight color: "white" Image { id: image anchors.fill: parent source: "images/sky.jpg" MouseArea { anchors.fill: parent } } } } } }}
Run our application and you can see the following picture:
Source code for the entire project in: git clone https://gitcafe.com/ubuntu/pinch.git