Warning, /education/gcompris/src/activities/guessnumber/Guessnumber.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - guessnumber.qml
0002 *
0003 * SPDX-FileCopyrightText: 2014 Thib ROMAIN <thibrom@gmail.com>
0004 *
0005 * Authors:
0006 * Clement Coudoin <clement.coudoin@free.fr> (GTK+ version)
0007 * Thib ROMAIN <thibrom@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 "guessnumber.js" as Activity
0016
0017 ActivityBase {
0018 id: activity
0019
0020 onStart: focus = true
0021 onStop: {}
0022
0023 property alias currentActivity: activity.activityInfo
0024
0025 pageComponent: Rectangle {
0026 id: background
0027 color: "#5a3820"
0028
0029 signal start
0030 signal stop
0031
0032 onWidthChanged: helico.init()
0033 onHeightChanged: helico.init()
0034
0035 Component.onCompleted: {
0036 dialogActivityConfig.initialize()
0037 activity.start.connect(start)
0038 activity.stop.connect(stop)
0039 }
0040
0041 // Add here the QML items you need to access in javascript
0042 QtObject {
0043 id: items
0044 property Item main: activity.main
0045 property alias background: background
0046 property int currentLevel: activity.currentLevel
0047 property alias bonus: bonus
0048 property alias helico: helico
0049 property alias textArea: textArea
0050 property alias infoText: userInfo
0051 property alias answerArea: answerArea
0052 readonly property var levels: activity.datasetLoader.data.length !== 0 ? activity.datasetLoader.data : null
0053 property int currentMax: 0
0054 property alias numpad: numpad
0055 property int maxSize: background.height * 0.16
0056 property int size: 70 * ApplicationInfo.ratio
0057 property int barHeightAddon: ApplicationSettings.isBarHidden ? 1 : 3
0058 }
0059
0060 onStart: { Activity.start(items) }
0061 onStop: { Activity.stop() }
0062
0063 // the cave image needs to be aligned on the right to always see the exit
0064 Image {
0065 source: "resource/cave.svg"
0066 height: parent.height
0067 sourceSize.height: height
0068 anchors.right: parent.right
0069 }
0070
0071 Helico {
0072 id: helico
0073 fillMode: "PreserveAspectFit"
0074 sourceSize.height: height
0075 height: (items.size>items.maxSize) ? items.maxSize : items.size
0076 }
0077
0078 GCText {
0079 id: textArea
0080 anchors.top: parent.top
0081 anchors.topMargin: 10
0082 anchors.left: parent.left
0083 anchors.leftMargin: numpad.columnWidth + 10
0084 anchors.right: answerArea.left
0085 horizontalAlignment: Text.AlignHCenter
0086 width: parent.width - answerArea.width - 10
0087 wrapMode: TextEdit.WordWrap
0088 color: "white"
0089 font.bold: true
0090 fontSize: mediumSize
0091 }
0092
0093 AnswerArea {
0094 id: answerArea
0095 anchors.right: parent.right
0096 anchors.rightMargin: numpad.visible ?
0097 numpad.columnWidth + 10 * ApplicationInfo.ratio :
0098 10 * ApplicationInfo.ratio
0099 anchors.top: parent.top
0100 anchors.topMargin: 10
0101 }
0102
0103 GCText {
0104 id: userInfo
0105 anchors.top: textArea.top
0106 anchors.topMargin: 15 + textArea.contentHeight
0107 anchors.horizontalCenter: textArea.horizontalCenter
0108 color: "white"
0109 font.bold: true
0110 fontSize: regularSize
0111 }
0112
0113 NumPad {
0114 id: numpad
0115 onAnswerChanged: {
0116 if(answer && answerArea.userEntry != answer)
0117 activity.audioEffects.play('qrc:/gcompris/src/activities/guessnumber/resource/helicopter.wav')
0118 answerArea.userEntry = answer
0119 }
0120 maxDigit: ("" + items.currentMax).length
0121 columnWidth: 60 * ApplicationInfo.ratio
0122 enableInput: !bonus.isPlaying
0123 }
0124
0125 Keys.onPressed: {
0126 numpad.updateAnswer(event.key, true);
0127 }
0128
0129 Keys.onReleased: {
0130 numpad.updateAnswer(event.key, false);
0131 }
0132
0133 DialogChooseLevel {
0134 id: dialogActivityConfig
0135 currentActivity: activity.activityInfo
0136
0137 onSaveData: {
0138 levelFolder = dialogActivityConfig.chosenLevels
0139 currentActivity.currentLevels = dialogActivityConfig.chosenLevels
0140 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels)
0141 }
0142
0143 onLoadData: {
0144 if(activityData) {
0145 Activity.initLevel()
0146 }
0147 }
0148 onClose: {
0149 home()
0150 }
0151 onStartActivity: {
0152 background.stop()
0153 background.start()
0154 }
0155 }
0156
0157 DialogHelp {
0158 id: dialogHelp
0159 onClose: home()
0160 }
0161
0162 Bar {
0163 id: bar
0164 level: items.currentLevel + 1
0165 content: BarEnumContent { value: help | home | level | activityConfig }
0166 onHelpClicked: {
0167 displayDialog(dialogHelp)
0168 }
0169 onActivityConfigClicked: {
0170 displayDialog(dialogActivityConfig)
0171 }
0172 onPreviousLevelClicked: Activity.previousLevel()
0173 onNextLevelClicked: Activity.nextLevel()
0174 onHomeClicked: activity.home()
0175 }
0176
0177 Bonus {
0178 id: bonus
0179 Component.onCompleted: win.connect(Activity.nextLevel)
0180 }
0181 }
0182
0183 }