• Skip to content
  • Skip to link menu
KDE API Documentation - main.qml Source File (GCompris-qt)
  • KDE Home
  • Contact Us
 

GCompris-qt

  • src
  • core
main.qml
1 /* GCompris - main.qml
2  *
3  * Copyright (C) 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
4  *
5  * Authors:
6  * Bruno Coudoin <bruno.coudoin@gcompris.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 import QtQuick 2.2
22 import QtQuick.Controls 1.0
23 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 
44 Window {
45  id: main
46  width: 800
47  height: 520
48  minimumWidth: 400
49  minimumHeight: 400
50  title: "GCompris"
51 
53 
54  property var applicationState: Qt.application.state
55 
56  onApplicationStateChanged: {
57  if (ApplicationInfo.isMobile && applicationState != Qt.ApplicationActive) {
58  audioVoices.stop();
59  audioEffects.stop();
60  }
61  }
62 
63  onClosing: Core.quit()
64 
65  GCAudio {
66  id: audioVoices
67  muted: !ApplicationSettings.isAudioVoicesEnabled
68 
69  Timer {
70  id: delayedWelcomeTimer
71  interval: 10000 /* Make sure, that playing welcome.ogg if delayed
72  * because of not yet registered voices, will only
73  * happen max 10sec after startup */
74  repeat: false
75 
76  onTriggered: {
77  DownloadManager.voicesRegistered.disconnect(playWelcome);
78  }
79 
80  function playWelcome() {
81  audioVoices.append(ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/misc/welcome.$CA"));
82  }
83  }
84 
85  Component.onCompleted: {
86  if(ApplicationSettings.isAudioEffectsEnabled)
87  append(ApplicationInfo.getAudioFilePath("qrc:/gcompris/src/core/resource/intro.$CA"))
88 
89  if (DownloadManager.areVoicesRegistered())
90  delayedWelcomeTimer.playWelcome();
91  else {
92  DownloadManager.voicesRegistered.connect(
93  delayedWelcomeTimer.playWelcome);
94  delayedWelcomeTimer.start();
95  }
96  }
97  }
98 
99  GCAudio {
100  id: audioEffects
101  muted: !ApplicationSettings.isAudioEffectsEnabled
102  }
103 
104  function playIntroVoice(name) {
105  name = name.split("/")[0]
106  audioVoices.append(ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/intro/" + name + ".$CA"))
107  }
108 
109  Component.onCompleted: {
110  console.log("enter main.qml (run #" + ApplicationSettings.exeCount
111  + ", ratio=" + ApplicationInfo.ratio
112  + ", fontRatio=" + ApplicationInfo.fontRatio
113  + ", dpi=" + Math.round(Screen.pixelDensity*25.4) + ")");
114  if (ApplicationSettings.exeCount == 1 && !ApplicationSettings.isKioskMode) {
115  // first run
116  var dialog;
117  dialog = Core.showMessageDialog(
118  main,
119  qsTr("Welcome to GCompris!") + '\n'
120  + qsTr("You are running GCompris for the first time.") + '\n'
121  + 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.")
122  + "\n"
123  + qsTr("Have Fun!")
124  + "\n"
125  + qsTr("Your current language is %1 (%2).")
126  .arg(Qt.locale(ApplicationInfo.localeShort).nativeLanguageName)
127  .arg(ApplicationInfo.localeShort)
128  + "\n"
129  + qsTr("Do you want to download the corresponding sound files now?"),
130  qsTr("Yes"),
131  function() {
132  if (DownloadManager.downloadResource(
133  DownloadManager.getVoicesResourceForLocale(ApplicationInfo.localeShort)))
134  var downloadDialog = Core.showDownloadDialog(pageView.currentItem, {});
135  },
136  qsTr("No"), null,
137  function() { pageView.currentItem.focus = true }
138  );
139  }
140  }
141 
142  StackView {
143  id: pageView
144  anchors.fill: parent
145  initialItem: {
146  "item": "qrc:/gcompris/src/activities/" + ActivityInfoTree.rootMenu.name,
147  "properties": {
148  'audioVoices': audioVoices,
149  'audioEffects': audioEffects
150  }
151  }
152 
153  focus: ApplicationInfo.QTVersion >= "5.4.0"
154 
155  delegate: StackViewDelegate {
156  id: root
157  function getTransition(properties)
158  {
159  audioVoices.clearQueue()
160  if(!properties.exitItem.isDialog) {
161  if(!properties.enterItem.isDialog) {
162  playIntroVoice(properties.enterItem.activityInfo.name)
163  }
164  properties.enterItem.start()
165  }
166 
167  if(properties.name === "pushTransition") {
168  if(properties.enterItem.isDialog) {
169  return pushVTransition
170  } else {
171  return pushHTransition
172  }
173  } else {
174  if(properties.exitItem.isDialog) {
175  return popVTransition
176  } else {
177  return popHTransition
178  }
179 
180  }
181  }
182 
183  function transitionFinished(properties)
184  {
185  properties.exitItem.opacity = 1
186  if(!properties.enterItem.isDialog) {
187  properties.exitItem.stop()
188  }
189  }
190 
191  property Component pushHTransition: StackViewTransition {
192  PropertyAnimation {
193  target: enterItem
194  property: "x"
195  from: target.width
196  to: 0
197  duration: 500
198  easing.type: Easing.OutSine
199  }
200  PropertyAnimation {
201  target: exitItem
202  property: "x"
203  from: 0
204  to: -target.width
205  duration: 500
206  easing.type: Easing.OutSine
207  }
208  }
209 
210  property Component popHTransition: StackViewTransition {
211  PropertyAnimation {
212  target: enterItem
213  property: "x"
214  from: -target.width
215  to: 0
216  duration: 500
217  easing.type: Easing.OutSine
218  }
219  PropertyAnimation {
220  target: exitItem
221  property: "x"
222  from: 0
223  to: target.width
224  duration: 500
225  easing.type: Easing.OutSine
226  }
227  }
228 
229  property Component pushVTransition: StackViewTransition {
230  PropertyAnimation {
231  target: enterItem
232  property: "y"
233  from: -target.height
234  to: 0
235  duration: 500
236  easing.type: Easing.OutSine
237  }
238  PropertyAnimation {
239  target: exitItem
240  property: "y"
241  from: 0
242  to: target.height
243  duration: 500
244  easing.type: Easing.OutSine
245  }
246  }
247 
248  property Component popVTransition: StackViewTransition {
249  PropertyAnimation {
250  target: enterItem
251  property: "y"
252  from: target.height
253  to: 0
254  duration: 500
255  easing.type: Easing.OutSine
256  }
257  PropertyAnimation {
258  target: exitItem
259  property: "y"
260  from: 0
261  to: -target.height
262  duration: 500
263  easing.type: Easing.OutSine
264  }
265  }
266 
267  property Component replaceTransition: pushHTransition
268  }
269  }
270 
272 }
ApplicationInfo::QTVersion
QString QTVersion
Qt version string (runtime).
Definition: ApplicationInfo.h:121
QtQuick
DownloadManager
A singleton class responsible for downloading, updating and maintaining remote resources.
Definition: DownloadManager.h:81
ApplicationInfo::getAudioFilePath
Q_INVOKABLE QString getAudioFilePath(const QString &file)
Returns an absolute path to a language specific sound/voices file.
Definition: ApplicationInfo.cpp:127
GCAudio
A QML component for audio playback.
Definition: GCAudio.qml:44
DownloadManager::downloadResource
Q_INVOKABLE bool downloadResource(const QString &path)
Download a resource specified by the relative resource path and register it if possible.
Definition: DownloadManager.cpp:167
ApplicationInfo::localeShort
QString localeShort
Short (2-letter) locale string of the currently active language.
Definition: ApplicationInfo.h:111
ApplicationSettings::isKioskMode
bool isKioskMode
Whether kiosk mode is currently active.
Definition: ApplicationSettings.h:149
GCompris
QtQml
ApplicationSettings::isAudioEffectsEnabled
bool isAudioEffectsEnabled
Whether audio effects should be enabled.
Definition: ApplicationSettings.h:83
ApplicationSettings
Singleton that contains GCompris' persistent settings.
Definition: ApplicationSettings.h:63
ApplicationInfo::isMobile
bool isMobile
Whether the application is currently running on a mobile platform.
Definition: ApplicationInfo.h:65
main
GCompris' main QML file defining the top level window.
Definition: main.qml:41
DownloadManager::getVoicesResourceForLocale
Q_INVOKABLE QString getVoicesResourceForLocale(const QString &locale) const
Generates a relative voices resources file-path for a given locale.
Definition: DownloadManager.cpp:120
DownloadManager::voicesRegistered
void voicesRegistered()
Emitted when voices resources for current locale have been registered.
ApplicationInfo
A general purpose singleton that exposes miscellaneous native functions to the QML layer...
Definition: ApplicationInfo.h:43
ApplicationSettings::isAudioVoicesEnabled
bool isAudioVoicesEnabled
Whether audio voices/speech should be enabled.
Definition: ApplicationSettings.h:78
DownloadManager::areVoicesRegistered
Q_INVOKABLE bool areVoicesRegistered() const
Whether voices for the currently active locale are registered.
Definition: DownloadManager.cpp:483
ApplicationInfo::fontRatio
qreal fontRatio
Ratio factor used for font scaling.
Definition: ApplicationInfo.h:106
ApplicationInfo::ratio
qreal ratio
Ratio factor used for scaling of sizes on high-dpi devices.
Definition: ApplicationInfo.h:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jun 2 2015 21:47:47 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GCompris-qt

Skip menu "GCompris-qt"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal