How to use gestures in Ubuntu to zoom in or out images, and ubuntu gestures

Source: Internet
Author: User

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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.