Card.qml 4.56 KB
Newer Older
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* GCompris - Card.qml
 *
 * Copyright (C) 2014 Holger Kaelberer  <holger.k@elberer.de>
 *
 * Authors:
 *   Pascal Georges <pascal.georges1@free.fr> (GTK+ version)
 *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ Mostly full rewrite)
 *   Holger Kaelberer <holger.k@elberer.de> (Qt Quick port)
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.1
import GCompris 1.0
import QtGraphicalEffects 1.0
import "../../core"
import "letter-in-word.js" as Activity

Item {
    id: cardItem


        Image{
            id: wordPic
            anchors.bottom: cardImage.top
            sourceSize.width: cardItem.width
            fillMode: Image.PreserveAspectFit
            source: imgurl
            z:-5
        }

        Image {
            id: cardImage
            sourceSize.width: cardItem.width
            fillMode: Image.PreserveAspectFit
            source:  Activity.url + "cloud.svg"
            z: (state == 'scaled') ? 1 : -1


            GCText {
                id: text
                anchors.horizontalCenter:parent.horizontalCenter

                anchors.verticalCenter: parent.verticalCenter

                z: 11

                text: spelling
                font.pointSize: NaN  // need to clear font.pointSize explicitly
                font.pixelSize: parent.width * 0.30
                font.bold: true
                style: Text.Outline
                styleColor: "#2a2a2a"
                color: "white"
            }

            DropShadow {
                anchors.fill: text
                cached: false
                horizontalOffset: 1
                verticalOffset: 1
                radius: 3
                samples: 16
                color: "#422a2a2a"
                source: text
            }



            ParticleSystemStarLoader {
                id: particle
                clip: false
            }

            states: State {
                name: "scaled"; when: mouseArea.containsMouse
                PropertyChanges {
                    target: cardItem
                    scale: /*carriageImage.scale * */ 1.2
                    z: 2}
            }

            transitions: Transition {
                NumberAnimation { properties: "scale"; easing.type: Easing.OutCubic }
            }

            SequentialAnimation {
                id: successAnimation
                running: selected
                loops: Animation.Infinite
                NumberAnimation {
                    target: cardImage
                    easing.type: Easing.InOutQuad
                    property: "rotation"
                    to: 20; duration: 500
                }
                NumberAnimation {
                    target: cardImage
                    easing.type: Easing.InOutQuad
                    property: "rotation"; to: -20
                    duration: 500 }

            }

            SequentialAnimation {
                id: failureAnimation
                NumberAnimation {
                    target: colorCardImage
                    property: "opacity"
                    to: 1; duration: 400
                }
                NumberAnimation {
                    target: colorCardImage
                    property: "opacity"
                    to: 0; duration: 200
                }
            }
            MouseArea {
                id: mouseArea
                anchors.fill: parent
                hoverEnabled: ApplicationInfo.isMobile ? false : true

                onClicked: {

                    if (Activity.checkWord(index)) {

                            successAnimation.restart();
                            particle.burst(30)


                    } else {
                        failureAnimation.restart()
                    }
                }
            }
        }

        Colorize {
                id: colorCardImage
                z: 5
                anchors.fill: cardImage
                source: cardImage
                hue: 0.0
                saturation: 1
                opacity: 0
            }
}