cards/qml/cards/Cards.qml
author Wes Thierry <wesleyt@symbian.org>
Fri, 05 Nov 2010 11:32:03 +0000
changeset 8 a593fb7f78c0
parent 3 2e16639599b7
permissions -rwxr-xr-x
Adding defines for magic numbers
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     1
import Qt 4.7
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     2
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     3
// This is a Qt Quick component. The name of the component is defined by the
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     4
// name of the file (ie Cards).
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     5
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     6
// Here we have taken some SVG file from Open Clipart(http://www.openclipart.org/people/nicubunu) to
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     7
// demonstrate how to use the QML Flipable element. Think of two images. One a playing card. The
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     8
// other is simply a pattern representing back of a playing card. When the user taps on the
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
// Flipable element, it rotates and displays the other side of the card.
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    10
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    11
// The key point here is the transition from one state to another. We have to faces to the
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
// card: front and back.
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
Flipable {
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    15
    id: container
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    16
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    17
    property alias image: frontImage.source
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    18
    property bool flipped: true
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    19
    property int xAxis: 0
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    20
    property int yAxis: 0
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    21
    property int angle: 0
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    22
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    23
    width: front.width; height: front.height
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    24
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    25
    // callee will define the front image
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    26
    front: Image { id: frontImage; smooth: true }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    27
    back: Image { source: "images/nicubunu_Card_backs_suits_red.svg"; smooth: true }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    28
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    29
    state: "back"
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    30
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    31
    MouseArea { anchors.fill: parent; onClicked: container.flipped = !container.flipped }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    32
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    33
    transform: Rotation {
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    34
        id: rotation; origin.x: container.width / 2; origin.y: container.height / 2
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    35
        axis.x: container.xAxis; axis.y: container.yAxis; axis.z: 0
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    36
    }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    37
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    38
    states: State {
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    39
        name: "back"; when: container.flipped
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    40
        PropertyChanges { target: rotation; angle: container.angle }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    41
    }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    42
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    43
    transitions: Transition {
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    44
        ParallelAnimation {
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    45
            NumberAnimation { target: rotation; properties: "angle"; duration: 600 }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    46
            SequentialAnimation {
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    47
                NumberAnimation { target: container; property: "scale"; to: 0.75; duration: 300 }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    48
                NumberAnimation { target: container; property: "scale"; to: 1.0; duration: 300 }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    49
            }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    50
        }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    51
    }
2e16639599b7 flipping cards example
John Kern <johnk@symbian.org>
parents:
diff changeset
    52
}