summaryrefslogtreecommitdiffstats
path: root/examples/declarative/toys/dynamicscene/qml/Sun.qml
blob: 43dcb9a128d37176404770fa7083b7a3b4940d99 (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
import Qt 4.7

Image {
    id: sun

    property bool created: false
    property string image: "../images/sun.png"

    source: image

    // once item is created, start moving offscreen
    NumberAnimation on y {
        to: window.height / 2
        running: created
        onRunningChanged: {
            if (running)
                duration = (window.height - sun.y) * 10;
            else
                state = "OffScreen"
        }
    }

    states: State {
        name: "OffScreen"
        StateChangeScript {
            script: { sun.created = false; sun.destroy() }
        }
    }

    onCreatedChanged: {
        if (created) {
            sun.z = 1;    // above the sky but below the ground layer 
            window.activeSuns++;
        } else {
            window.activeSuns--;
        }
    }
}