diff --git a/src/activities/scalesboard/Scalesboard.qml b/src/activities/scalesboard/Scalesboard.qml index e1cfd504e..35ff83d7d 100644 --- a/src/activities/scalesboard/Scalesboard.qml +++ b/src/activities/scalesboard/Scalesboard.qml @@ -1,347 +1,392 @@ /* GCompris - Scalesboard.qml * * Copyright (C) 2014 Bruno Coudoin * * Authors: * miguel DE IZARRA (GTK+ version) * Bruno Coudoin (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.6 import GCompris 1.0 import "../../core" import "scalesboard.js" as Activity import "." ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Image { id: background anchors.fill: parent source: Activity.url + "background.svg" sourceSize.width: Math.max(parent.width, parent.height) fillMode: Image.PreserveAspectCrop signal start signal stop property int scaleHeight: items.masseAreaLeft.weight == items.masseAreaRight.weight ? 0 : items.masseAreaLeft.weight > items.masseAreaRight.weight ? 20 : -20 Component.onCompleted: { dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } // Add here the QML items you need to access in javascript QtObject { id: items property Item main: activity.main property alias background: background property alias bar: bar property alias bonus: bonus property int numberOfSubLevels property int currentSubLevel property int giftWeight property int scaleHeight: background.scaleHeight property var levels: activity.datasetLoader.data property alias masseAreaCenter: masseAreaCenter property alias masseAreaLeft: masseAreaLeft property alias masseAreaRight: masseAreaRight property alias masseCenterModel: masseAreaCenter.masseModel property alias masseRightModel: masseAreaRight.masseModel property alias question: question property alias numpad: numpad property bool rightDrop } onStart: { Activity.start(items) } onStop: { Activity.stop() } - property bool vert: background.width > background.height + property bool isHorizontal: background.width > background.height Image { - id: scale + id: scaleBoard source: Activity.url + "scale.svg" - sourceSize.width: Math.min(parent.width - 10 * ApplicationInfo.ratio, - (parent.height - bar.height - 10 * ApplicationInfo.ratio) * 2) + sourceSize.width: isHorizontal ? Math.min(parent.width - okButton.height * 2, + (parent.height - okButton.height * 2) * 2) : parent.width anchors.centerIn: parent } Image { id: needle - parent: scale + parent: scaleBoard source: Activity.url + "needle.svg" sourceSize.width: parent.width * 0.75 - z: -10 + z: -1 property int angle: - background.scaleHeight * 0.35 anchors { horizontalCenter: parent.horizontalCenter verticalCenter: parent.verticalCenter verticalCenterOffset: - parent.paintedHeight * 0.15 } transform: Rotation { origin.x: needle.width / 2 origin.y: needle.height * 0.9 angle: needle.angle } Behavior on angle { NumberAnimation { duration: 500 easing.type: Easing.InOutQuad } } } // === The Left plate === Image { id: plateLeft - parent: scale + parent: scaleBoard source: Activity.url + "plate.svg" sourceSize.width: parent.width * 0.35 - z: -1 + z: -10 anchors { horizontalCenter: parent.horizontalCenter horizontalCenterOffset: - parent.paintedWidth * 0.3 verticalCenter: parent.verticalCenter verticalCenterOffset: - parent.paintedHeight * 0.03 + background.scaleHeight } Behavior on anchors.verticalCenterOffset { NumberAnimation { duration: 500 easing.type: Easing.InOutQuad } } // The Left Drop Area MasseArea { id: masseAreaLeft - parent: scale + parent: scaleBoard width: plateLeft.width anchors { horizontalCenter: parent.horizontalCenter horizontalCenterOffset: - parent.paintedWidth * 0.3 verticalCenter: parent.verticalCenter verticalCenterOffset: - parent.paintedHeight * 0.44 + background.scaleHeight } masseAreaCenter: masseAreaCenter masseAreaLeft: masseAreaLeft masseAreaRight: masseAreaRight nbColumns: 3 audioEffects: activity.audioEffects Behavior on anchors.verticalCenterOffset { NumberAnimation { duration: 500 easing.type: Easing.InOutQuad } } } } // === The Right plate === Image { id: plateRight - parent: scale + parent: scaleBoard source: Activity.url + "plate.svg" sourceSize.width: parent.width * 0.35 - z: -1 + z: -10 anchors { horizontalCenter: parent.horizontalCenter horizontalCenterOffset: parent.paintedWidth * 0.3 verticalCenter: parent.verticalCenter verticalCenterOffset: - parent.paintedHeight * 0.03 - background.scaleHeight } Behavior on anchors.verticalCenterOffset { NumberAnimation { duration: 500 easing.type: Easing.InOutQuad } } // The Right Drop Area MasseArea { id: masseAreaRight - parent: scale + parent: scaleBoard width: plateRight.width anchors { horizontalCenter: parent.horizontalCenter horizontalCenterOffset: parent.paintedWidth * 0.3 verticalCenter: parent.verticalCenter verticalCenterOffset: - parent.paintedHeight * 0.44 - background.scaleHeight } masseAreaCenter: masseAreaCenter masseAreaLeft: masseAreaLeft masseAreaRight: masseAreaRight nbColumns: 3 dropEnabledForThisLevel: items.rightDrop audioEffects: activity.audioEffects Behavior on anchors.verticalCenterOffset { NumberAnimation { duration: 500 easing.type: Easing.InOutQuad } } } } // === The Initial Masses List === MasseArea { id: masseAreaCenter - parent: scale + parent: scaleBoard x: parent.width * 0.05 y: parent.height * 0.84 - height width: parent.width masseAreaCenter: masseAreaCenter masseAreaLeft: masseAreaLeft masseAreaRight: masseAreaRight nbColumns: masseModel.count audioEffects: activity.audioEffects } Message { id: message anchors { top: parent.top topMargin: 10 right: parent.right rightMargin: 10 left: parent.left leftMargin: 10 } } Question { id: question - parent: scale + parent: scaleBoard anchors.horizontalCenter: parent.horizontalCenter y: parent.height * 0.45 z: 1000 width: parent.width - y answer: items.giftWeight visible: (items.question.text && background.scaleHeight === 0) ? true : false } DialogChooseLevel { id: dialogActivityConfig currentActivity: activity.activityInfo onSaveData: { levelFolder = dialogActivityConfig.chosenLevels currentActivity.currentLevels = dialogActivityConfig.chosenLevels ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) // restart activity on saving background.start() } onClose: { home() } onStartActivity: { background.start() } } DialogHelp { id: dialogHelp onClose: home() } BarButton { id: okButton source: "qrc:/gcompris/src/core/resource/bar_ok.svg" sourceSize.width: 60 * ApplicationInfo.ratio - anchors.bottom: bar.top - anchors.bottomMargin: parent.width * 0.03 - anchors.left: score.left - anchors.leftMargin: parent.width * 0.01 visible: (!question.text || items.question.userEntry) ? true : false ParticleSystemStarLoader { id: okButtonParticles clip: false } MouseArea { id: okButtonMouseArea anchors.fill: parent onClicked: { Activity.checkAnswer() } } } Bar { id: bar content: BarEnumContent { value: help | home | level | activityConfig } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onActivityConfigClicked: { displayDialog(dialogActivityConfig) } onLevelChanged: message.text = items.levels[bar.level - 1].message ? items.levels[bar.level - 1].message : "" } Score { id: score - anchors { - bottom: background.vert ? background.bottom : bar.top - right: parent.right - bottomMargin: 10 * ApplicationInfo.ratio - } - numberOfSubLevels: items.numberOfSubLevels currentSubLevel: items.currentSubLevel } + states: [ + State { + name: "horizontalLayout"; when: background.isHorizontal + AnchorChanges { + target: score + anchors.top: okButton.bottom + anchors.bottom: undefined + anchors.right: background.right + anchors.verticalCenter: undefined + } + PropertyChanges { + target: score + anchors.topMargin: 10 * ApplicationInfo.ratio + } + AnchorChanges { + target: okButton + anchors.horizontalCenter: score.horizontalCenter + anchors.verticalCenter: background.verticalCenter + anchors.bottom: undefined + anchors.right: undefined + } + PropertyChanges { + target: okButton + anchors.rightMargin: 0 + anchors.bottomMargin: 0 + } + }, + State { + name: "verticalLayout"; when: !background.isHorizontal + AnchorChanges { + target: score + anchors.top: undefined + anchors.bottom: undefined + anchors.right: okButton.left + anchors.verticalCenter: okButton.verticalCenter + } + PropertyChanges { + target: score + anchors.topMargin: 0 + } + AnchorChanges { + target: okButton + anchors.horizontalCenter: undefined + anchors.verticalCenter: undefined + anchors.bottom: bar.top + anchors.right: background.right + } + PropertyChanges { + target: okButton + anchors.rightMargin: width * 0.2 + anchors.bottomMargin: width * 0.3 + } + } + ] + NumPad { id: numpad onAnswerChanged: question.userEntry = answer maxDigit: ('' + items.giftWeight).length + 1 opacity: question.visible ? 1 : 0 columnWidth: 60 * ApplicationInfo.ratio } Keys.onPressed: { if(okButton.visible && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) { Activity.checkAnswer() } else if(question.visible) { numpad.updateAnswer(event.key, true); } } Keys.onReleased: { if(question.visible) { numpad.updateAnswer(event.key, false); } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextSubLevel) } } }