Warning, /education/gcompris/src/activities/gletters/FallingWord.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Word.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Holger Kaelberer <holger.k@elberer.de> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Holger Kaelberer <holger.k@elberer.de> (Qt Quick port) 0008 * 0009 * 0010 * SPDX-License-Identifier: GPL-3.0-or-later 0011 */ 0012 import QtQuick 2.12 0013 import QtGraphicalEffects 1.0 0014 import GCompris 1.0 0015 0016 import "../../core" 0017 import "gletters.js" as Activity 0018 0019 Item { 0020 id: word 0021 0022 width: wordText.width 0023 height: wordText.height 0024 0025 /// index into text.split("") where next typed match should occur 0026 property int unmatchedIndex: 0; 0027 property alias text: wordText.text; 0028 property bool wonState: false 0029 property string mode 0030 0031 signal won 0032 0033 onWon: { 0034 wonState = true 0035 particle.burst(30) 0036 dropShadow.opacity = 0 0037 fadeout.restart(); 0038 } 0039 0040 Component.onCompleted: { 0041 // make sure our word is completely visible 0042 if (x + width >= parent.width) 0043 x = parent.width - width; 0044 } 0045 0046 onUnmatchedIndexChanged: { 0047 if (unmatchedIndex <= 0) 0048 highlightedWordText.text = ""; 0049 else if (wordText.text.length > 0 && wordText.text.length >= unmatchedIndex) { 0050 highlightedWordText.text = wordText.text.substring(0, unmatchedIndex); 0051 /* Need to add the ZERO WIDTH JOINER to force joined char in Arabic and 0052 * Hangul: https://en.wikipedia.org/wiki/Zero-width_joiner 0053 * 0054 * FIXME: this works only on desktop systems, on android this 0055 * shifts the typed word a few pixels down. */ 0056 if (!ApplicationInfo.isMobile) 0057 highlightedWordText.text += "\u200C"; 0058 } 0059 } 0060 0061 PropertyAnimation { 0062 id: fadeout 0063 target: word; 0064 property: "opacity" 0065 to: 0 0066 duration: 1000 0067 onStopped: Activity.deleteWord(word); 0068 } 0069 0070 function checkMatch(c) 0071 { 0072 // We are in the ending animation 0073 if (wonState) 0074 return 0075 0076 var chars = text.split(""); 0077 if (chars[unmatchedIndex] === c) { 0078 unmatchedIndex++; 0079 return true; 0080 } else { 0081 unmatchedIndex = 0; 0082 return false; 0083 } 0084 } 0085 0086 function startMoving(dur) 0087 { 0088 down.duration = dur; 0089 down.restart(); 0090 } 0091 0092 function isCompleted() 0093 { 0094 return (unmatchedIndex === text.length); 0095 } 0096 0097 GCText { 0098 id: wordText 0099 text: "" 0100 fontSize: 35 0101 font.bold: true 0102 color: "navy" 0103 style: Text.Outline 0104 styleColor: "white" 0105 0106 ParticleSystemStarLoader { 0107 id: particle 0108 clip: false 0109 } 0110 0111 GCText { 0112 id: highlightedWordText 0113 anchors.fill: parent 0114 text: "" 0115 fontSize: parent.fontSize 0116 font.bold: parent.font.bold 0117 color: "red" 0118 style: Text.Outline 0119 styleColor: "white" 0120 } 0121 } 0122 0123 DropShadow { 0124 id: dropShadow 0125 anchors.fill: wordText 0126 cached: false 0127 horizontalOffset: 1 0128 verticalOffset: 1 0129 radius: 3.0 0130 samples: 16 0131 color: "#422a2a2a" 0132 source: wordText 0133 } 0134 0135 NumberAnimation { 0136 id: down 0137 target: word 0138 property: "y" 0139 to: parent.height 0140 duration: 10000 0141 0142 onStopped: { 0143 Activity.audioCrashPlay(); 0144 Activity.appendRandomWord(word.text) 0145 Activity.deleteWord(word); 0146 } 0147 } 0148 }