Changeset View
Standalone View
src/activities/scalesboard/Scalesboard.qml
Show All 23 Lines | |||||
24 | 24 | | |||
25 | import "../../core" | 25 | import "../../core" | ||
26 | import "scalesboard.js" as Activity | 26 | import "scalesboard.js" as Activity | ||
27 | import "." | 27 | import "." | ||
28 | 28 | | |||
29 | ActivityBase { | 29 | ActivityBase { | ||
30 | id: activity | 30 | id: activity | ||
31 | 31 | | |||
32 | property var dataset | | |||
33 | 32 | | |||
34 | onStart: focus = true | 33 | onStart: focus = true | ||
35 | onStop: {} | 34 | onStop: {} | ||
36 | 35 | | |||
37 | pageComponent: Image { | 36 | pageComponent: Image { | ||
38 | id: background | 37 | id: background | ||
39 | anchors.fill: parent | 38 | anchors.fill: parent | ||
40 | source: Activity.url + "background.svg" | 39 | source: Activity.url + "background.svg" | ||
41 | sourceSize.width: Math.max(parent.width, parent.height) | 40 | sourceSize.width: Math.max(parent.width, parent.height) | ||
42 | fillMode: Image.PreserveAspectCrop | 41 | fillMode: Image.PreserveAspectCrop | ||
43 | signal start | 42 | signal start | ||
44 | signal stop | 43 | signal stop | ||
45 | 44 | | |||
46 | property int scaleHeight: items.masseAreaLeft.weight == items.masseAreaRight.weight ? 0 : | 45 | property int scaleHeight: items.masseAreaLeft.weight == items.masseAreaRight.weight ? 0 : | ||
47 | items.masseAreaLeft.weight > items.masseAreaRight.weight ? 20 : -20 | 46 | items.masseAreaLeft.weight > items.masseAreaRight.weight ? 20 : -20 | ||
48 | 47 | | |||
49 | Component.onCompleted: { | 48 | Component.onCompleted: { | ||
49 | dialogActivityConfig.initialize() | ||||
50 | activity.start.connect(start) | 50 | activity.start.connect(start) | ||
51 | activity.stop.connect(stop) | 51 | activity.stop.connect(stop) | ||
52 | } | 52 | } | ||
53 | 53 | | |||
54 | // Add here the QML items you need to access in javascript | 54 | // Add here the QML items you need to access in javascript | ||
55 | QtObject { | 55 | QtObject { | ||
56 | id: items | 56 | id: items | ||
57 | property Item main: activity.main | 57 | property Item main: activity.main | ||
58 | property alias background: background | 58 | property alias background: background | ||
59 | property alias bar: bar | 59 | property alias bar: bar | ||
60 | property alias bonus: bonus | 60 | property alias bonus: bonus | ||
61 | property int numberOfSubLevels | 61 | property int numberOfSubLevels | ||
62 | property int currentSubLevel | 62 | property int currentSubLevel | ||
63 | property int giftWeight | 63 | property int giftWeight | ||
64 | property var dataset: activity.dataset | 64 | property int scaleHeight: background.scaleHeight | ||
65 | property var levels: activity.datasetLoader.data | ||||
65 | property alias masseAreaCenter: masseAreaCenter | 66 | property alias masseAreaCenter: masseAreaCenter | ||
66 | property alias masseAreaLeft: masseAreaLeft | 67 | property alias masseAreaLeft: masseAreaLeft | ||
67 | property alias masseAreaRight: masseAreaRight | 68 | property alias masseAreaRight: masseAreaRight | ||
68 | property alias masseCenterModel: masseAreaCenter.masseModel | 69 | property alias masseCenterModel: masseAreaCenter.masseModel | ||
69 | property alias masseRightModel: masseAreaRight.masseModel | 70 | property alias masseRightModel: masseAreaRight.masseModel | ||
70 | property alias question: question | 71 | property alias question: question | ||
71 | property alias numpad: numpad | 72 | property alias numpad: numpad | ||
73 | property bool rightDrop | ||||
72 | } | 74 | } | ||
73 | 75 | | |||
74 | onStart: { Activity.start(items) } | 76 | onStart: { Activity.start(items) } | ||
75 | onStop: { Activity.stop() } | 77 | onStop: { Activity.stop() } | ||
76 | 78 | | |||
77 | property bool vert: background.width > background.height | 79 | property bool vert: background.width > background.height | ||
78 | 80 | | |||
79 | onScaleHeightChanged: Activity.initCompleted && scaleHeight == 0 && question.hasText == "" ? | | |||
80 | bonus.good("flower") : | | |||
81 | activity.audioEffects.play('qrc:/gcompris/src/activities/erase/resource/eraser2.wav') | | |||
82 | | ||||
83 | Image { | 81 | Image { | ||
84 | id: scale | 82 | id: scale | ||
85 | source: Activity.url + "scale.svg" | 83 | source: Activity.url + "scale.svg" | ||
86 | sourceSize.width: Math.min(parent.width - 10 * ApplicationInfo.ratio, | 84 | sourceSize.width: Math.min(parent.width - 10 * ApplicationInfo.ratio, | ||
87 | (parent.height - bar.height - 10 * ApplicationInfo.ratio) * 2) | 85 | (parent.height - bar.height - 10 * ApplicationInfo.ratio) * 2) | ||
88 | anchors.centerIn: parent | 86 | anchors.centerIn: parent | ||
89 | } | 87 | } | ||
90 | 88 | | |||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 186 | anchors { | |||
190 | horizontalCenterOffset: parent.paintedWidth * 0.3 | 188 | horizontalCenterOffset: parent.paintedWidth * 0.3 | ||
191 | verticalCenter: parent.verticalCenter | 189 | verticalCenter: parent.verticalCenter | ||
192 | verticalCenterOffset: - parent.paintedHeight * 0.44 - background.scaleHeight | 190 | verticalCenterOffset: - parent.paintedHeight * 0.44 - background.scaleHeight | ||
193 | } | 191 | } | ||
194 | masseAreaCenter: masseAreaCenter | 192 | masseAreaCenter: masseAreaCenter | ||
195 | masseAreaLeft: masseAreaLeft | 193 | masseAreaLeft: masseAreaLeft | ||
196 | masseAreaRight: masseAreaRight | 194 | masseAreaRight: masseAreaRight | ||
197 | nbColumns: 3 | 195 | nbColumns: 3 | ||
198 | dropEnabledForThisLevel: items.dataset[bar.level - 1].rightDrop | 196 | dropEnabledForThisLevel: items.rightDrop | ||
199 | audioEffects: activity.audioEffects | 197 | audioEffects: activity.audioEffects | ||
200 | 198 | | |||
201 | Behavior on anchors.verticalCenterOffset { | 199 | Behavior on anchors.verticalCenterOffset { | ||
202 | NumberAnimation { | 200 | NumberAnimation { | ||
203 | duration: 500 | 201 | duration: 500 | ||
204 | easing.type: Easing.InOutQuad | 202 | easing.type: Easing.InOutQuad | ||
205 | } | 203 | } | ||
206 | } | 204 | } | ||
Show All 9 Lines | 209 | MasseArea { | |||
216 | width: parent.width | 214 | width: parent.width | ||
217 | masseAreaCenter: masseAreaCenter | 215 | masseAreaCenter: masseAreaCenter | ||
218 | masseAreaLeft: masseAreaLeft | 216 | masseAreaLeft: masseAreaLeft | ||
219 | masseAreaRight: masseAreaRight | 217 | masseAreaRight: masseAreaRight | ||
220 | nbColumns: masseModel.count | 218 | nbColumns: masseModel.count | ||
221 | audioEffects: activity.audioEffects | 219 | audioEffects: activity.audioEffects | ||
222 | } | 220 | } | ||
223 | 221 | | |||
224 | | ||||
225 | Message { | 222 | Message { | ||
226 | id: message | 223 | id: message | ||
227 | anchors { | 224 | anchors { | ||
228 | top: parent.top | 225 | top: parent.top | ||
229 | topMargin: 10 | 226 | topMargin: 10 | ||
230 | right: parent.right | 227 | right: parent.right | ||
231 | rightMargin: 10 | 228 | rightMargin: 10 | ||
232 | left: parent.left | 229 | left: parent.left | ||
233 | leftMargin: 10 | 230 | leftMargin: 10 | ||
234 | } | 231 | } | ||
235 | } | 232 | } | ||
236 | 233 | | |||
237 | Question { | 234 | Question { | ||
238 | id: question | 235 | id: question | ||
239 | parent: scale | 236 | parent: scale | ||
240 | anchors.horizontalCenter: parent.horizontalCenter | 237 | anchors.horizontalCenter: parent.horizontalCenter | ||
241 | y: parent.height * 0.45 | 238 | y: parent.height * 0.45 | ||
242 | z: 1000 | 239 | z: 1000 | ||
243 | width: parent.width - y | 240 | width: parent.width - y | ||
244 | text: items.dataset[bar.level - 1].question && background.scaleHeight == 0 ? | | |||
245 | items.dataset[bar.level - 1].question : "" | | |||
246 | answer: items.giftWeight | 241 | answer: items.giftWeight | ||
jjazeix: can you rework this?
It seems items.question is this "Question" so it does not make any sense… | |||||
242 | visible: (items.question.text && background.scaleHeight === 0) ? true : false | ||||
jjazeix: (background.scaleHeight === 0) | |||||
there is already a "displayed" property in the Question.qml, is it necessary to duplicate it? jjazeix: there is already a "displayed" property in the Question.qml, is it necessary to duplicate it? | |||||
243 | } | ||||
244 | | ||||
jjazeix: (items.question.text !== "") | |||||
245 | DialogChooseLevel { | ||||
246 | id: dialogActivityConfig | ||||
247 | currentActivity: activity.activityInfo | ||||
247 | 248 | | |||
248 | property bool hasText: items.dataset[bar.level - 1].question ? true : false | 249 | onSaveData: { | ||
250 | levelFolder = dialogActivityConfig.chosenLevels | ||||
251 | currentActivity.currentLevels = dialogActivityConfig.chosenLevels | ||||
252 | ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) | ||||
253 | // restart activity on saving | ||||
254 | background.start() | ||||
255 | } | ||||
256 | onClose: { | ||||
257 | home() | ||||
258 | } | ||||
259 | onStartActivity: { | ||||
260 | background.start() | ||||
261 | } | ||||
jjazeix: Same as above, can it be replaced with the "displayed" property? | |||||
249 | } | 262 | } | ||
250 | 263 | | |||
251 | DialogHelp { | 264 | DialogHelp { | ||
252 | id: dialogHelp | 265 | id: dialogHelp | ||
253 | onClose: home() | 266 | onClose: home() | ||
254 | } | 267 | } | ||
255 | 268 | | |||
269 | BarButton { | ||||
270 | id: okButton | ||||
271 | source: "qrc:/gcompris/src/core/resource/bar_ok.svg" | ||||
272 | sourceSize.width: 60 * ApplicationInfo.ratio | ||||
273 | anchors.bottom: bar.top | ||||
274 | anchors.bottomMargin: parent.width * 0.03 | ||||
275 | anchors.left: score.left | ||||
276 | anchors.leftMargin: parent.width * 0.01 | ||||
277 | visible: (!question.text || items.question.userEntry) ? true : false | ||||
jjazeix: true/false | |||||
jjazeix: remove extra space | |||||
278 | ParticleSystemStarLoader { | ||||
279 | id: okButtonParticles | ||||
280 | clip: false | ||||
281 | } | ||||
282 | MouseArea { | ||||
283 | id: okButtonMouseArea | ||||
284 | anchors.fill: parent | ||||
285 | onClicked: { | ||||
286 | Activity.checkAnswer() | ||||
287 | } | ||||
288 | } | ||||
289 | } | ||||
290 | | ||||
256 | Bar { | 291 | Bar { | ||
257 | id: bar | 292 | id: bar | ||
258 | content: BarEnumContent { value: help | home | level } | 293 | content: BarEnumContent { value: help | home | level | activityConfig } | ||
259 | onHelpClicked: { | 294 | onHelpClicked: { | ||
260 | displayDialog(dialogHelp) | 295 | displayDialog(dialogHelp) | ||
261 | } | 296 | } | ||
262 | onPreviousLevelClicked: Activity.previousLevel() | 297 | onPreviousLevelClicked: Activity.previousLevel() | ||
263 | onNextLevelClicked: Activity.nextLevel() | 298 | onNextLevelClicked: Activity.nextLevel() | ||
264 | onHomeClicked: activity.home() | 299 | onHomeClicked: activity.home() | ||
265 | 300 | onActivityConfigClicked: { | |||
266 | onLevelChanged: message.text = items.dataset[bar.level - 1].message ? items.dataset[bar.level - 1].message : "" | 301 | displayDialog(dialogActivityConfig) | ||
302 | } | ||||
303 | onLevelChanged: message.text = items.levels[bar.level - 1].message ? items.levels[bar.level - 1].message : "" | ||||
267 | } | 304 | } | ||
268 | 305 | | |||
269 | Score { | 306 | Score { | ||
270 | id: score | 307 | id: score | ||
271 | anchors { | 308 | anchors { | ||
272 | bottom: background.vert ? background.bottom : bar.top | 309 | bottom: background.vert ? background.bottom : bar.top | ||
273 | right: parent.right | 310 | right: parent.right | ||
274 | bottomMargin: 10 * ApplicationInfo.ratio | 311 | bottomMargin: 10 * ApplicationInfo.ratio | ||
275 | } | 312 | } | ||
276 | 313 | | |||
277 | numberOfSubLevels: items.numberOfSubLevels | 314 | numberOfSubLevels: items.numberOfSubLevels | ||
278 | currentSubLevel: items.currentSubLevel | 315 | currentSubLevel: items.currentSubLevel | ||
279 | opacity: question.displayed ? 0 : 1 | | |||
280 | } | 316 | } | ||
@echarruau does it make sense to hide the sublevel counter when we are in a "Guess the weight" question? jjazeix: @echarruau does it make sense to hide the sublevel counter when we are in a "Guess the weight"… | |||||
It does not make sens to hide it. Pupils need to be able to go down a level if they are not managing this level to retrain the precedent one. echarruau: It does not make sens to hide it. Pupils need to be able to go down a level if they are not… | |||||
281 | 317 | | |||
282 | NumPad { | 318 | NumPad { | ||
283 | id: numpad | 319 | id: numpad | ||
284 | onAnswerChanged: question.userEntry = answer | 320 | onAnswerChanged: question.userEntry = answer | ||
285 | maxDigit: ('' + items.giftWeight).length + 1 | 321 | maxDigit: ('' + items.giftWeight).length + 1 | ||
286 | opacity: question.displayed ? 1 : 0 | 322 | opacity: question.visible ? 1 : 0 | ||
287 | columnWidth: 60 * ApplicationInfo.ratio | 323 | columnWidth: 60 * ApplicationInfo.ratio | ||
288 | } | 324 | } | ||
289 | 325 | | |||
290 | Keys.onPressed: { | 326 | Keys.onPressed: { | ||
291 | if(question.displayed) { | 327 | if(okButton.visible && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) { | ||
328 | Activity.checkAnswer() | ||||
329 | } | ||||
330 | else if(question.visible) { | ||||
can you use a better property than "background.scaleHeight === 0"? If you just read the code, you don't understand where this comes from. jjazeix: can you use a better property than "background.scaleHeight === 0"? If you just read the code… | |||||
292 | numpad.updateAnswer(event.key, true); | 331 | numpad.updateAnswer(event.key, true); | ||
293 | } | 332 | } | ||
294 | } | 333 | } | ||
295 | 334 | | |||
296 | Keys.onReleased: { | 335 | Keys.onReleased: { | ||
297 | if(question.displayed) { | 336 | if(question.visible) { | ||
298 | numpad.updateAnswer(event.key, false); | 337 | numpad.updateAnswer(event.key, false); | ||
299 | } | 338 | } | ||
300 | } | 339 | } | ||
301 | 340 | | |||
302 | Bonus { | 341 | Bonus { | ||
303 | id: bonus | 342 | id: bonus | ||
304 | Component.onCompleted: win.connect(Activity.nextSubLevel) | 343 | Component.onCompleted: win.connect(Activity.nextSubLevel) | ||
305 | } | 344 | } | ||
306 | } | 345 | } | ||
307 | 346 | | |||
308 | } | 347 | } |
can you rework this?
It seems items.question is this "Question" so it does not make any sense to refer to it for text.
And this should not be needed as visible is set to false if there is no question?