Warning, /education/gcompris/src/core/Balloon.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Balloon.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Aruna Sankaranarayanan <arunasank@src.gnome.org> 0004 * 0005 * Authors: 0006 * Aruna Sankaranarayanan <arunasank@src.gnome.org> 0007 * Bruno Coudoin <bruno.coudoin@gcompris.net> Improved Animation 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 import QtQuick 2.12 0013 import GCompris 1.0 0014 0015 /** 0016 * A QML component to visualize countdown. 0017 * 0018 * Balloon usually consists of timeout duration (@ref duration) 0019 * and a boolean to check if animation are running at a moment (@ref disabled). 0020 * 0021 * A balloon falls from top to bottom in a given duration on 0022 * calling startMoving method and stops on calling stopMoving method. 0023 * 0024 * @inherit QtQuick.Image 0025 */ 0026 Image { 0027 id: balloon 0028 source: "qrc:/gcompris/src/core/resource/tuxballoon.svg"; 0029 sourceSize.width: parent.width * 0.4 0030 scale: 0.8 0031 x: parent.width / 2 0032 y: - balloon.height 0033 0034 /** 0035 * type:int 0036 * Height of activity window. 0037 */ 0038 property int parentHeight: parent.height 0039 0040 /** 0041 * Emitted when balloon hits the ground i.e. on completion of time duration. 0042 */ 0043 signal timeout 0044 0045 /** 0046 * Emitted when countdown is ready to start. 0047 */ 0048 signal ready 0049 0050 /** 0051 * type:int 0052 * Total duration of the countdown. 0053 */ 0054 property int duration 0055 0056 /** 0057 * type:boolean 0058 * To know if countdown is running at a moment. 0059 */ 0060 property bool disabled 0061 0062 /** 0063 * type:boolean 0064 * To know if the activity is running or not 0065 * Is set to false in stopBalloon, which should be called by activity's onStop 0066 * to avoid restarting the animation in onParentHeightChanged. 0067 */ 0068 property bool activityRunning: true 0069 0070 onParentHeightChanged: { 0071 if(activityRunning) { 0072 startMoving(duration) 0073 } 0074 } 0075 0076 // Starts the countdown and down animation starts. 0077 function startMoving(durationIncoming) 0078 { 0079 stopMoving() 0080 disabled = false 0081 duration = durationIncoming 0082 down.restart() 0083 } 0084 0085 // Stops the countdown and the down animation stops. 0086 function stopMoving() 0087 { 0088 disabled = true 0089 down.stop() 0090 reinit.start() 0091 } 0092 0093 // Completely stop the ballon when the activity stops. 0094 function stopBalloon() 0095 { 0096 activityRunning = false 0097 disabled = true 0098 down.stop() 0099 reinit.stop() 0100 } 0101 0102 ParallelAnimation { 0103 id: reinit 0104 running: false 0105 NumberAnimation { 0106 target: balloon 0107 property: "scale" 0108 to: 0.8 0109 duration: 1000 0110 } 0111 NumberAnimation { 0112 target: balloon 0113 property: "y" 0114 to: - balloon.height 0115 duration: 1000 0116 easing.type: Easing.InOutQuad 0117 } 0118 NumberAnimation { 0119 target: balloon 0120 property: "rotation" 0121 to: 0 0122 duration: 1000 0123 easing.type: Easing.InOutQuad 0124 } 0125 } 0126 0127 SequentialAnimation { 0128 id: down 0129 0130 onRunningChanged: { 0131 if (!down.running && !balloon.disabled) { 0132 timeout() 0133 } 0134 } 0135 0136 ParallelAnimation { 0137 0138 NumberAnimation { 0139 target: balloon 0140 property: "scale" 0141 to: 0.8 0142 duration: 1000 0143 } 0144 NumberAnimation { 0145 target: balloon 0146 property: "y" 0147 to: - balloon.height 0148 duration: 1000 0149 easing.type: Easing.InOutQuad 0150 } 0151 NumberAnimation { 0152 target: balloon 0153 property: "rotation" 0154 to: 0 0155 duration: 1000 0156 easing.type: Easing.InOutQuad 0157 } 0158 } 0159 0160 ParallelAnimation { 0161 running: false 0162 NumberAnimation { 0163 target: balloon 0164 property: "scale" 0165 to: 1 0166 duration: balloon.duration 0167 } 0168 NumberAnimation { 0169 target: balloon 0170 property: "y" 0171 to: parent.height - balloon.height 0172 duration: balloon.duration 0173 easing.type: Easing.InOutQuad 0174 } 0175 SequentialAnimation { 0176 NumberAnimation { 0177 target: balloon 0178 property: "rotation" 0179 to: -5 0180 duration: 3000 0181 easing.type: Easing.InOutQuad 0182 } 0183 SequentialAnimation { 0184 loops: 1 0185 NumberAnimation { 0186 target: balloon 0187 property: "rotation" 0188 from: -5; to: 5 0189 duration: 3000 0190 easing.type: Easing.InOutQuad 0191 } 0192 NumberAnimation { 0193 target: balloon 0194 property: "rotation" 0195 from: 5; to: -5 0196 duration: 3000 0197 easing.type: Easing.InOutQuad } 0198 } 0199 NumberAnimation { 0200 target: balloon 0201 property: "rotation" 0202 to: 0 0203 duration: 3000 0204 easing.type: Easing.InOutQuad 0205 } 0206 } 0207 } 0208 } 0209 }