ClickOnLetter.qml 7.91 KB
Newer Older
1
/* GCompris - ClickOnLetter.qml
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * Copyright (C) 2014 Holger Kaelberer 
 * 
 * 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 QtMultimedia 5.0
26
import QtGraphicalEffects 1.0
27
import GCompris 1.0
28
import "../../core"
29
30
31
32
33
import "click_on_letter.js" as Activity

ActivityBase {
    id: activity
    focus: true
Holger Kaelberer's avatar
Holger Kaelberer committed
34
35
36
    
    /* mode of the activity, either "lowercase" (click_on_letter)
     * or "uppercase" (click_on_letter_up): */
37
38
    property string mode: "lowercase"
    
39
40
    pageComponent: Image {
        id: background
41
42
        source: Activity.url + "background.svgz"
        fillMode: Image.PreserveAspectCrop
43
44
45
46
47
48
49
50
        signal start
        signal stop
        focus: true
        
        Component.onCompleted: {
            activity.start.connect(start)
            activity.stop.connect(stop)
        }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
        
        QtObject {
            id: items
            property alias bar: bar
            property alias trainModel: trainModel
            property alias nextLevelAudio: nextLevelAudio
            property alias levelsFile: levelsFile
            property alias letterAudio: letterAudio 
            property alias questionItem: questionItem
            property alias score: score
            property alias bonus: bonus
        }
        
        onStart: Activity.start(items, mode); 
        
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        onStop: Activity.stop()

        DialogHelp {
            id: dialogHelpLeftRight
            onClose: home()
        }

        Bar {
            id: bar
            
            // anchor in top right corner:
            anchors.bottom: undefined 
            anchors.top: parent.top
            x: parent.width - width
            anchors.topMargin: height + 10
            
            content: BarEnumContent { value: help | home | repeat | previous | next }
            onHelpClicked: {
                displayDialog(dialogHelpLeftRight)
            }
            onPreviousLevelClicked: Activity.previousLevel()
            onNextLevelClicked: Activity.nextLevel()
            onHomeClicked: home()
89
            onRepeatClicked: if (ApplicationSettings.isAudioEnabled)
90
91
92
93
94
95
96
97
98
99
                                letterAudio.play();
        }

        Score {
            id: score
            
            anchors.top: parent.top
            anchors.topMargin: 10 * ApplicationInfo.ratio
            anchors.left: parent.left
            anchors.leftMargin: 10 * ApplicationInfo.ratio
100
101
            anchors.bottom: undefined
            anchors.right: undefined
102
103
104
105
106
107
108
        }

        Bonus {
            id: bonus
            Component.onCompleted: win.connect(Activity.nextSubLevel)
        }
        
109
110
111
112
113
114
115
116
117
118
119
120
        Image {
            id: railway
            source: Activity.url + "railway.svgz"
            fillMode: Image.PreserveAspectCrop
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            width: parent.width
            height: 15 * ApplicationInfo.ratio
            sourceSize.width: parent.width
            anchors.bottomMargin: 13 * ApplicationInfo.ratio
        }

121
122
123
124
125
        Item {
            id: questionItem
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.leftMargin: 10 * ApplicationInfo.ratio
126
            anchors.topMargin: parent.height * 0.25
127
            z: 10
128
129
130
            width: questionText.width * 2
            height: questionText.height * 1.3
            visible: false
131
132
133
134
135
136
137
138
139
140
141
142
143
            
            property alias text: questionText.text
            
            Rectangle {
                id: questionRect
                anchors.fill: parent
                
                border.color: "#FFFFFFFF"
                border.width: 2
                color: "#000065"
                opacity: 0.31
                radius: 10
            }
144

145
146
147
148
149
150
151
152
153
154
            Text {
                id: questionText
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                opacity: 1.0
                z:11            
                text: ""
                font.pointSize: 44
                font.bold: true
                style: Text.Outline
155
                styleColor: "black"
156
157
                color: "white"
            }
158
159
160
161
162
163
164
165
166
167
168
169

            DropShadow {
                anchors.fill: questionText
                cached: true
                horizontalOffset: 3
                verticalOffset: 3
                radius: 8.0
                samples: 16
                color: "#80000000"
                source: questionText
            }

170
171
172
        }
        
        ListModel {
173
            id: trainModel     
174
175
        }
        
176
177
178
        property int itemWidth: Math.min(parent.width / 7.5, parent.height / 5)
        property int itemHeight: itemWidth * 1.11

179
180
        Image {
            id: engine
181
182
183
184
            source: Activity.url + "engine.svgz"

            anchors.bottom: railway.bottom
            anchors.left: railway.left
185
            anchors.leftMargin: 10 * ApplicationInfo.ratio
186
187
188
189
            anchors.bottomMargin: 5 * ApplicationInfo.ratio
            sourceSize.width: itemWidth
            fillMode: Image.PreserveAspectFit
        }
190

191
192
193
        Image {
            id: smoke
            source: Activity.url + "smoke.svgz"
194

195
196
197
198
199
200
            anchors.bottom: engine.top
            anchors.left: railway.left
            anchors.leftMargin: 10 * ApplicationInfo.ratio
            anchors.bottomMargin: 5 * ApplicationInfo.ratio
            sourceSize.width: itemWidth
            fillMode: Image.PreserveAspectFit
201
202
203
204
        }

        GridView {
            id: train
205
206
207
208
209
210
211
212
213
            anchors.bottom: railway.bottom
            anchors.left: engine.right
            anchors.right: parent.right
            anchors.top: parent.top
            anchors.bottomMargin: 5 * ApplicationInfo.ratio
            cellWidth: itemWidth
            cellHeight: itemHeight
            clip: false
            interactive: false
214
215
216
217
            verticalLayoutDirection: GridView.BottomToTop
            layoutDirection: Qt.LeftToRight
            
            model: trainModel
218
219
220
221
222
            delegate: Carriage {
                sourceSize.width: background.itemWidth
                width: background.itemWidth
                nbCarriage: (parent.width - engine.width) / background.itemWidth
            }
223
        }
224
225
226
227
228
229
230
231
        
        File {
            id: levelsFile
            name: ""
                
            onError: console.log("Click_on_letter: levelsFile error: " + msg);
        }

232
        GCAudio {
233
            id: nextLevelAudio
234
            source: ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/click_on_letter.ogg")
235
236
237
            onError: letterAudio.play()
            // When this sound is complete, play the letter
            onDone: letterAudio.playDelayed(100);
238
239
        }

240
        GCAudio {
241
            id: letterAudio
242
            onError: questionItem.visible = true
243

244
245
246
247
248
249
250
251
252
253
254
255
256
            function playDelayed(ms) {
                if (letterAudioTimer.running)
                    letterAudioTimer.stop();
                letterAudioTimer.interval = ms;
                letterAudioTimer.start();
            }
        }
        
        Timer {
            id: letterAudioTimer
            repeat: false        
            onTriggered: letterAudio.play();
        }
257
258
    }
}