diff --git a/src/activities/digital_electricity/DigitalElectricity.qml b/src/activities/digital_electricity/DigitalElectricity.qml index 9e7a1b6a9..fab319c4d 100644 --- a/src/activities/digital_electricity/DigitalElectricity.qml +++ b/src/activities/digital_electricity/DigitalElectricity.qml @@ -1,530 +1,536 @@ /* GCompris - DigitalElectricity.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (Qt Quick port) * Rudra Nil Basu (Qt Quick port) * Timothée Giet (mouse drag refactoring) * * 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 "digital_electricity.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} property string mode: "tutorial" property bool isTutorialMode: mode == "tutorial" ? true : false pageComponent: Image { id: background anchors.fill: parent source: Activity.url + "texture02.png" fillMode: Image.Tile signal start signal stop property bool vert: background.width > background.height onVertChanged: { if (playArea.x >= mousePan.drag.maximumX) { playArea.x = mousePan.drag.maximumX } if (playArea.y >= mousePan.drag.maximumY) { playArea.y = mousePan.drag.maximumY } if (playArea.x <= mousePan.drag.minimumX) { playArea.x = mousePan.drag.minimumX } if (playArea.y <= mousePan.drag.minimumY) { playArea.y = mousePan.drag.minimumY } } Component.onCompleted: { dialogActivityConfig.getInitialConfiguration() activity.start.connect(start) activity.stop.connect(stop) } Keys.onPressed: { if (event.key == Qt.Key_Plus) { Activity.zoomIn() } if (event.key == Qt.Key_Minus) { Activity.zoomOut() } if (event.key == Qt.Key_Right) { playArea.x -= 200; } if (event.key == Qt.Key_Left) { playArea.x += 200 } if (event.key == Qt.Key_Up) { playArea.y += 200 } if (event.key == Qt.Key_Down) { playArea.y -= 200 } if (playArea.x >= mousePan.drag.maximumX) { playArea.x = mousePan.drag.maximumX } if (playArea.y >= mousePan.drag.maximumY) { playArea.y = mousePan.drag.maximumY } if (playArea.x <= mousePan.drag.minimumX) { playArea.x = mousePan.drag.minimumX } if (playArea.y <= mousePan.drag.minimumY) { playArea.y = mousePan.drag.minimumY } } // Add here the QML items you need to access in javascript QtObject { id: items property Item main: activity.main property alias playArea: playArea property alias mousePan: mousePan property alias bar: bar property alias bonus: bonus property alias availablePieces: availablePieces property alias toolTip: toolTip property alias infoTxt: infoTxt property alias truthTablesModel: truthTablesModel property alias displayTruthTable: inputOutputTxt.displayTruthTable property alias dataset: dataset property alias tutorialDataset: tutorialDataset property alias infoImage: infoImage property bool isTutorialMode: activity.isTutorialMode property alias tutorialInstruction: tutorialInstruction + property int toolsMargin: 90 * ApplicationInfo.ratio } Loader { id: dataset asynchronous: false } Dataset { id: tutorialDataset } IntroMessage { id: tutorialInstruction intro: [] - textContainerWidth: background.vert ? parent.width - inputComponentsContainer.width - 90 * ApplicationInfo.ratio : 0.9 * background.width - textContainerHeight: background.vert ? 0.5 * parent.height : parent.height - inputComponentsContainer.height - (bar.height * 1.1) - 90 * ApplicationInfo.ratio + textContainerWidth: background.vert ? parent.width - inputComponentsContainer.width - items.toolsMargin : 0.9 * background.width + textContainerHeight: background.vert ? 0.5 * parent.height : parent.height - inputComponentsContainer.height - (bar.height * 1.1) - items.toolsMargin anchors { fill: undefined top: background.vert ? parent.top : inputComponentsContainer.bottom topMargin: 10 right: parent.right rightMargin: 5 left: background.vert ? inputComponentsContainer.right : parent.left leftMargin: 5 } z: 5 } onStart: { Activity.start(items) } onStop: { Activity.stop() } Rectangle { - id: playArea - color: "#10000000" - x: background.vert ? 90 * ApplicationInfo.ratio : 0 - y: background.vert ? 0 : 90 * ApplicationInfo.ratio - width: background.vert ? - background.width * 4 - 90 * ApplicationInfo.ratio : background.width * 4 - height: background.vert ? - background.height * 4 - (bar.height * 1.1) : - background.height * 4 - (bar.height * 1.1) - 90 * ApplicationInfo.ratio - - PinchArea { - id: pinchZoom - anchors.fill: parent - onPinchFinished: { - if (pinch.scale < 1) { - Activity.zoomOut() - } - if (pinch.scale > 1) { - Activity.zoomIn() - } - } - MouseArea { - id: mousePan - anchors.fill: parent - scrollGestureEnabled: false //needed for pinchZoom - drag.target: playArea - drag.axis: Drag.XandYAxis - drag.minimumX: 0 - playArea.width * 0.75 - drag.maximumX: background.vert ? 90 * ApplicationInfo.ratio : 0 - drag.minimumY: 0 - playArea.height * 0.75 - drag.maximumY: background.vert ? 0 : 90 * ApplicationInfo.ratio - onClicked: { - Activity.deselect() - availablePieces.hideToolbar() - } - } + id: visibleArea + color: "#00000000" + width: background.vert ? background.width - items.toolsMargin - 10 : background.width - 10 + height: background.vert ? background.height - bar.height - items.toolsMargin - 10 : background.height - bar.height - 10 + anchors { + fill: undefined + top: background.vert ? parent.top : inputComponentsContainer.bottom + topMargin: 5 + right: parent.right + rightMargin: 5 + left: background.vert ? inputComponentsContainer.right : parent.left + leftMargin: 5 + bottom: bar.top + bottomMargin: 20 } - + z: 6 + GCText { id: infoTxt anchors { horizontalCenter: parent.horizontalCenter - top: infoTxtContainer.top + top: parent.top topMargin: 2 } fontSizeMode: Text.Fit minimumPixelSize: 10 + font.pixelSize: 150 color: "white" - style: Text.Outline - styleColor: "black" horizontalAlignment: Text.AlignHLeft width: Math.min(implicitWidth, 0.90 * parent.width) - height: inputOutputTxt.visible == false ? Math.min(implicitHeight, 0.9 * parent.height) : + height: inputOutputTxt.visible == false ? Math.min(implicitHeight, 0.7 * parent.height) : Math.min(implicitHeight, (inputOutputTxt.inputs > 2 ? 0.3 : 0.4) * parent.height) wrapMode: TextEdit.WordWrap visible: false z: 4 } Rectangle { id: infoTxtContainer - anchors.centerIn: parent - width: infoTxt.width + 20 - height: inputOutputTxt.visible == false ? infoTxt.height + infoImage.height + 6 : - infoTxt.height + inputOutputTxt.height + truthTable.height + 8 - opacity: 0.8 + anchors.fill: parent + opacity: 1 radius: 10 + color: "#373737" border.width: 2 - border.color: "black" + border.color: "#F2F2F2" visible: infoTxt.visible - gradient: Gradient { - GradientStop { position: 0.0; color: "#000" } - GradientStop { position: 0.9; color: "#666" } - GradientStop { position: 1.0; color: "#AAA" } - } MouseArea { anchors.fill: parent onClicked: infoTxt.visible = false } z: 3 } Image { id: infoImage - property int heightNeed: parent.height - infoTxt.height property bool imgVisible: false - height: source == "" ? 0 : parent.height - infoTxt.height - 10 + height: source == "" ? 0 : parent.height * 0.3 - 10 width: source == "" ? 0 : parent.width - 10 fillMode: Image.PreserveAspectFit visible: infoTxt.visible && imgVisible anchors { top: infoTxt.bottom - horizontalCenter: parent.horizontalCenter + horizontalCenter: infoTxtContainer.horizontalCenter } z: 5 } - - + ListModel { id: truthTablesModel property int rows property int columns property int inputs property int outputs } Row { id: inputOutputTxt z: 5 property bool displayTruthTable visible: infoTxt.visible && displayTruthTable property int inputs: truthTablesModel.inputs property int outputs: truthTablesModel.outputs - property int cellSize: Math.min(parent.height - infoTxt.height - 10, (inputs > 2 ? 0.6 : + property int cellSize: Math.min(parent.height - infoTxt.height - 20, (inputs > 2 ? 0.6 : 0.45) * parent.height) / truthTablesModel.rows property int minSize: 2 * cellSize height: cellSize anchors { top: infoTxt.bottom horizontalCenter: parent.horizontalCenter } Rectangle { color: "#c7ecfb" width: Math.max(inputOutputTxt.minSize, inputOutputTxt.cellSize * inputOutputTxt.inputs) height: inputOutputTxt.cellSize border.color: "black" border.width: 1 GCText { anchors.centerIn: parent fontSizeMode: Text.Fit minimumPixelSize: 10 color: "white" style: Text.Outline styleColor: "black" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter height: parent.height width: parent.width text: qsTr("Input") } } Rectangle { color: "#47ffc2" width: Math.max(inputOutputTxt.minSize, inputOutputTxt.cellSize * inputOutputTxt.outputs) * 1.5 height: inputOutputTxt.cellSize border.color: "black" border.width: 1 GCText { anchors.centerIn: parent fontSizeMode: Text.Fit minimumPixelSize: 10 color: "white" style: Text.Outline styleColor: "black" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter height: parent.height width: parent.width text: qsTr("Output") } } } Grid { id: truthTable rows: truthTablesModel.rows columns: truthTablesModel.columns height: rows * inputOutputTxt.cellSize z: 5 visible: inputOutputTxt.visible anchors { top: inputOutputTxt.bottom horizontalCenter: parent.horizontalCenter } Repeater { id: repeater model: truthTablesModel delegate: blueSquare Component { id: blueSquare Rectangle { width: ((index % truthTable.columns) / (truthTablesModel.inputs - 1)) <= 1 ? (inputOutputTxt.inputs > 1 ? inputOutputTxt.cellSize : inputOutputTxt.minSize) : (inputOutputTxt.outputs > 1 ? inputOutputTxt.cellSize : inputOutputTxt.minSize) * 1.5 height: inputOutputTxt.cellSize border.color: "black" border.width: 1 color: { if(truthTablesModel.inputs == 1) { return index%2 == 0 ? "#c7ecfb" : "#47ffc2" } else { return ((index % truthTable.columns) / (truthTablesModel.inputs - 1)) <= 1 ? "#c7ecfb" : "#47ffc2" } } GCText { id: truthTableValue anchors.centerIn: parent fontSizeMode: Text.Fit minimumPixelSize: 10 color: "white" style: Text.Outline styleColor: "black" horizontalAlignment: Text.AlignHCenter height: parent.height width: parent.width text: value } } } } } + + } + + + Rectangle { + id: playArea + color: "#10000000" + x: background.vert ? items.toolsMargin : 0 + y: background.vert ? 0 : items.toolsMargin + width: background.vert ? + background.width * 4 - items.toolsMargin : background.width * 4 + height: background.vert ? + background.height * 4 - (bar.height * 1.1) : + background.height * 4 - (bar.height * 1.1) - items.toolsMargin + + PinchArea { + id: pinchZoom + anchors.fill: parent + onPinchFinished: { + if (pinch.scale < 1) { + Activity.zoomOut() + } + if (pinch.scale > 1) { + Activity.zoomIn() + } + } + MouseArea { + id: mousePan + anchors.fill: parent + scrollGestureEnabled: false //needed for pinchZoom + drag.target: playArea + drag.axis: Drag.XandYAxis + drag.minimumX: 0 - playArea.width * 0.75 + drag.maximumX: background.vert ? items.toolsMargin : 0 + drag.minimumY: 0 - playArea.height * 0.75 + drag.maximumY: background.vert ? 0 : items.toolsMargin + onClicked: { + Activity.deselect() + availablePieces.hideToolbar() + } + } + } } Rectangle { id: inputComponentsContainer width: background.vert ? - 90 * ApplicationInfo.ratio : + items.toolsMargin : background.width height: background.vert ? background.height : - 90 * ApplicationInfo.ratio + items.toolsMargin color: "#4A3823" anchors.left: parent.left Image { anchors.fill: parent anchors.rightMargin: background.vert ? 3 * ApplicationInfo.ratio : 0 anchors.bottomMargin: background.vert ? 0 : 3 * ApplicationInfo.ratio source: Activity.url + "texture01.png" fillMode: Image.Tile ListWidget { id: availablePieces vert: background.vert ? true : false } } z: 10 } Rectangle { id: toolTip anchors { bottom: bar.top bottomMargin: 10 left: inputComponentsContainer.left leftMargin: 5 } width: toolTipTxt.width + 10 height: toolTipTxt.height + 5 + color: "#373737" opacity: 1 radius: 10 z: 100 border.width: 2 - border.color: "black" - gradient: Gradient { - GradientStop { position: 0.0; color: "#000" } - GradientStop { position: 0.9; color: "#666" } - GradientStop { position: 1.0; color: "#AAA" } - } + border.color: "#F2F2F2" property alias text: toolTipTxt.text Behavior on opacity { NumberAnimation { duration: 120 } } function show(newText) { if(newText) { text = newText - opacity = 0.8 + opacity = 1 } else { opacity = 0 } } GCText { id: toolTipTxt anchors.centerIn: parent fontSize: regularSize color: "white" - style: Text.Outline - styleColor: "black" horizontalAlignment: Text.AlignHCenter wrapMode: TextEdit.WordWrap } } DialogActivityConfig { id: dialogActivityConfig currentActivity: activity content: Component { Item { property alias modesComboBox: modesComboBox property var availableModes: [ { "text": qsTr("Tutorial Mode"), "value": "tutorial" }, { "text": qsTr("Free Mode"), "value": "free" }, ] Flow { id: flow spacing: 5 width: dialogActivityConfig.width GCComboBox { id: modesComboBox model: availableModes background: dialogActivityConfig label: qsTr("Select your Mode") } } } } onClose: home(); onLoadData: { if(dataToSave && dataToSave["modes"]) { activity.mode = dataToSave["modes"]; } } onSaveData: { var newMode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modesComboBox.currentIndex].value; if (newMode !== activity.mode) { activity.mode = newMode; dataToSave = {"modes": activity.mode}; Activity.reset() } } function setDefaultValues() { for(var i = 0 ; i < dialogActivityConfig.configItem.availableModes.length; i ++) { if(dialogActivityConfig.configItem.availableModes[i].value === activity.mode) { dialogActivityConfig.configItem.modesComboBox.currentIndex = i; break; } } } } DialogHelp { id: dialogHelp onClose: home() } BarButton { id: okButton visible: activity.isTutorialMode anchors { bottom: bar.top right: parent.right rightMargin: 10 * ApplicationInfo.ratio bottomMargin: 10 * ApplicationInfo.ratio } source: "qrc:/gcompris/src/core/resource/bar_ok.svg" sourceSize.width: 60 * ApplicationInfo.ratio onClicked: Activity.checkAnswer() } Bar { id: bar content: BarEnumContent { value: help | home | ( activity.isTutorialMode ? level : 0) | reload | config} onHelpClicked: {displayDialog(dialogHelp)} onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: Activity.reset() onConfigClicked: { dialogActivityConfig.active = true dialogActivityConfig.setDefaultValues() displayDialog(dialogActivityConfig) } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } }