main.qml 6.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* GCompris - main.qml
 *
 * Copyright (C) 2014 Bruno Coudoin
 *
 * 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
24
import QtQuick.Controls 1.2
import QtQuick.Window 2.1
import QtQuick.Dialogs 1.1
25

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

29
Window {
30
31
32
    id: main
    width: 800
    height: 520
33
    minimumWidth: 400
34
    minimumHeight: 400
35
    title: "GCompris"
36
37

    onClosing: Core.quit()
38

39
    GCAudio {
Bruno Coudoin's avatar
Bruno Coudoin committed
40
41
        id: audioVoices
        muted: !ApplicationSettings.isAudioVoicesEnabled
42
43

        Component.onCompleted: {
44
45
            if(ApplicationSettings.isAudioEffectsEnabled)
                append("qrc:/gcompris/src/core/resource/intro.ogg")
46
47
            append(ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/welcome.ogg"))
        }
Bruno Coudoin's avatar
Bruno Coudoin committed
48
49
50
51
52
    }

    GCAudio {
        id: audioEffects
        muted: !ApplicationSettings.isAudioEffectsEnabled
53
    }
54
55
56

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

60
61
62
63
64
65
66
67
68
    Component.onCompleted: {
        console.log("enter main.qml (run #" + ApplicationSettings.exeCount + ")")
        if (ApplicationSettings.exeCount == 1) {
            // first run
            var buttonHandler = new Array();
            var dialog;
            buttonHandler[StandardButton.Ok] = function() {};
            dialog = Core.showMessageDialog(main, qsTr("Welcome to GCompris!"),
                    qsTr("You are running GCompris for the first time."),
69
70
71
72
73
                    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("Your current locale is '%1'").arg(ApplicationInfo.localeShort) +
                    "\n" +
                    qsTr("Have Fun!"),
74
75
76
77
78
                    StandardIcon.Information,
                    buttonHandler
            );
        }
    }
79

80
81
82
    StackView {
        id: pageView
        anchors.fill: parent
83
        initialItem: "qrc:/gcompris/src/activities/" + ActivityInfoTree.rootMenu.name
84
        delegate: StackViewDelegate {
85
86
87
            id: root
            function getTransition(properties)
            {
88
                properties.exitItem.pause()
89
                audioVoices.clearQueue()
90
                if(!properties.exitItem.isDialog) {
Bruno Coudoin's avatar
Bruno Coudoin committed
91
92
                    if(!properties.enterItem.isDialog) {
                        playIntroVoice(properties.enterItem.activityInfo.name)
Bruno Coudoin's avatar
Bruno Coudoin committed
93
94
                        properties.enterItem.audioVoices = audioVoices
                        properties.enterItem.audioEffects = audioEffects
Bruno Coudoin's avatar
Bruno Coudoin committed
95
                    }
96
97
98
                    properties.enterItem.start()
                }

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
                if(properties.name === "pushTransition") {
                    if(properties.enterItem.isDialog) {
                        return pushVTransition
                    } else {
                        return pushHTransition
                    }
                } else {
                    if(properties.exitItem.isDialog) {
                        return popVTransition
                    } else {
                        return popHTransition
                    }

                }
            }

115
116
117
118
119
120
            function transitionFinished(properties)
            {
                properties.exitItem.opacity = 1
                properties.enterItem.play()
                if(!properties.enterItem.isDialog) {
                    properties.exitItem.stop()
121
                }
122
123
124
            }

            property Component pushHTransition: StackViewTransition {
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
                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
                }
            }
142
143

            property Component popHTransition: StackViewTransition {
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
                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
159
160
                }
            }
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
            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
197
198
                }
            }
199
200

            property Component replaceTransition: pushHTransition
201
202
203
        }
    }
}