main.qml 9.1 KB
Newer Older
1
2
/* GCompris - main.qml
 *
3
 * Copyright (C) 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * Authors:
 *   Bruno Coudoin <bruno.coudoin@gcompris.net>
 *
 *   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/>.
 */
Bruno Coudoin's avatar
Bruno Coudoin committed
21
import QtQuick 2.2
22
23
import QtQuick.Controls 1.2
import QtQuick.Window 2.1
24
import QtQml 2.2
25

26
import GCompris 1.0
27
import "qrc:/gcompris/src/core/core.js" as Core
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * GCompris' main QML file defining the top level window.
 * @ingroup infrastructure
 *
 * Handles application start (Component.onCompleted) and shutdown (onClosing)
 * on the QML layer.
 *
 * Contains the central GCAudio objects audio effects and audio voices.
 *
 * Contains the top level StackView presenting and animating GCompris'
 * full screen views.
 *
 * @sa BarButton, BarEnumContent
 * @inherit QtQuick.Window
 */
44
Window {
45
46
47
    id: main
    width: 800
    height: 520
48
    minimumWidth: 400
49
    minimumHeight: 400
50
    title: "GCompris"
51

52
53
54
55
56
57
58
59
60
    property var applicationState: Qt.application.state

    onApplicationStateChanged: {
        if (ApplicationInfo.isMobile && applicationState != Qt.ApplicationActive) {
            audioVoices.stop();
            audioEffects.stop();
        }
    }

61
    onClosing: Core.quit()
62

63
    GCAudio {
Bruno Coudoin's avatar
Bruno Coudoin committed
64
65
        id: audioVoices
        muted: !ApplicationSettings.isAudioVoicesEnabled
66

67
68
69
70
71
72
73
74
        Timer {
            id: delayedWelcomeTimer
            interval: 10000 /* Make sure, that playing welcome.ogg if delayed
                             * because of not yet registered voices, will only
                             * happen max 10sec after startup */
            repeat: false

            onTriggered: {
75
                DownloadManager.voicesRegistered.disconnect(playWelcome);
76
77
78
79
80
81
82
            }

            function playWelcome() {
                audioVoices.append(ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/welcome.ogg"));
            }
        }

83
        Component.onCompleted: {
84
85
            if(ApplicationSettings.isAudioEffectsEnabled)
                append("qrc:/gcompris/src/core/resource/intro.ogg")
86
87
88
89
90
91
92
93

            if (DownloadManager.areVoicesRegistered())
                delayedWelcomeTimer.playWelcome();
            else {
                DownloadManager.voicesRegistered.connect(
                        delayedWelcomeTimer.playWelcome);
                delayedWelcomeTimer.start();
            }
94
        }
Bruno Coudoin's avatar
Bruno Coudoin committed
95
96
97
98
99
    }

    GCAudio {
        id: audioEffects
        muted: !ApplicationSettings.isAudioEffectsEnabled
100
    }
101
102
103

    function playIntroVoice(name) {
        name = name.split("/")[0]
Bruno Coudoin's avatar
Bruno Coudoin committed
104
        audioVoices.append(ApplicationInfo.getAudioFilePath("voices/$LOCALE/intro/" + name + ".ogg"))
105
106
    }

107
    Component.onCompleted: {
108
109
        console.log("enter main.qml (run #" + ApplicationSettings.exeCount
                + ", ratio=" + ApplicationInfo.ratio
110
                + ", fontRatio=" + ApplicationInfo.fontRatio
111
                + ", dpi=" + Math.round(Screen.pixelDensity*25.4) + ")");
112
        if (ApplicationSettings.exeCount == 1 && !ApplicationSettings.isKioskMode) {
113
114
            // first run
            var dialog;
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
            dialog = Core.showMessageDialog(
                        main,
                        qsTr("Welcome to GCompris!") + '\n'
                        + qsTr("You are running GCompris for the first time.") + '\n'
                        + qsTr("You should verify that your application settings especially your language is set correctly, and that all language specific sound files are installed. You can do this in the Preferences Dialog.")
                        + "\n"
                        + qsTr("Have Fun!")
                        + "\n"
                        + qsTr("Your current language is %1 (%2).")
                          .arg(Qt.locale(ApplicationSettings.locale).nativeLanguageName)
                          .arg(ApplicationSettings.locale)
                        + "\n"
                        + qsTr("Do you want to download the corresponding sound files now?"),
                        "YES",
                        function() {
                            if (DownloadManager.downloadResource(
                                        DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale)))
                                var downloadDialog = Core.showDownloadDialog(pageView.currentItem, {});
                        },
                        "NO", null,
                        function() { pageView.currentItem.focus = true }
136
137
138
            );
        }
    }
139

140
141
142
    StackView {
        id: pageView
        anchors.fill: parent
143
144
145
146
147
148
149
150
        initialItem: {
            "item": "qrc:/gcompris/src/activities/" + ActivityInfoTree.rootMenu.name,
            "properties": {
                'audioVoices': audioVoices,
                'audioEffects': audioEffects
            }
        }

151
        delegate: StackViewDelegate {
152
153
154
            id: root
            function getTransition(properties)
            {
155
                properties.exitItem.pause()
156
                audioVoices.clearQueue()
157
                if(!properties.exitItem.isDialog) {
Bruno Coudoin's avatar
Bruno Coudoin committed
158
159
160
                    if(!properties.enterItem.isDialog) {
                        playIntroVoice(properties.enterItem.activityInfo.name)
                    }
161
162
163
                    properties.enterItem.start()
                }

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
                if(properties.name === "pushTransition") {
                    if(properties.enterItem.isDialog) {
                        return pushVTransition
                    } else {
                        return pushHTransition
                    }
                } else {
                    if(properties.exitItem.isDialog) {
                        return popVTransition
                    } else {
                        return popHTransition
                    }

                }
            }

180
181
182
183
184
185
            function transitionFinished(properties)
            {
                properties.exitItem.opacity = 1
                properties.enterItem.play()
                if(!properties.enterItem.isDialog) {
                    properties.exitItem.stop()
186
                }
187
188
189
            }

            property Component pushHTransition: StackViewTransition {
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
                PropertyAnimation {
                    target: enterItem
                    property: "x"
                    from: target.width
                    to: 0
                    duration: 500
                    easing.type: Easing.OutSine
                }
                PropertyAnimation {
                    target: exitItem
                    property: "x"
                    from: 0
                    to: -target.width
                    duration: 500
                    easing.type: Easing.OutSine
                }
            }
207
208

            property Component popHTransition: StackViewTransition {
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
                PropertyAnimation {
                    target: enterItem
                    property: "x"
                    from: -target.width
                    to: 0
                    duration: 500
                    easing.type: Easing.OutSine
                }
                PropertyAnimation {
                    target: exitItem
                    property: "x"
                    from: 0
                    to: target.width
                    duration: 500
                    easing.type: Easing.OutSine
224
225
                }
            }
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
            property Component pushVTransition: StackViewTransition {
                PropertyAnimation {
                    target: enterItem
                    property: "y"
                    from: -target.height
                    to: 0
                    duration: 500
                    easing.type: Easing.OutSine
                }
                PropertyAnimation {
                    target: exitItem
                    property: "y"
                    from: 0
                    to: target.height
                    duration: 500
                    easing.type: Easing.OutSine
                }
            }

            property Component popVTransition: StackViewTransition {
                PropertyAnimation {
                    target: enterItem
                    property: "y"
                    from: target.height
                    to: 0
                    duration: 500
                    easing.type: Easing.OutSine
                }
                PropertyAnimation {
                    target: exitItem
                    property: "y"
                    from: 0
                    to: -target.height
                    duration: 500
                    easing.type: Easing.OutSine
262
263
                }
            }
264
265

            property Component replaceTransition: pushHTransition
266
267
268
        }
    }
}