summaryrefslogtreecommitdiffstats
path: root/examples/declarative/touchinteraction/pincharea/flickresize.qml
blob: 8034e296b1c9b50e706eae13bc4d29563c69b0ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import QtQuick 1.1

Rectangle {
    width: 640
    height: 360
    color: "gray"

    Flickable {
        id: flick
        anchors.fill: parent
        contentWidth: 500
        contentHeight: 500

        PinchArea {
            width: Math.max(flick.contentWidth, flick.width)
            height: Math.max(flick.contentHeight, flick.height)
            onPinchChanged: {
                // adjust content pos due to drag
                flick.contentX += pinch.lastCenter.x - pinch.center.x
                flick.contentY += pinch.lastCenter.y - pinch.center.y

                // resize content
                var scale = 1.0 + pinch.scale - pinch.lastScale
                flick.resizeContent(flick.contentWidth * scale, flick.contentHeight * scale, pinch.center)
            }

            onPinchFinished: {
                // Move its content within bounds.
                flick.returnToBounds()
            }

            Rectangle {
                width: flick.contentWidth
                height: flick.contentHeight
                color: "white"
                Image {
                    anchors.fill: parent
                    source: "qt-logo.jpg"
                    MouseArea {
                        anchors.fill: parent
                        onDoubleClicked: {
                            flick.contentWidth = 500
                            flick.contentHeight = 500
                        }
                    }
                }
            }
        }
    }
}