main.qml 6.27 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
import QtQuick.Controls 1.2
import QtQuick.Window 2.1
24
import QtMultimedia 5.0
25
import QtQuick.Dialogs 1.1
26

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

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

    onClosing: Core.quit()
39
        
40
    GCAudio {
41
42
        id: audio
        source: "qrc:/gcompris/src/core/resource/intro.ogg"
43
        autoPlay: false
44
    }
45
46
47
48
49
50

    function playIntroVoice(name) {
        name = name.split("/")[0]
        audio.append(ApplicationInfo.getAudioFilePath("voices/$LOCALE/intro/" + name + ".ogg"))
    }

51
52
53
54
55
56
57
58
59
    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."),
60
61
62
63
64
                    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!"),
65
66
67
68
69
                    StandardIcon.Information,
                    buttonHandler
            );
        }
    }
70

71
72
73
    StackView {
        id: pageView
        anchors.fill: parent
74
        initialItem: "qrc:/gcompris/src/activities/" + ActivityInfoTree.rootMenu.name
75
        delegate: StackViewDelegate {
76
77
78
            id: root
            function getTransition(properties)
            {
79
80
                properties.exitItem.pause()
                if(!properties.exitItem.isDialog) {
81
82
                    playIntroVoice(properties.enterItem.activityInfo.name)
                    properties.enterItem.audio = audio
83
84
85
                    properties.enterItem.start()
                }

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
                if(properties.name === "pushTransition") {
                    if(properties.enterItem.isDialog) {
                        return pushVTransition
                    } else {
                        return pushHTransition
                    }
                } else {
                    if(properties.exitItem.isDialog) {
                        return popVTransition
                    } else {
                        return popHTransition
                    }

                }
            }

102
103
104
105
106
107
            function transitionFinished(properties)
            {
                properties.exitItem.opacity = 1
                properties.enterItem.play()
                if(!properties.enterItem.isDialog) {
                    properties.exitItem.stop()
108
                }
109
110
111
            }

            property Component pushHTransition: StackViewTransition {
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
                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
                }
            }
129
130

            property Component popHTransition: StackViewTransition {
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
                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
146
147
                }
            }
148

149
150
151
152
153
154
155
156
157
158
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
            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
184
185
                }
            }
186
187

            property Component replaceTransition: pushHTransition
188
189
190
        }
    }
}