summaryrefslogtreecommitdiffstats
path: root/demos/qml-demo-shell/qml-demo-shell.qml
blob: f8ed58ae2532b70591284f55c51405cb6e92d26b (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import QtQuick 2.0
import Unity.Application 0.1

Rectangle {
    id: root

    focus: true
    Keys.onVolumeUpPressed: {
        console.log("\"Volume Up\" pressed");
    }
    Keys.onVolumeDownPressed: {
        console.log("\"Volume Down\" pressed");
    }

    gradient: Gradient {
        GradientStop { position: 0.0; color: "lightsteelblue" }
        GradientStop { position: 1.0; color: "pink" }
    }

    Image {
        id: unityLogo
        source: "UnityLogo.png"
        fillMode: Image.PreserveAspectFit
        anchors.centerIn: parent
        width: 600
        height: 600

        RotationAnimation {
            id: logoAnimation
            target: unityLogo
            from: 0
            to: 359
            duration: 3000
            easing.type: Easing.Linear
            loops: Animation.Infinite
        }

    }

    MultiPointTouchArea {
        anchors.fill: parent
        minimumTouchPoints: 1
        maximumTouchPoints: 1
        touchPoints: [
            TouchPoint { id: point }
        ]
        property Item window: null
        property real previousX: 0
        property real previousY: 0

        onPressed: {
            // if at least 2 touch points are within a Window, select that Window
            window = windowContainer.childAt(point.x, point.y);

            // save mouse position
            previousX = point.x
            previousY = point.y
        }

        onUpdated: {
            if (!window) return;

            var offset = point.x - previousX
            if (window.width > 100) {
                window.width += offset
            }
            previousX = point.x

            offset = point.y - previousY
            if (window.height > 100) {
                window.height += offset
            }
            previousY = point.y
        }

        onReleased: {
            window = null
            print(window.width, window.height)
        }

        MultiPointTouchArea {
            id: touchArea
            x: unityLogo.x
            y: unityLogo.y
            width: unityLogo.width
            height: unityLogo.height
            minimumTouchPoints:1
            maximumTouchPoints:1
            onPressed: {
                if (logoAnimation.paused) {
                    logoAnimation.resume();
                } else if (logoAnimation.running) {
                    logoAnimation.pause();
                } else {
                    logoAnimation.start();
                }
            }
        }

        Item {
            id: windowContainer
            anchors.fill: parent
        }
    }

    Rectangle {
        width: 30; height: 30
        color: "green"
        x: point.x
        y: point.y
    }

    Rectangle {
        width: 60
        height: 40
        color: "red"
        anchors { right: parent.right; bottom: parent.bottom }
        Text {
            anchors.centerIn: parent
            text: "Quit"
        }
        MouseArea {
            anchors.fill: parent
            onClicked: Qt.quit()
        }
    }

    Connections {
        target: SurfaceManager
        onSurfaceCreated: {
            print("new surface", surface.name)

            var windowComponent = Qt.createComponent("Window.qml");
            var window = windowComponent.createObject(windowContainer);
            window.setSurface(surface);

            openAnimation.target = window;
            openAnimation.start();
        }

        onSurfaceDestroyed: {
            print("surface destroying", surface.name)
            closeAnimation.surface = surface;
            closeAnimation.start();
        }
    }

    NumberAnimation {
        id: openAnimation
        property: "x";
        from: root.width; to: 10;
        duration: 1200; easing.type: Easing.InOutQuad
    }

    SequentialAnimation {
        id: closeAnimation
        property variant surface: null
        NumberAnimation {
            target: (closeAnimation.surface && closeAnimation.surface.parent) ? closeAnimation.surface.parent.parent : null
            property: "scale";
            to: 0;
            duration: 500; easing.type: Easing.InQuad
        }
        ScriptAction {
            script: {
                closeAnimation.surface.parent.destroy(); //parent.destroy();
                closeAnimation.surface.release();
                print("surface destroyed")
            }
        }
    }
}