summaryrefslogtreecommitdiffstats
path: root/examples/declarative/snow/snow.qml
blob: 2241c3f26ca263ccfcca54e16b6c85cafe569fa7 (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
import Qt 4.6

Rectangle {
    id: ImagePanel
    width: 1024
    height: 768
    color: "black"

    property int maximumColumn: 4
    property int selectedItemRow: 0
    property int selectedItemColumn: 0

    Script { source: "create.js" }

    onSelectedItemColumnChanged: if (selectedItemColumn == maximumColumn) createNewBlock();

    property int imageWidth: 200
    property int imageHeight: 200

    property int selectedX: selectedItemColumn * imageWidth
    property int selectedY: selectedItemRow * imageHeight

    Item {
        anchors.centerIn: parent
        Row {
            id: MyLayout
            property real targetX: -(selectedX + imageWidth / 2)

            property real targetDeform: 0
            property bool slowDeform: true

            property real deform: 0
            deform: SpringFollow {
                id: "DeformFollow"; source: MyLayout.targetDeform; velocity: MyLayout.slowDeform?0.1:2
                onSyncChanged: if(inSync) { MyLayout.slowDeform = true; MyLayout.targetDeform = 0; }
            }
                
            ImageBatch { offset: 0; ref: ImagePanel }

            x: SpringFollow { source: MyLayout.targetX; velocity: 1000 }
            y: SpringFollow { source: -(selectedY + imageHeight / 2); velocity: 500 }
        }

        transform: Rotation {
            axis.y: 1; axis.z: 0
            angle: MyLayout.deform * -100
        }
    }

    Script {
        function left() {
            if (selectedItemColumn <= 0) return;
            selectedItemColumn -= 1;
            MyLayout.slowDeform = false;
            MyLayout.targetDeform = Math.max(Math.min(MyLayout.deform - 0.1, -0.1), -0.4);
        }
        function right() {
            selectedItemColumn += 1;
            MyLayout.slowDeform = false;
            MyLayout.targetDeform = Math.min(Math.max(MyLayout.deform + 0.1, 0.1), 0.4);
        }
    }

    focus: true
    Keys.onLeftPressed: "left()"
    Keys.onRightPressed: "right()"
    Keys.onUpPressed: "if (selectedItemRow > 0) selectedItemRow = selectedItemRow - 1"
    Keys.onDownPressed: "if (selectedItemRow < 3) selectedItemRow = selectedItemRow + 1"
}