summaryrefslogtreecommitdiff
path: root/qml/pages/Point.qml
blob: 03a1e39cfbcf8c059cec7b9b3d00342b5c70f9f0 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import QtQuick 2.0

Item {

    /**
     * A mark on the stone for identify it easily.
     */
    property bool mark: false

    /*
     * Make the stone appear.
     */
    function put(isWhite, animation) {
        if (animation) {
            state = "shown";
        } else {
            piece.opacity = 1;
            piece.scale = 1;
            state = "";
        }
        piece.type = isWhite ? "white" : "black";
    }

    /**
     * Make the stone disappear.
     */
    function remove(animation) {
        if (animation) {
            state = "remove"
        } else {
            piece.type = "";
            state = "";
        }
    }

    /*
     * return the current stone type.
     */
    function getType() {
        if (state == "remove")  {
            return "";
        } else {
            return piece.type;
        }
    }

    states: [
        State {
            name: "shown"
            PropertyChanges  { target: piece; opacity:1 }
        }, State {
            name: "remove"
            onCompleted: piece.type = "";
        }
    ]

    transitions: [
        Transition {
            to: "remove"
            NumberAnimation {
                targets: piece;
                property: "opacity";
                from: 1;
                to: 0
                duration: 500;
            }
        },
        Transition {
            to: "shown"
            PropertyAnimation {
                target: piece;
                property: "scale";
                from: 0;
                to: 1
                easing.type: Easing.OutBack
            }
        }
    ]

    Image {
        id: piece
        anchors.fill: parent
        source: getImageForType();

        property string type: "";

        function getImageForType() {
            if ("" === type) {
                return ""
            }
            return "../content/gfx/" + type + ".png"
        }

    }
}