summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/declarative/flipable.qml
blob: ae743450f1e3a36113835257c5b16f5d9ffc0ac0 (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
//! [0]
import Qt 4.7

Flipable {
    id: flipable
    width: 240
    height: 240

    property int angle: 0
    property bool flipped: false

    front: Image { source: "front.png" }
    back: Image { source: "back.png" }

    transform: Rotation {
        origin.x: flipable.width/2; origin.y: flipable.height/2
        axis.x: 0; axis.y: 1; axis.z: 0     // rotate around y-axis
        angle: flipable.angle
    }

    states: State {
        name: "back"
        PropertyChanges { target: flipable; angle: 180 }
        when: flipable.flipped
    }

    transitions: Transition {
        NumberAnimation { properties: "angle"; duration: 1000 }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: flipable.flipped = !flipable.flipped
    }
}
//! [0]