summaryrefslogtreecommitdiffstats
path: root/examples/declarative/snow/snow.qml
blob: 39c9c434b122bf3e14eaf6620422d1e8340e5034 (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: layout
            property real targetX: -(selectedX + imageWidth / 2)

            property real targetDeform: 0
            property bool slowDeform: true

            property real deform: 0
            deform: SpringFollow {
                id: deformFollow; source: layout.targetDeform; velocity: layout.slowDeform?0.1:2
                onSyncChanged: if(inSync) { layout.slowDeform = true; layout.targetDeform = 0; }
            }

            ImageBatch { offset: 0; ref: imagePanel }

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

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

    Script {
        function left() {
            if (selectedItemColumn <= 0) return;
            selectedItemColumn -= 1;
            layout.slowDeform = false;
            layout.targetDeform = Math.max(Math.min(layout.deform - 0.1, -0.1), -0.4);
        }
        function right() {
            selectedItemColumn += 1;
            layout.slowDeform = false;
            layout.targetDeform = Math.min(Math.max(layout.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"
}