Warning, /education/gcompris/src/activities/braille_fun/BrailleFun.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - braille_fun.qml
0002 *
0003 * SPDX-FileCopyrightText: 2014 Arkit Vora <arkitvora123@gmail.com>
0004 *
0005 * Authors:
0006 * Srishti Sethi (GTK+ version)
0007 * Arkit Vora <arkitvora123@gmail.com> (Qt Quick port)
0008 *
0009 * SPDX-License-Identifier: GPL-3.0-or-later
0010 */
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013
0014 import "../../core"
0015 import "../braille_alphabets"
0016 import "braille_fun.js" as Activity
0017
0018
0019
0020 ActivityBase {
0021 id: activity
0022
0023 onStart: focus = true
0024 onStop: {}
0025
0026 pageComponent: Image {
0027 id: background
0028 anchors.fill: parent
0029 fillMode: Image.PreserveAspectCrop
0030 sourceSize.width: width
0031 sourceSize.height: height
0032 source: Activity.url + "hillside.svg"
0033 signal start
0034 signal stop
0035
0036 Component.onCompleted: {
0037 activity.start.connect(start)
0038 activity.stop.connect(stop)
0039 }
0040
0041 Keys.onPressed: {
0042 if(event.key === Qt.Key_Space)
0043 brailleMap.clicked();
0044 }
0045
0046 // Add here the QML items you need to access in javascript
0047 QtObject {
0048 id: items
0049 property Item main: activity.main
0050 property alias background: background
0051 property GCSfx audioEffects: activity.audioEffects
0052 property int currentLevel: activity.currentLevel
0053 property alias bonus: bonus
0054 property alias questionItem: questionItem
0055 property alias score: score
0056 property alias cardRepeater: cardRepeater
0057 property alias animateX: animateX
0058 property alias charBg: charBg
0059 property string question
0060 property int baseMargins: 10 * ApplicationInfo.ratio
0061 }
0062
0063 onStart: { Activity.start(items) }
0064 onStop: { Activity.stop() }
0065
0066 Item {
0067 id: layoutArea
0068 anchors.top: planeText.bottom
0069 anchors.bottom: background.bottom
0070 anchors.left: background.left
0071 anchors.right: background.right
0072 anchors.bottomMargin: bar.height * 1.3
0073 }
0074
0075 Item {
0076 id: planeText
0077 width: plane.width
0078 height: plane.height
0079 x: - width
0080 anchors.top: parent.top
0081 anchors.topMargin: 20 * ApplicationInfo.ratio
0082
0083 Image {
0084 id: plane
0085 anchors.centerIn: planeText
0086 anchors.top: parent.top
0087 source: Activity.url + "plane.svg"
0088 sourceSize.height: 90 * ApplicationInfo.ratio
0089 }
0090
0091 GCText {
0092 id: questionItem
0093 anchors.right: planeText.right
0094 anchors.rightMargin: plane.width / 2
0095 anchors.verticalCenter: planeText.verticalCenter
0096 fontSize: hugeSize
0097 font.weight: Font.DemiBold
0098 color: "#2a2a2a"
0099 text: items.question
0100 }
0101
0102 PropertyAnimation {
0103 id: animateX
0104 target: planeText
0105 properties: "x"
0106 from: - planeText.width
0107 to: background.width
0108 duration: 11000
0109 easing.type: Easing.OutInCirc
0110 loops: Animation.Infinite
0111 }
0112 }
0113
0114 Item {
0115 id: charBg
0116 anchors {
0117 top: layoutArea.top
0118 bottom: score.top
0119 left: layoutArea.left
0120 right: layoutArea.right
0121 margins: items.baseMargins
0122 }
0123
0124 property int charWidth: Math.min(120 * ApplicationInfo.ratio, width * 0.3)
0125
0126 function clickable(status) {
0127 for(var i=0 ; i < cardRepeater.model ; i++) {
0128 cardRepeater.itemAt(i).ins.clickable = status
0129 }
0130 }
0131
0132 function clearAllLetters() {
0133 for(var i=0 ; i < cardRepeater.model ; i++) {
0134 cardRepeater.itemAt(i).ins.clearLetter()
0135 }
0136 }
0137
0138 Row {
0139 id: row
0140 spacing: items.baseMargins
0141 anchors.centerIn: parent
0142
0143 Repeater {
0144 id: cardRepeater
0145
0146 Item {
0147 id: inner
0148 height: charBg.height - 2 * items.baseMargins
0149 width: charBg.charWidth
0150 property string brailleChar: ins.brailleChar
0151 property alias ins: ins
0152
0153 Rectangle {
0154 id: rect1
0155 width: parent.width
0156 height: ins.height
0157 anchors.horizontalCenter: inner.horizontalCenter
0158 anchors.top: parent.top
0159 border.width: ins.found ? 0 : 2 * ApplicationInfo.ratio
0160 border.color: "#fff"
0161 radius: items.baseMargins
0162 color: ins.found ? '#85d8f6' : "#dfe1e8"
0163
0164 BrailleChar {
0165 id: ins
0166 clickable: true
0167 anchors.centerIn: rect1
0168 width: parent.width * 0.5
0169 isLetter: true
0170 onBrailleCharChanged: {
0171 inner.brailleChar = ins.brailleChar
0172 var answerString = "" ;
0173 if(brailleChar == "") {
0174 // fix TypeError on level change
0175 return
0176 }
0177 for(var i = 0 ; i < items.currentLevel + 1 ; i++ ) {
0178 answerString = answerString + cardRepeater.itemAt(i).brailleChar;
0179 }
0180 if(answerString === items.question) {
0181 charBg.clickable(false)
0182 Activity.goodAnswer()
0183 }
0184 }
0185 property string question: items.question[modelData] ? items.question[modelData] : ""
0186 property bool found: question === brailleChar
0187 }
0188 }
0189
0190 GCText {
0191 text: brailleChar
0192 font.weight: Font.DemiBold
0193 color: "#2a2a2a"
0194 fontSize: hugeSize
0195 anchors {
0196 top: rect1.bottom
0197 topMargin: 4 * ApplicationInfo.ratio
0198 horizontalCenter: rect1.horizontalCenter
0199 }
0200 }
0201 }
0202
0203 }
0204 }
0205 }
0206
0207 Score {
0208 id: score
0209 anchors.bottom: layoutArea.bottom
0210 anchors.right: layoutArea.right
0211 anchors.rightMargin: items.baseMargins
0212 anchors.top: undefined
0213 anchors.left: undefined
0214 onStop: Activity.nextQuestion()
0215 }
0216
0217
0218 DialogHelp {
0219 id: dialogHelp
0220 onClose: home()
0221 }
0222
0223 BrailleMap {
0224 id: dialogMap
0225 onClose: home()
0226 }
0227
0228 Bar {
0229 id: bar
0230 level: items.currentLevel + 1
0231 content: BarEnumContent { value: help | home | level }
0232 onHelpClicked: {
0233 displayDialog(dialogHelp)
0234 }
0235 onPreviousLevelClicked: Activity.previousLevel()
0236 onNextLevelClicked: Activity.nextLevel()
0237 onHomeClicked: activity.home()
0238 }
0239
0240 BarButton {
0241 id: brailleMap
0242 source: "qrc:/gcompris/src/activities/braille_alphabets/resource/braille_button.svg"
0243 anchors {
0244 right: background.right
0245 top: background.top
0246 margins: items.baseMargins
0247 }
0248 sourceSize.width: 60 * ApplicationInfo.ratio
0249 onClicked: {
0250 dialogMap.visible = true
0251 displayDialog(dialogMap)
0252 }
0253 }
0254
0255 Bonus {
0256 id: bonus
0257 Component.onCompleted: {
0258 win.connect(Activity.nextLevel)
0259 }
0260 }
0261 }
0262
0263 }