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

GCompris-qt

  • src
  • core
Bonus.qml
1 /* GCompris - Bonus.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 GCompris 1.0
23 
24 // Requires the global property in the scope:
25 // property GCAudio audioEffects, audioVoices
26 
41 Image {
42  id: bonus
43 
48  property string winSound: url + "sounds/bonus.wav"
49 
54  property string looseSound
55 
61  signal win
62 
68  signal loose
69 
71  property string url: "qrc:/gcompris/src/core/resource/"
72  property bool isWin: false
73  property var winVoices: [
74  "voices-$CA/$LOCALE/misc/congratulation.$CA",
75  "voices-$CA/$LOCALE/misc/great.$CA",
76  "voices-$CA/$LOCALE/misc/good.$CA",
77  "voices-$CA/$LOCALE/misc/awesome.$CA",
78  "voices-$CA/$LOCALE/misc/fantastic.$CA",
79  "voices-$CA/$LOCALE/misc/waytogo.$CA",
80  "voices-$CA/$LOCALE/misc/super.$CA",
81  "voices-$CA/$LOCALE/misc/perfect.$CA"
82  ]
83  property var looseVoices: [
84  "voices-$CA/$LOCALE/misc/check_answer.$CA"
85  ]
87 
88  visible: true
89  opacity: 0
90  anchors.fill: parent
91  fillMode: Image.Pad
92  z: 1000
93  scale: ApplicationInfo.ratio
94 
104  function good(name) {
105  if(!audioVoices.play(
106  ApplicationInfo.getAudioFilePath(
107  winVoices[Math.floor(Math.random()*winVoices.length)])))
108  if(winSound)
109  audioEffects.play(winSound)
110  source = url + "bonus/" + name + "_good.svg"
111  isWin = true;
112  animation.start()
113  }
114 
124  function bad(name) {
125  if(!audioEffects.play(
126  ApplicationInfo.getAudioFilePath(
127  looseVoices[Math.floor(Math.random()*looseVoices.length)])))
128  if(looseSound)
129  audioEffects.play(looseSound)
130  source = url + "bonus/" + name + "_bad.svg"
131  isWin = false;
132  animation.start()
133  }
134 
135  SequentialAnimation {
136  id: animation
137  NumberAnimation {
138  target: bonus
139  property: "opacity"
140  from: 0; to: 1.0
141  duration: 1000
142  easing.type: Easing.InOutQuad
143  }
144  NumberAnimation {
145  target: bonus
146  property: "opacity"
147  from: 1.0; to: 0
148  duration: 500
149  easing.type: Easing.InOutQuad
150  }
151  onStopped: isWin ? win() : loose()
152  }
153 }
QtQuick
ApplicationInfo::getAudioFilePath
Q_INVOKABLE QString getAudioFilePath(const QString &file)
Returns an absolute path to a language specific sound/voices file.
Definition: ApplicationInfo.cpp:127
GCompris
ApplicationInfo
A general purpose singleton that exposes miscellaneous native functions to the QML layer...
Definition: ApplicationInfo.h:43
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