diff --git a/src/activities/digital_electricity/SevenSegment.qml b/src/activities/digital_electricity/BCDToSevenSegment.qml similarity index 65% copy from src/activities/digital_electricity/SevenSegment.qml copy to src/activities/digital_electricity/BCDToSevenSegment.qml index 6fd40b63e..c56be6cce 100644 --- a/src/activities/digital_electricity/SevenSegment.qml +++ b/src/activities/digital_electricity/BCDToSevenSegment.qml @@ -1,95 +1,102 @@ -/* GCompris - SevenSegment.qml +/* GCompris - BCDToSevenSegment.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.3 import "digital_electricity.js" as Activity import GCompris 1.0 Item { - id: sevenSegment + id: bcdTosevenSegment property variant code height: parent.height width: parent.width Image { - source: Activity.url + "sevenSegmentDisplayA.svg" - visible: code[0] == 1 + source: Activity.url + (code[0] == 1 ? "BCDTo7SegmentA_red.svgz" : "BCDTo7SegmentA_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayB.svg" - visible: code[1] == 1 + source: Activity.url + (code[1] == 1 ? "BCDTo7SegmentB_red.svgz" : "BCDTo7SegmentB_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayC.svg" - visible: code[2] == 1 + source: Activity.url + (code[2] == 1 ? "BCDTo7SegmentC_red.svgz" : "BCDTo7SegmentC_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayD.svg" - visible: code[3] == 1 + source: Activity.url + (code[3] == 1 ? "BCDTo7SegmentD_red.svgz" : "BCDTo7SegmentD_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayE.svg" - visible: code[4] == 1 + source: Activity.url + (code[4] == 1 ? "BCDTo7SegmentE_red.svgz" : "BCDTo7SegmentE_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayF.svg" - visible: code[5] == 1 + source: Activity.url + (code[5] == 1 ? "BCDTo7SegmentF_red.svgz" : "BCDTo7SegmentF_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayG.svg" - visible: code[6] == 1 + source: Activity.url + (code[6] == 1 ? "BCDTo7SegmentG_red.svgz" : "BCDTo7SegmentG_black.svgz") anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } } diff --git a/src/activities/digital_electricity/DigitalElectricity.qml b/src/activities/digital_electricity/DigitalElectricity.qml index 9b66f763b..cf8e13f7b 100644 --- a/src/activities/digital_electricity/DigitalElectricity.qml +++ b/src/activities/digital_electricity/DigitalElectricity.qml @@ -1,347 +1,347 @@ /* GCompris - DigitalElectricity.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.1 -//import QtQuick.Controls 1.4 +import QtQuick 2.3 import GCompris 1.0 import "../../core" import "digital_electricity.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Rectangle { id: background anchors.fill: parent color: "#ffffb3" signal start signal stop property bool vert: background.width > background.height Component.onCompleted: { 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 backgroundContainer: backgroundContainer 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 infoImage: infoImage } Loader { id: dataset asynchronous: false } onStart: { Activity.start(items) } onStop: { Activity.stop() } Rectangle { id: backgroundContainer color: "#ffffb3" x: background.vert ? 90 * ApplicationInfo.ratio : 0 y: background.vert ? 0 : 90 * ApplicationInfo.ratio width: background.vert ? background.width - 90 * ApplicationInfo.ratio : background.width height: background.vert ? background.height - (bar.height * 1.1) : background.height - (bar.height * 1.1) - 90 * ApplicationInfo.ratio MouseArea { anchors.fill: parent onClicked: Activity.deselect() } GCText { id: infoTxt anchors { horizontalCenter: parent.horizontalCenter top: infoTxtContainer.top topMargin: 2 } fontSizeMode: Text.Fit minimumPixelSize: 10 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) : 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 radius: 10 border.width: 2 border.color: "black" 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 width: source == "" ? 0 : parent.width - 10 fillMode: Image.PreserveAspectFit visible: infoTxt.visible && imgVisible anchors { top: infoTxt.bottom horizontalCenter: parent.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 : 0.45) * parent.height) / truthTablesModel.rows property int minSize: 2 * cellSize //width: truthTable.width 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: "#c7ecfb" - width: Math.max(inputOutputTxt.minSize, inputOutputTxt.cellSize * inputOutputTxt.outputs) + 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 //width: columns * inputOutputTxt.cellSize height: rows * inputOutputTxt.cellSize z: 5 visible: inputOutputTxt.visible anchors { top: inputOutputTxt.bottom horizontalCenter: parent.horizontalCenter } //spacing: 1 Repeater { id: repeater model: truthTablesModel //15//pieces 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) + (inputOutputTxt.outputs > 1 ? inputOutputTxt.cellSize : inputOutputTxt.minSize) * 1.5 height: inputOutputTxt.cellSize border.color: "black" border.width: 1 //radius: 1 - color: "#c7ecfb" + color: ((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: leftWidget width: background.vert ? 90 * ApplicationInfo.ratio : background.width height: background.vert ? background.height : 90 * ApplicationInfo.ratio color: "#FFFF42" border.color: "#FFD85F" border.width: 4 anchors.left: parent.left ListWidget { id: availablePieces vert: background.vert ? true : false } } Rectangle { id: toolTip anchors { bottom: bar.top bottomMargin: 10 left: leftWidget.left leftMargin: 5 } width: toolTipTxt.width + 10 height: toolTipTxt.height + 5 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" } } property alias text: toolTipTxt.text Behavior on opacity { NumberAnimation { duration: 120 } } function show(newText) { if(newText) { text = newText opacity = 0.8 } else { opacity = 0 } } GCText { id: toolTipTxt anchors.centerIn: parent fontSize: regularSize color: "white" style: Text.Outline styleColor: "black" horizontalAlignment: Text.AlignHCenter wrapMode: TextEdit.WordWrap } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | reload} onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: Activity.reset() } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/digital_electricity/DragListItem.qml b/src/activities/digital_electricity/DragListItem.qml index 9db25edae..3db2f3ba3 100644 --- a/src/activities/digital_electricity/DragListItem.qml +++ b/src/activities/digital_electricity/DragListItem.qml @@ -1,142 +1,141 @@ /* gcompris - DragListItem.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.3 -import QtGraphicalEffects 1.0 import GCompris 1.0 import "digital_electricity.js" as Activity Item { id: item width: tile.width height: tile.height property string source: imgName property double heightInColumn property double widthInColumn property double tileWidth property double tileHeight property bool selected: false //property double terminalSize: size signal pressed Rectangle { id: tile width: tileWidth height: tileHeight color: (parent.selected && tileImage.parent == tile) ? "#33FF294D" : "transparent" border.color: (parent.selected && tileImage.parent == tile) ? "white" : "transparent" border.width: 3 radius: 2 property double xCenter: tile.x + tile.width / 2 property double yCenter: tile.y + tile.height / 2 property bool selected: false Image { anchors.centerIn: parent width: widthInColumn height: heightInColumn fillMode: Image.PreserveAspectFit source: Activity.url + imgName } Image { id: tileImage anchors.centerIn: parent width: smallWidth height: smallHeight fillMode: Image.PreserveAspectFit source: Activity.url + imgName mipmap: true antialiasing: true property double smallWidth: widthInColumn property double smallHeight: heightInColumn property double fullWidth: imgWidth * backgroundContainer.width property double fullHeight: imgHeight * backgroundContainer.height property QtObject tileImageParent property bool small: true function toSmall() { width = smallWidth height = smallHeight small = true } function toFull() { width = fullWidth height = fullHeight small = false } MultiPointTouchArea { id: mouseArea touchPoints: [ TouchPoint { id: point1 } ] property real startX property real startY property bool pressedOnce anchors.fill: parent onPressed: { //item.pressed() //tileImage.toSmall() //console.log("onPressed 1",tileImage.parent) tileImage.anchors.centerIn = undefined //console.log("onPressed 2",tileImage.parent) startX = point1.x startY = point1.y tileImage.toFull() toolTip.show(toolTipText) pressedOnce = true item.selected = true } onUpdated: { var moveX = point1.x - startX var moveY = point1.y - startY parent.x = parent.x + moveX parent.y = parent.y + moveY //console.log("parent.x",parent.x,"parent.y",parent.y) } onReleased: { if (pressedOnce) { pressedOnce = false item.selected = false //console.log("dropped parent.x",parent.x,"parent.y",parent.y) var coord = backgroundContainer.mapFromItem(tileImage.parent, parent.x, parent.y) //console.log("coord.x",coord.x,"coord.y",coord.y) //console.log("dropped",terminalSize) if(coord.x > 0 && (backgroundContainer.width - coord.x > tileImage.fullWidth)) Activity.createComponent(coord.x, coord.y, imgName, imgWidth, imgHeight, toolTipText, terminalSize) tileImage.anchors.centerIn = tile tileImage.toSmall() toolTip.show("") } } } } } } diff --git a/src/activities/digital_electricity/ElectricalComponent.qml b/src/activities/digital_electricity/ElectricalComponent.qml index d9845416d..099292e7e 100644 --- a/src/activities/digital_electricity/ElectricalComponent.qml +++ b/src/activities/digital_electricity/ElectricalComponent.qml @@ -1,149 +1,149 @@ /* GCompris - Component.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.3 import "digital_electricity.js" as Activity import GCompris 1.0 Image { id: electricalComponent property QtObject pieceParent property string imgSrc property double posX property double posY property double imgWidth property double imgHeight property int index property string toolTipTxt property int rotationAngle: 0 property int initialAngle: 0 property int startingAngle: 0 property int output property double terminalSize property variant inputs: [] property variant outputs: [] property alias rotateComponent: rotateComponent x: posX * parent.width y: posY * parent.height width: imgWidth * parent.width height: imgHeight * parent.height fillMode: Image.PreserveAspectFit opacity: 1.0 - source: Activity.url + imgSrc + source: Activity.url + (imgSrc == "BCDTo7Segment.svg" ? "BCDTo7SegmentDropped.svg" : imgSrc) z: 2 mipmap: true antialiasing: true onPaintedWidthChanged: { updateDragConstraints() Activity.updateWires(index) } PropertyAnimation { id: rotateComponent target: electricalComponent property: "rotation" from: initialAngle; to: initialAngle + rotationAngle duration: 1 onStarted:{Activity.animationInProgress = true} onStopped: { initialAngle = initialAngle + rotationAngle //console.log("initialAngle",initialAngle) Activity.updateWires(index) if(initialAngle == startingAngle + rotationAngle * 45) { if(initialAngle == 360 || initialAngle == -360) initialAngle = 0 startingAngle = initialAngle Activity.animationInProgress = false updateDragConstraints() } else rotateComponent.start() } easing.type: Easing.InOutQuad } function updateDragConstraints() { //console.log("initialAngle",initialAngle) if(initialAngle == 0 || initialAngle == 180 || initialAngle == 360 || initialAngle == -360 || initialAngle == -180) { mouseArea.drag.minimumX = (electricalComponent.paintedWidth - electricalComponent.width)/2 mouseArea.drag.minimumY = (electricalComponent.paintedHeight - electricalComponent.height)/2 mouseArea.drag.maximumX = electricalComponent.parent.width - (electricalComponent.width + electricalComponent.paintedWidth)/2 mouseArea.drag.maximumY = electricalComponent.parent.height - (electricalComponent.height + electricalComponent.paintedHeight)/2 } else { mouseArea.drag.minimumX = (electricalComponent.paintedHeight - electricalComponent.width)/2 mouseArea.drag.minimumY = (electricalComponent.paintedWidth - electricalComponent.height)/2 mouseArea.drag.maximumX = electricalComponent.parent.width - (electricalComponent.width + electricalComponent.paintedHeight)/2 mouseArea.drag.maximumY = electricalComponent.parent.height - (electricalComponent.height + electricalComponent.paintedWidth)/2 } //console.log("mouseArea",mouseArea.drag.minimumX,mouseArea.drag.minimumY) } MouseArea { id: mouseArea //anchors.fill: parent width: parent.paintedWidth height: parent.paintedHeight anchors.centerIn: parent drag.target: electricalComponent onPressed: { //console.log("Component index",index) Activity.updateToolTip(toolTipTxt) Activity.componentSelected(index) } onClicked: { //console.log("Component index",index) if(Activity.toolDelete) { Activity.removeComponent(index) } else { if(imgSrc == "switchOff.svg") { imgSrc = "switchOn.svg" Activity.updateComponent(index) } else if(imgSrc == "switchOn.svg") { imgSrc = "switchOff.svg" Activity.updateComponent(index) } } } /*onPositionChanged: { Activity.updateWires(index) }*/ onReleased: { parent.posX = parent.x / parent.parent.width parent.posY = parent.y / parent.parent.height parent.x = Qt.binding(function() { return parent.posX * parent.parent.width }) parent.y = Qt.binding(function() { return parent.posY * parent.parent.height }) Activity.updateToolTip("") } } } diff --git a/src/activities/digital_electricity/ListWidget.qml b/src/activities/digital_electricity/ListWidget.qml index 438bb9b5d..5ec8bb25f 100644 --- a/src/activities/digital_electricity/ListWidget.qml +++ b/src/activities/digital_electricity/ListWidget.qml @@ -1,323 +1,323 @@ /* gcompris - ListWidget.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.1 +import QtQuick 2.3 import GCompris 1.0 import "../../core" import "digital_electricity.js" as Activity Item { id: listWidget anchors.fill: parent anchors.topMargin: 5 * ApplicationInfo.ratio anchors.leftMargin: 5 * ApplicationInfo.ratio z: 10 property bool vert property alias model: mymodel property alias view: view property alias repeater: repeater property alias toolDelete: toolDelete property alias rotateLeft: rotateLeft property alias rotateRight: rotateRight property alias info: info ListModel { id: mymodel } Grid { id: view width: listWidget.vert ? leftWidget.width : 2 * bar.height height: listWidget.vert ? background.height - 2 * bar.height : bar.height spacing: 5 z: 20 columns: listWidget.vert ? 1 : nbItemsByGroup + 2 property int currentDisplayedGroup: 0 property int setCurrentDisplayedGroup: 0 property int nbItemsByGroup: listWidget.vert ? parent.height / iconSize - 2 : parent.width / iconSize - 2 property int nbDisplayedGroup: Math.ceil(model.count / nbItemsByGroup) property int iconSize: 80 * ApplicationInfo.ratio property int previousNavigation: 1 property int nextNavigation: 1 onNbDisplayedGroupChanged: { view.setCurrentDisplayedGroup = 0 refreshLeftWidget() } add: Transition { NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 400 } NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 400 } } move: Transition { NumberAnimation { properties: "x,y"; duration: 400; easing.type: Easing.OutBounce } } //For setting navigation buttons function setNextNavigation() { nextNavigation = 0 //console.log("setNextNavigation",nextNavigation) if(currentDisplayedGroup + 1 < nbDisplayedGroup) nextNavigation = 1 //console.log("setNextNavigation",nextNavigation) } function setPreviousNavigation() { previousNavigation = 0 if(currentDisplayedGroup > 0) previousNavigation = 1 //console.log("setPreviousNavigation",previousNavigation) } function refreshLeftWidget() { //console.log("refreshLeftWidget") availablePieces.view.currentDisplayedGroup = availablePieces.view.setCurrentDisplayedGroup availablePieces.view.setNextNavigation() availablePieces.view.setPreviousNavigation() } Column { id: toolButtons width: listWidget.vert ? listWidget.width : listWidget.height height: listWidget.vert ? listWidget.width : listWidget.height spacing: 10 //z: 20 Row { spacing: view.iconSize * 0.20 Image { id: toolDelete state: "notSelected" sourceSize.width: view.iconSize * 0.35 fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent onClicked: { toolDelete.state = toolDelete.state == "selected" ? "notSelected" : "selected" Activity.toolDelete = !Activity.toolDelete //true //console.log("state",toolDelete.state) } } states: [ State { name: "selected" PropertyChanges{ target: toolDelete source: Activity.url + "deleteOn.svg" } }, State { name: "notSelected" PropertyChanges { target: toolDelete source: Activity.url + "deleteOff.svg" } } ] } Image { id: info source: Activity.url + "Info.svg" sourceSize.width: view.iconSize * 0.35 fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent onClicked: { if(!Activity.animationInProgress && parent.state == "canBeSelected") { //console.log("rotateLeft clicked") Activity.displayInfo() } } } states: [ State { name: "canBeSelected" PropertyChanges{ target: info source: Activity.url + "Info.svg" } }, State { name: "canNotBeSelected" PropertyChanges { target: info source: Activity.url + "InfoOff.svg" } } ] } } Row { spacing: view.iconSize * 0.20 Image { id: rotateLeft //source: Activity.url + "rotateLeft.svg" sourceSize.width: view.iconSize * 0.35 fillMode: Image.PreserveAspectFit state: "CanNotBeSelected" MouseArea { anchors.fill: parent //enabled: parent.state == "canBeSelected" onClicked: { if(!Activity.animationInProgress && parent.state == "canBeSelected") { //console.log("rotateLeft clicked") Activity.rotateLeft() } } } states: [ State { name: "canBeSelected" PropertyChanges{ target: rotateLeft source: Activity.url + "rotateLeft.svg" } }, State { name: "canNotBeSelected" PropertyChanges { target: rotateLeft source: Activity.url + "rotateLeftOff.svg" } } ] } Image { id: rotateRight //source: Activity.url + "rotateRight.svg" sourceSize.width: view.iconSize * 0.35 fillMode: Image.PreserveAspectFit state: "CanNotBeSelected" MouseArea { anchors.fill: parent //enabled: parent.state == "canBeSelected" onClicked: { if(!Activity.animationInProgress && parent.state == "canBeSelected") { //console.log("rotateRight clicked") Activity.rotateRight() } } } states: [ State { name: "canBeSelected" PropertyChanges{ target: rotateRight source: Activity.url + "rotateRight.svg" } }, State { name: "canNotBeSelected" PropertyChanges { target: rotateRight source: Activity.url + "rotateRightOff.svg" } } ] } } } Repeater { id: repeater property int currentIndex width: 100 /*onCurrentIndexChanged: { for(var i = 0; i < mymodel.count; i++) { if(currentIndex != i) repeater.itemAt(i).selected = false else repeater.itemAt(i).selected = true } if(currentIndex == -1) toolTip.opacity = 0 }*/ DragListItem { id: contactsDelegate z: 1 heightInColumn: view.iconSize * 0.75//listWidget.vert ? view.iconSize * 0.75 : view.iconSize * 0.9 widthInColumn: view.iconSize * 0.85//listWidget.vert ? view.iconSize * 0.9 : view.iconSize * 0.75 tileWidth: view.iconSize//listWidget.vert ? view.iconSize : view.iconSize * 0.85 tileHeight: view.iconSize * 0.85//listWidget.vert ? view.iconSize * 0.85 : view.iconSize visible: view.currentDisplayedGroup * view.nbItemsByGroup <= index && index <= (view.currentDisplayedGroup+1) * view.nbItemsByGroup-1 onPressed: repeater.currentIndex = index } clip: true model: mymodel onModelChanged: repeater.currentIndex = -1 } Row { spacing: view.iconSize * 0.20 Image { id: previous opacity: (model.count > view.nbItemsByGroup && view.previousNavigation != 0 && view.currentDisplayedGroup != 0) ? 1 : 0 source: "qrc:/gcompris/src/core/resource/bar_previous.svg" sourceSize.width: view.iconSize * 0.30 fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent onClicked: { repeater.currentIndex = -1 if(previous.opacity == 1) { view.setCurrentDisplayedGroup = view.currentDisplayedGroup - view.previousNavigation view.refreshLeftWidget() } } } } Image { id: next visible: model.count > view.nbItemsByGroup && view.nextNavigation != 0 && view.currentDisplayedGroup < view.nbDisplayedGroup - 1 source: "qrc:/gcompris/src/core/resource/bar_next.svg" sourceSize.width: view.iconSize * 0.30 fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent onClicked: { repeater.currentIndex = -1 view.setCurrentDisplayedGroup = view.currentDisplayedGroup + view.nextNavigation view.refreshLeftWidget() } } } } } } diff --git a/src/activities/digital_electricity/SevenSegment.qml b/src/activities/digital_electricity/SevenSegment.qml index 6fd40b63e..1da2646da 100644 --- a/src/activities/digital_electricity/SevenSegment.qml +++ b/src/activities/digital_electricity/SevenSegment.qml @@ -1,95 +1,109 @@ /* GCompris - SevenSegment.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.3 import "digital_electricity.js" as Activity import GCompris 1.0 Item { id: sevenSegment property variant code height: parent.height width: parent.width Image { - source: Activity.url + "sevenSegmentDisplayA.svg" + source: Activity.url + "sevenSegmentDisplayA.svgz" visible: code[0] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayB.svg" + source: Activity.url + "sevenSegmentDisplayB.svgz" visible: code[1] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayC.svg" + source: Activity.url + "sevenSegmentDisplayC.svgz" visible: code[2] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayD.svg" + source: Activity.url + "sevenSegmentDisplayD.svgz" visible: code[3] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayE.svg" + source: Activity.url + "sevenSegmentDisplayE.svgz" visible: code[4] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayF.svg" + source: Activity.url + "sevenSegmentDisplayF.svgz" visible: code[5] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } Image { - source: Activity.url + "sevenSegmentDisplayG.svg" + source: Activity.url + "sevenSegmentDisplayG.svgz" visible: code[6] == 1 anchors.centerIn: parent height: parent.height width: parent.width fillMode: Image.PreserveAspectFit + mipmap: true + antialiasing: true } } diff --git a/src/activities/digital_electricity/TerminalPoint.qml b/src/activities/digital_electricity/TerminalPoint.qml index 5d8cf1f3d..0d233d0fb 100644 --- a/src/activities/digital_electricity/TerminalPoint.qml +++ b/src/activities/digital_electricity/TerminalPoint.qml @@ -1,87 +1,87 @@ /* GCompris - TerminalPoint.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.0 +import QtQuick 2.3 import "digital_electricity.js" as Activity import GCompris 1.0 Rectangle { id: terminalPoint property double posX property double posY property double size: parent.terminalSize property bool selected: false property string type property int value: -1 property int index property int componentIndex property variant wireIndex: [] width: size * parent.paintedHeight height: size * parent.paintedHeight radius: width / 2 color: "Black" x: (parent.width - parent.paintedWidth) / 2 + posX * parent.paintedWidth - width / 2 y: (parent.height - parent.paintedHeight) / 2 + posY * parent.paintedHeight - height / 2 //property variant coord: parent.parent.mapFromItem(terminalPoint, terminalPoint.x + width / 2, terminalPoint.y + height / 2) property double xCenter: terminalPoint.parent.x + terminalPoint.x + width/2 property double yCenter: terminalPoint.parent.y + terminalPoint.y + height/2 //property double xCenterFromComponent: terminalPoint.parent.x + terminalPoint.parent.width / 2 - xCenter //property double yCenterFromComponent: terminalPoint.parent.y + terminalPoint.parent.height / 2 - yCenter property double xCenterFromComponent: terminalPoint.x + width/2 - terminalPoint.parent.width / 2 property double yCenterFromComponent: terminalPoint.y + height/2 - terminalPoint.parent.height / 2 Rectangle { id: boundary anchors.centerIn: terminalPoint width: terminalPoint.width * 1.4 height: width visible: selected radius: width / 2 color: "green" z: -1 } MouseArea { id: mouseArea anchors.fill: parent onPressed: { selected = true //console.log("Pressed Terminal",index,type,value) Activity.terminalPointSelected(index) //parent.parent.parent.moveFromX = parent.parent.x + mouseX //parent.parent.parent.moveFromY = parent.parent.y + mouseY } /* onPositionChanged: { parent.parent.parent.moveToX = parent.parent.x + mouseX parent.parent.parent.moveToY = parent.parent.y + mouseY //console.log(parent.parent.parent.moveToX,parent.parent.parent.moveToY) //console.log(parent.parent.x + mouseX,parent.parent.y + mouseY) parent.parent.parent.requestPaint() }*/ } } diff --git a/src/activities/digital_electricity/Wire.qml b/src/activities/digital_electricity/Wire.qml index 57cd319a0..b22e89095 100644 --- a/src/activities/digital_electricity/Wire.qml +++ b/src/activities/digital_electricity/Wire.qml @@ -1,66 +1,66 @@ /* GCompris - Wire.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.0 +import QtQuick 2.3 import "digital_electricity.js" as Activity import GCompris 1.0 Rectangle { id: wire //property double posX1 //property double posY1 //property double posX2 //property double posY2 //property double rectWidth //property double rotateAngle property string wireColor property int index property int from property int to //width: rectWidth height: 5 color: wireColor //"Red" radius: height / 2 //x: posX1 //y: posY1 transformOrigin: Item.Left //rotation: rotateAngle MouseArea { id: mouseArea //anchors.fill: parent width: parent.width height: parent.height * 3 anchors.centerIn: parent onPressed: { //console.log("Pressed Wire",index,color,wireColor) if(Activity.toolDelete) { Activity.removeWire(index) } } } } diff --git a/src/activities/digital_electricity/digital_electricity.js b/src/activities/digital_electricity/digital_electricity.js index d43d771fe..3e5cdae54 100644 --- a/src/activities/digital_electricity/digital_electricity.js +++ b/src/activities/digital_electricity/digital_electricity.js @@ -1,815 +1,638 @@ /* GCompris - digital_electricity.js * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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 . */ .pragma library -.import QtQuick 2.0 as Quick +.import QtQuick 2.3 as Quick var currentLevel = 0 var numberOfLevel = 4 var items var url = "qrc:/gcompris/src/activities/digital_electricity/resource/" //var componentIndex = 0 var toolDelete var selectedIndex var animationInProgress var selectedTerminal var mapSrc = {} var terminals = [] var deletedIndex = [] var components = [] var componentsInfo = [] var wires = [] var connected = [] var deletedWireIndex = [] var colors = ["red","green","blue","blueviolet","silver"] var sevenSegmentDisplay = [] +var BCDTo7Segment = [] function start(items_) { + items = items_ currentLevel = 0 var filename = url + "ElectricalComponents.qml" items.dataset.source = filename var componentsData = items.dataset.item var componentsDataLength = componentsData.components.length for(var i = 0 ; i < componentsDataLength ; ++i) { var component = componentsData.components[i] items.availablePieces.model.append( { "imgName": component.imgName, "imgWidth": component.imgWidth, "imgHeight": component.imgHeight, "toolTipText": component.toolTipText, "terminalSize": component.terminalSize, }); mapSrc[component.imgName] = i if(component.imgName == "ledOff.svg") mapSrc["ledOn.svg"] = i else if(component.imgName == "switchOff.svg") mapSrc["switchOn.svg"] = i componentsInfo[i] = [] componentsInfo[i][0] = component.imgWidth componentsInfo[i][1] = component.imgHeight componentsInfo[i][2] = component.toolTipText componentsInfo[i][3] = component.terminalSize componentsInfo[i][4] = [] var inputs = component.inputTerminals for(var j = 0 ; j < inputs.length ; ++j) { componentsInfo[i][4][j] = [] var input = inputs[j] componentsInfo[i][4][j][0] = input.posX componentsInfo[i][4][j][1] = input.posY componentsInfo[i][4][j][2] = input.value == undefined ? -1 : input.value } componentsInfo[i][5] = [] var outputs = component.outputTerminals //console.log("outputs.length",outputs.length) for(var j = 0 ; j < outputs.length ; ++j) { componentsInfo[i][5][j] = [] var output = outputs[j] componentsInfo[i][5][j][0] = output.posX componentsInfo[i][5][j][1] = output.posY componentsInfo[i][5][j][2] = output.value == undefined ? -1 : output.value } componentsInfo[i][6] = component.information componentsInfo[i][7] = component.truthTable } - /*items.availablePieces.model.append( { - "imgName": "zero.svg", - "imgWidth": 0.12, - "imgHeight": 0.2, - "toolTipText": qsTr("Zero input"), - "terminalSize": 0.205 - }); - items.availablePieces.model.append( { - "imgName": "one.svg", - "imgWidth": 0.12, - "imgHeight": 0.2, - "toolTipText": qsTr("One input"), - "terminalSize": 0.218 - }); - /*items.availablePieces.model.append( { - "imgName": "battery.svg", - "imgWidth": 0.13, - "imgHeight": 0.18, - "toolTipText": qsTr("Battery") - }); - items.availablePieces.model.append( { - "imgName": "comparator.svg", - "imgWidth": 0.3, - "imgHeight": 0.25, - "toolTipText": qsTr("Comparator") - }); - items.availablePieces.model.append( { - "imgName": "ledOff.svg", - "imgWidth": 0.16, - "imgHeight": 0.2, - "toolTipText": qsTr("LED"), - "terminalSize": 0.111 - }); - /*items.availablePieces.model.append( { - "imgName": "switchOff.svg", - "imgWidth": 0.18, - "imgHeight": 0.15, - "toolTipText": qsTr("Switch") - }); - items.availablePieces.model.append( { - "imgName": "BCDTo7Segment.svg", - "imgWidth": 0.3, - "imgHeight": 0.4, - "toolTipText": qsTr("BCD To 7 Segment") - }); - items.availablePieces.model.append( { - "imgName": "sevenSegmentDisplay.svg", - "imgWidth": 0.18, - "imgHeight": 0.4, - "toolTipText": qsTr("7 Segment Display"), - "terminalSize": 0.097 - }); - items.availablePieces.model.append( { - "imgName": "gateAnd.svg", - "imgWidth": 0.15, - "imgHeight": 0.12, - "toolTipText": qsTr("AND gate"), - "terminalSize": 0.246 - }); - /*items.availablePieces.model.append( { - "imgName": "gateNand.svg", - "imgWidth": 0.15, - "imgHeight": 0.12, - "toolTipText": qsTr("NAND gate") - }); - items.availablePieces.model.append( { - "imgName": "gateNor.svg", - "imgWidth": 0.15, - "imgHeight": 0.12, - "toolTipText": qsTr("NOR gate") - }); - items.availablePieces.model.append( { - "imgName": "gateNot.svg", - "imgWidth": 0.15, - "imgHeight": 0.12, - "toolTipText": qsTr("Not gate") - }); - items.availablePieces.model.append( { - "imgName": "gateOr.svg", - "imgWidth": 0.15, - "imgHeight": 0.12, - "toolTipText": qsTr("Or gate") - }); - items.availablePieces.model.append( { - "imgName": "gateXor.svg", - "imgWidth": 0.15, - "imgHeight": 0.12, - "toolTipText": qsTr("Xor gate") - }); - //*/ - //items.availablePieces.view.refreshLeftWidget() initLevel() } function stop() { for(var i = 0 ; i < components.length ; ++i) { var j for(j = 0 ; j < deletedIndex.length ; ++j) { if(deletedIndex[j] == i) break } if(j == deletedIndex.length) { - if(components[i].imgSrc == "sevenSegmentDisplay.svg") + if(components[i].imgSrc == "sevenSegmentDisplay.svgz") sevenSegmentDisplay[i].destroy() + else if(components[i].imgSrc == "BCDTo7Segment.svg") + BCDTo7Segment[i].destroy() components[i].destroy() } } /*for(var i = 0 ; i < terminals.length ; ++i) { terminals[i].destroy(); }*/ for(var i = 0 ; i < wires.length ; ++i) { var j for(j = 0 ; j < deletedWireIndex.length ; ++j) { if(deletedWireIndex[j] == i) break } if(j == deletedWireIndex.length) wires[i].destroy() } } function initLevel() { + items.availablePieces.view.currentDisplayedGroup = 0 items.availablePieces.view.previousNavigation = 1 items.availablePieces.view.nextNavigation = 1 terminals = [] deletedIndex = [] components = [] wires = [] connected = [] deletedWireIndex = [] sevenSegmentDisplay = [] + BCDTo7Segment = [] animationInProgress = false deselect() toolDelete = false updateToolTip("") } function reset() { + deselect() stop() initLevel() } function createComponent(x, y, src, imgWidth, imgHeight, toolTipTxt, terminalSize) { + var electricComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/ElectricalComponent.qml") - if (electricComponent.status == electricComponent.Error) { - // Error Handling - console.log("Error loading component:", electricComponent.errorString()); - } //console.log("Inside createComponent") x = x / items.backgroundContainer.width y = y / items.backgroundContainer.height //console.log("x",x,"y",y) var index if(deletedIndex.length > 0) { index = deletedIndex[deletedIndex.length - 1] deletedIndex.pop() } else index = components.length var componentInfo = componentsInfo[mapSrc[src]] components[index] = electricComponent.createObject( items.backgroundContainer, { "index": index, "posX": x, "posY": y, "imgSrc": src, "imgWidth": componentInfo[0], "imgHeight": componentInfo[1], "toolTipTxt": componentInfo[2], "terminalSize": componentInfo[3] }); var electricComponentCreated = components[index] var terminalComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/TerminalPoint.qml") //console.log("Error loading component:", terminalComponent.errorString()) var terminalIndex = terminals.length //console.log("terminalIndex",terminalIndex) - if(src == "sevenSegmentDisplay.svg") { + if(src == "sevenSegmentDisplay.svgz") { var sevenSegmentComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/SevenSegment.qml") sevenSegmentDisplay[index] = sevenSegmentComponent.createObject( electricComponentCreated, { - "code": [0,0,0,0,0,0] + "code": [0, 0, 0, 0, 0, 0, 0] }); sevenSegmentDisplay[index].anchors.centerIn = electricComponentCreated } + else if(src == "BCDTo7Segment.svg") { + var BCDTo7SegmentComponent = Qt.createComponent( + "qrc:/gcompris/src/activities/digital_electricity/BCDToSevenSegment.qml") + BCDTo7Segment[index] = BCDTo7SegmentComponent.createObject( + electricComponentCreated, { + "code": [0, 0, 0, 0, 0, 0, 0] + }); + BCDTo7Segment[index].anchors.centerIn = electricComponentCreated + } var inputs = componentInfo[4] for(var i = 0 ; i < inputs.length ; ++i) { var input = inputs[i] electricComponentCreated.inputs.push(terminalIndex) terminals[terminalIndex++] = terminalComponent.createObject( electricComponentCreated, { "posX": input[0], "posY": input[1], "index": terminalIndex - 1, "type": "In", "componentIndex": index, "value": input[2] }); //console.log("posX",input[0]) } var outputs = componentInfo[5] //console.log("outputs.length",outputs.length) for(var i = 0 ; i < outputs.length ; ++i) { var output = outputs[i] electricComponentCreated.outputs.push(terminalIndex) terminals[terminalIndex++] = terminalComponent.createObject( electricComponentCreated, { "posX": output[0], "posY": output[1], "index": terminalIndex - 1, "type": "Out", "componentIndex": index, "value": output[2] }); } componentSelected(index) } function terminalPointSelected(index) { if(selectedTerminal == -1 || selectedTerminal == index) selectedTerminal = index else if((terminals[index].type != terminals[selectedTerminal].type) && terminals[index].componentIndex != terminals[selectedTerminal].componentIndex) { var inIndex = terminals[index].type == "In" ? index : selectedTerminal var outIndex = terminals[index].type == "Out" ? index : selectedTerminal //console.log("in, connected[inIndex]",connected[inIndex],"inIndex",inIndex) if(connected[inIndex] == undefined || connected[inIndex] == -1) { //console.log("in2") var wireComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/Wire.qml") var index if(deletedWireIndex.length > 0) { index = deletedWireIndex[deletedWireIndex.length - 1] deletedWireIndex.pop() } else index = wires.length var colorIndex = Math.floor(Math.random() * colors.length) //console.log("colorIndex",colorIndex) wires[index] = wireComponent.createObject( items.backgroundContainer, { "from": outIndex, "to": inIndex, "wireColor": colors[colorIndex], "index": index }); terminals[inIndex].value = terminals[outIndex].value terminals[inIndex].wireIndex.push(index) terminals[outIndex].wireIndex.push(index) updateWires(terminals[inIndex].componentIndex) updateWires(terminals[outIndex].componentIndex) updateComponent(terminals[inIndex].componentIndex) connected[inIndex] = outIndex } deselect() } else { //console.log("else") deselect() selectedTerminal = index terminals[index].selected = true } } function updateComponent(index) { var visited = [] updateComponentUtility(index, visited) } function updateComponentUtility(index, visited) { //console.log("index",index,"components[index].imgSrc",components[index].imgSrc) if(visited[index] != undefined) // To prevent infinite loop because of bad connection return visited[index] = true var component = components[index] if(component.imgSrc == "ledOff.svg") { if(terminals[component.inputs[0]].value == 1 && terminals[component.inputs[1]].value == 0) component.source = url + "ledOn.svg" else component.source = url + "ledOff.svg" //console.log("component.source",component.source) return } - else if(component.imgSrc == "sevenSegmentDisplay.svg") { + else if(component.imgSrc == "sevenSegmentDisplay.svgz") { var code = [] for(var i = 0 ; i < 7 ; ++i) { var value = terminals[component.inputs[i]].value if(value == -1) { - for(var j = 0 ; j < 7 ; ++j) code[j] = 0 + for(var j = 0 ; j < 7 ; ++j) + code[j] = 0 + break } code[i] = value } sevenSegmentDisplay[index].code = code return } else if(component.imgSrc == "switchOff.svg") { terminals[component.outputs[0]].value = -1 } else if(component.imgSrc == "switchOn.svg") { terminals[component.outputs[0]].value = terminals[component.inputs[0]].value } else if(component.imgSrc == "comparator.svg") { var firstInput = terminals[component.inputs[0]].value var secondInput = terminals[component.inputs[1]].value if(firstInput != -1 && secondInput != -1) { terminals[component.outputs[0]].value = firstInput < secondInput ? 1 : 0 terminals[component.outputs[1]].value = firstInput == secondInput ? 1 : 0 terminals[component.outputs[2]].value = firstInput > secondInput ? 1 : 0 } else { terminals[component.outputs[0]].value = -1 terminals[component.outputs[1]].value = -1 terminals[component.outputs[2]].value = -1 } } - else { + else { // For the components that have a truth table var inputSet = false var compnentInfo = componentsInfo[mapSrc[component.imgSrc]] var truthTable = compnentInfo[7] var i var input = component.inputs for(i = 1 ; i < truthTable.length ; ++i) { var j for(j = 0 ; j < input.length; ++j) { if(terminals[input[j]].value != truthTable[i][j]) break } if(j == input.length) break } var output = component.outputs if(i == truthTable.length) { for(var j = 0 ; j < output.length ; ++j) terminals[output[j]].value = -1 } else { for(var j = 0 ; j < output.length ; ++j) terminals[output[j]].value = truthTable[i][j + input.length] } } + if(component.imgSrc == "BCDTo7Segment.svg") { + var code = [] + for(var i = 0 ; i < 7 ; ++i) { + var value = terminals[component.outputs[i]].value + if(value == -1) { + for(var j = 0 ; j < 7 ; ++j) + code[j] = 0 + break + } + code[i] = value + } + BCDTo7Segment[index].code = code + //for(var i=0;i<7;++i) console.log("code[i]",i,code[i],"BCDTo7Segment[index].code[i]",BCDTo7Segment[index].code[i]) + + } + for(var i = 0 ; i < component.outputs.length ; ++i) { var terminal = terminals[component.outputs[i]] for(var j = 0 ; j < terminal.wireIndex.length ; ++j) { terminals[wires[terminal.wireIndex[j]].to].value = terminal.value } } for(var i = 0 ; i < component.outputs.length ; ++i) { var terminal = terminals[component.outputs[i]] //console.log("terminal index",terminal.index) for(var j = 0 ; j < terminal.wireIndex.length ; ++j) { //console.log("wires[terminal.wireIndex[j]].to",wires[terminal.wireIndex[j]].to) updateComponentUtility(terminals[wires[terminal.wireIndex[j]].to].componentIndex,visited) } } } function updateWires(index) { var component = components[index] if(component == undefined || component.inputs == undefined || component.outputs == undefined) return var rotatedAngle = component.initialAngle * Math.PI / 180 for(var i = 0 ; i < component.inputs.length ; ++i) { var terminal = terminals[component.inputs[i]] if(terminal.wireIndex.length != 0) { var wire = wires[terminal.wireIndex[0]] var otherAngle = components[terminals[wire.from].componentIndex].initialAngle * Math.PI / 180 var x = terminals[wire.from].xCenterFromComponent var y = terminals[wire.from].yCenterFromComponent var x1 = terminals[wire.from].xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle) var y1 = terminals[wire.from].yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle) //console.log(otherComponentAngle,x,y,x1,y1) x = terminal.xCenterFromComponent y = terminal.yCenterFromComponent var x2 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle) var y2 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle) /*if((rotatedAngle > 0 && rotatedAngle <= 90) || rotatedAngle == -270) { x2 = component.x + component.width / 2 + (terminal.yCenterFromComponent * rotatedAngle) / 90 y2 = component.y + component.height / 2 - (terminal.xCenterFromComponent * rotatedAngle) / 90 } else if(rotatedAngle == 180 || rotatedAngle == -180) { x2 = x2 + terminal.xCenterFromComponent * 2 y2 = y2 + terminal.yCenterFromComponent * 2 } else if(rotatedAngle == 270 || rotatedAngle == -90) { x2 = component.x + component.width / 2 - terminal.yCenterFromComponent y2 = component.y + component.height / 2 + terminal.xCenterFromComponent }*/ var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2 var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1)) if(x2 - x1 < 0) angle = angle - 180 wire.x = x1 wire.y = y1 wire.width = width wire.rotation = angle //wire.rotateAngle = angle } } //console.log("component index",component.index,"component.outputs.length",component.outputs.length) for(var i = 0 ; i < component.outputs.length ; ++i) { var terminal = terminals[component.outputs[i]] //console.log("terminal index",terminal.index,"component.outputs[i]",component.outputs[i]) for(var j = 0 ; j < terminal.wireIndex.length ; ++j) { var x = terminal.xCenterFromComponent var y = terminal.yCenterFromComponent var x1 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle) var y1 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle) var wire = wires[terminal.wireIndex[j]] var otherAngle = components[terminals[wire.to].componentIndex].initialAngle * Math.PI / 180 x = terminals[wire.to].xCenterFromComponent y = terminals[wire.to].yCenterFromComponent var x2 = terminals[wire.to].xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle) var y2 = terminals[wire.to].yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle) /*if(rotatedAngle == 90 || rotatedAngle == -270) { x1 = component.x + component.width / 2 + terminal.yCenterFromComponent y1 = component.y + component.height / 2 - terminal.xCenterFromComponent } else if(rotatedAngle == 180 || rotatedAngle == -180) { x1 = x1 + terminal.xCenterFromComponent * 2 y1 = y1 + terminal.yCenterFromComponent * 2 } else if(rotatedAngle == 270 || rotatedAngle == -90) { x1 = component.x + component.width / 2 - terminal.yCenterFromComponent y1 = component.y + component.height / 2 + terminal.xCenterFromComponent }*/ var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2 var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1)) if(x2 - x1 < 0) angle = angle - 180 //wire.posX1 = x1 //wire.posY1 = y1 //wire.posX2 = x2 //wire.posY2 = y2 wire.x = x1 wire.y = y1 wire.width = width wire.rotation = angle //wire.rotateAngle = angle } } } function deselect() { //items.availablePieces.toolDelete.state = "notSelected" items.availablePieces.rotateLeft.state = "canNotBeSelected" items.availablePieces.rotateRight.state = "canNotBeSelected" items.availablePieces.info.state = "canNotBeSelected" items.infoTxt.visible = false //toolDelete = false selectedIndex = -1 selectedTerminal = -1 for(var i = 0 ; i < terminals.length ; ++i) { terminals[i].selected = false } } function removeComponent(index) { var component = components[index] - if(component.src == "sevenSegmentDisplay.svg") + if(component.src == "sevenSegmentDisplay.svgz") sevenSegmentDisplay[index].destroy() for(var i = 0 ; i < component.inputs.length ; ++i) { var terminal = terminals[component.inputs[i]] if(terminal.wireIndex.length != 0) // Input Terminal can have only 1 wire removeWire(terminal.wireIndex[0]) } for(var i = 0 ; i < component.outputs.length ; ++i) { var terminal = terminals[component.outputs[i]] //console.log("Remove terminal.wireIndex.length",terminal.wireIndex.length) while (terminal.wireIndex.length != 0) { //console.log("terminal.wireIndex[j]",terminal.wireIndex[j]) removeWire(terminal.wireIndex[0]) // Output Terminal can have more than 1 wire } } components[index].destroy() deletedIndex.push(index) deselect() } function removeWire(index) { var wire = wires[index] var inTerminal = terminals[wire.to] var outTerminal = terminals[wire.from] var removeIndex = inTerminal.wireIndex.indexOf(index) inTerminal.wireIndex.splice(removeIndex,1) removeIndex = outTerminal.wireIndex.indexOf(index) outTerminal.wireIndex.splice(removeIndex,1) //removeIndex = connected.indexOf(wire.to) //connected.splice(wire.to,1) connected[wire.to] = -1 inTerminal.value = -1 wires[index].destroy() deletedWireIndex.push(index) updateComponent(inTerminal.componentIndex) } function componentSelected(index) { selectedIndex = index items.availablePieces.rotateLeft.state = "canBeSelected" items.availablePieces.rotateRight.state = "canBeSelected" items.availablePieces.info.state = "canBeSelected" } function rotateLeft() { + components[selectedIndex].rotationAngle = -2//components[selectedIndex].initialAngle - 90 //console.log("rotationAngle",components[selectedIndex].rotationAngle) components[selectedIndex].rotateComponent.start() /*components[selectedIndex].initialAngle = components[selectedIndex].rotationAngle == -360 ? 0 : components[selectedIndex].rotationAngle*/ } function rotateRight() { + components[selectedIndex].rotationAngle = 2//components[selectedIndex].initialAngle + 90 //console.log("rotationAngle",components[selectedIndex].rotationAngle) components[selectedIndex].rotateComponent.start() /*components[selectedIndex].initialAngle = components[selectedIndex].rotationAngle == 360 ? 0 : components[selectedIndex].rotationAngle*/ } function displayInfo() { var src = components[selectedIndex].imgSrc var component = componentsInfo[mapSrc[src]] deselect() items.infoTxt.visible = true items.infoTxt.text = component[6] if(component[7].length == 0) items.displayTruthTable = false else { items.displayTruthTable = true var truthTable = items.truthTablesModel truthTable.clear() truthTable.rows = component[7].length truthTable.columns = component[7][0].length truthTable.inputs = component[4].length truthTable.outputs = component[5].length for(var i = 0 ; i < component[7].length ; ++i) for(var j = 0 ; j < component[7][i].length ; ++j) truthTable.append({'value': component[7][i][j]}) } - if(src == "sevenSegmentDisplay.svg") { + if(src == "sevenSegmentDisplay.svgz") { items.infoImage.imgVisible = true items.infoImage.source = url + "7SegmentDisplay.svg" } else { items.infoImage.imgVisible = false items.infoImage.source = "" } - - - //console.log(componentName,componentName=="battery.svg") - /*if(componentName == "battery.svg") { - items.infoTxt.text = qsTr("Battery is a power source of DC voltage. In analog electronics, the positive " + - "terminal gives positive voltage, equal to the rating of battery and negative " + - "terminal acts as ground (zero voltage). The battery can have different values " + - "depending on its rating. In digital electronics, positive voltage is represented " + - "by symbol ‘1’ and ground is represented by symbol ‘0’. Therefore in digital " + - "electronics, there are only two states of voltage produced by battery – ‘1’ and ‘0’.") - //items.infoImage.source = "" - }*/ - - - - /*if(componentName == "one.svg" || componentName == "zero.svg") { - items.infoTxt.text = qsTr("Digital electronics is a branch of electronics that handle digital signals " + - "(i.e discrete signals instead of continous signals). Therefore all values within " + - "a range or band represent the same numeric value. In most cases, the number of " + - "these states is two and they are represented by two voltage bands: one near a " + - "reference value (typically termed as 'ground' or zero volts), and other value near " + - "the supply voltage. These correspond to the 'false' ('0') and 'true' ('1') values " + - "of the Boolean domain respectively (named after its inventor, George Boole). " + - "In this activity, you can give '0' and '1' as input to other logical devices, " + - "and see their output through an output device.") - //items.infoImage.source = "" - } - else if(componentName == "gateAnd.svg") { - items.infoTxt.text = qsTr("AND gate takes 2 or more binary input in its input terminals and outputs a single " + - "value. The output is 0 if any of the input is 0, else it is 1. In this activity, " + - "a 2 input AND gate is shown. Truth table for 2 input AND gate is:") - //items.infoImage.source = url + "AndTruthTable.svg" - items.truthTablesModel.rows = 1 - items.truthTablesModel.columns = 3 - items.truthTablesModel.inputs = 2 - items.truthTablesModel.outputs = 1 - items.truthTablesModel.append({'value': "A"}) - items.truthTablesModel.append({'value': "B"}) - items.truthTablesModel.append({'value': "C"}) - - } - else if(componentName == "gateNand.svg") { - items.infoTxt.text = qsTr("NAND gate takes 2 or more binary input in its input terminals and outputs a single " + - "value. It is the complement of AND gate. In this activity, a 2 input NAND gate is " + - "shown. Truth table for 2 input NAND gate is:") - //items.infoImage.source = url + "NandTruthTable.svg" - } - else if(componentName == "gateNor.svg") { - items.infoTxt.text = qsTr("NOR gate takes 2 or more binary input in its input terminals and outputs a single " + - "value. It is the complement of OR gate. In this activity, a 2 input NOR gate is " + - "shown. Truth table for 2 input NOR gate is:") - //items.infoImage.source = url + "NorTruthTable.svg" - } - else if(componentName == "gateNot.svg") { - items.infoTxt.text = qsTr("Not gate (also known as inverter) takes a binary input in its input terminal and " + - "outputs a single value. The output is the complement of the input value, that is, it " + - "is 0 if input is 1, and 1 if input is 0. Truth table for NOT gate is:") - //items.infoImage.source = url + "NotTruthTable.svg" - } - else if(componentName == "gateOr.svg") { - items.infoTxt.text = qsTr("OR gate takes 2 or more binary input in its input terminals and outputs a single " + - "value. The output is 1 if any of the input is 1, else it is 0. In this activity, a " + - "2 input OR gate is shown. Truth table for 2 input OR gate is:") - //items.infoImage.source = url + "OrTruthTable.svg" - } - else if(componentName == "gateXor.svg") { - items.infoTxt.text = qsTr("XOR gate takes 2 or more binary input in its input terminals and outputs a single " + - "value. The output is 1 if number of '1' in input is odd, and 0 if number of '1' in " + - "input is even. In this activity, a 2 input XOR gate is shown. Truth table for " + - "2 input XOR gate is:") - //items.infoImage.source = url + "XorTruthTable.svg" - } - else if(componentName == "comparator.svg") { - items.infoTxt.text = qsTr("Comparator takes 2 numbers as input, A and B. It compares them and outputs 3 " + - "values. First value is true if A < B, else it is false. Second value is true " + - "if A = B, else it is false. Third value is true if A > B, else it is false. " + - "In digital electronics, true value is represented as 1, and false value is " + - "represented as 0") - } - /*else if(componentName == "BCDTo7Segment.svg") { - items.infoTxt.text = qsTr("BCD to 7 segment converter takes 4 binary inputs in its input terminals and gives " + - "7 binary outputs. The 4 binary inputs represents a BCD number (binary-coded decimal). " + - "The converter converts this BCD number to corresponding bits, which are used to " + - "display the decimal number (represented by the BCD number) on the 7 segment display. " + - "The truth table for BCD To 7 Segment converted is:") - //items.infoImage.source = url + "BCDTo7SegmentTruthTable.svg" - } - else if(componentName == "BCDTo7Segment.svg") { - items.infoTxt.text = qsTr("BCD to 7 segment converter takes 4 binary inputs which represent a BCD number, " + - "and convert them to 7 binary bits which represent corresponding number in 7 segment " + - "format. The truth table is:") - //items.infoImage.source = url + "BCDTo7SegmentTruthTable.svg" - } - else if(componentName == "sevenSegmentDisplay.svg") { - items.infoTxt.text = qsTr("7 segment display takes 7 binary inputs in its input terminals. The display " + - "consists of 7 segments and each segment gets lighted according to the input. " + - "By generating different combination of binary inputs, the display can be used to " + - "display various different symbols. The diagram is:") - //items.infoImage.source = url + "7SegmentDisplay.svg" - } - else if(componentName == "ledOn.svg" || componentName == "ledOff.svg") { - items.infoTxt.text = qsTr("LED (Light-emitting diode) is a two-lead semiconductor light source. It emits " + - "light when activated. LED has 2 input terminals, the longer terminal is the " + - "positive terminal (anode) and smaller terminal is the negative terminal (cathode)" + - ". LED is activated when anode has a higher potential than cathode. In digital " + - "electronics LED can be used to check the output of the components. Connect " + - "the cathode of LED to ground ('0') and anode of LED to the output of the " + - "component. If output is 1, the LED will be activated (emit light), and if " + - "output is 0, the LED will be deactivated.") - //items.infoImage.source = "" - } - else if(componentName == "switchOn.svg" || componentName == "switchOff.svg") { - items.infoTxt.text = qsTr("Switch is used to maintain easy connection between two terminals. If the switch is " + - "turned on, then the two terminals are connected and current can flow through the " + - "switch. If the switch is turned off, then the connection between terminal is broken, " + - "and current can not flow through it.") - //items.infoImage.source = "" - }*/ - //console.log(items.infoTxt.text) } function updateToolTip(toolTipTxt) { items.toolTip.show(toolTipTxt) } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } diff --git a/src/activities/digital_electricity/resource/BCDTo7Segment.svg b/src/activities/digital_electricity/resource/BCDTo7Segment.svg index b6ab20074..0e3e22b2d 100644 --- a/src/activities/digital_electricity/resource/BCDTo7Segment.svg +++ b/src/activities/digital_electricity/resource/BCDTo7Segment.svg @@ -1,324 +1,324 @@ + sodipodi:docname="BCDTo7Segment2.svg"> image/svg+xml b + y="434.48846">b c + y="514.02008">c d + y="602.86847">d e + y="686.80664">e f + y="769.22711">f g a B C D A diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentA_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentA_black.svgz new file mode 100644 index 000000000..bb86d095d Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentA_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentA_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentA_red.svgz new file mode 100644 index 000000000..f6829e0a4 Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentA_red.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentB_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentB_black.svgz new file mode 100644 index 000000000..35a9d89be Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentB_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentB_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentB_red.svgz new file mode 100644 index 000000000..a4eb7f4e9 Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentB_red.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentC_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentC_black.svgz new file mode 100644 index 000000000..0776862a3 Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentC_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentC_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentC_red.svgz new file mode 100644 index 000000000..0ae50099d Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentC_red.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentD_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentD_black.svgz new file mode 100644 index 000000000..bf214465b Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentD_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentD_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentD_red.svgz new file mode 100644 index 000000000..19cfd068e Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentD_red.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7Segment.svg b/src/activities/digital_electricity/resource/BCDTo7SegmentDropped.svg similarity index 72% copy from src/activities/digital_electricity/resource/BCDTo7Segment.svg copy to src/activities/digital_electricity/resource/BCDTo7SegmentDropped.svg index b6ab20074..81ffcb1ef 100644 --- a/src/activities/digital_electricity/resource/BCDTo7Segment.svg +++ b/src/activities/digital_electricity/resource/BCDTo7SegmentDropped.svg @@ -1,324 +1,247 @@ image/svg+xml - + - b - c - d - e - f - g - a B C D A diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentE_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentE_black.svgz new file mode 100644 index 000000000..519bae57c Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentE_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentE_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentE_red.svgz new file mode 100644 index 000000000..141e88519 Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentE_red.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentF_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentF_black.svgz new file mode 100644 index 000000000..d34c470e9 Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentF_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentF_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentF_red.svgz new file mode 100644 index 000000000..d0111decc Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentF_red.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentG_black.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentG_black.svgz new file mode 100644 index 000000000..545dba8f4 Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentG_black.svgz differ diff --git a/src/activities/digital_electricity/resource/BCDTo7SegmentG_red.svgz b/src/activities/digital_electricity/resource/BCDTo7SegmentG_red.svgz new file mode 100644 index 000000000..7e5f26d3c Binary files /dev/null and b/src/activities/digital_electricity/resource/BCDTo7SegmentG_red.svgz differ diff --git a/src/activities/digital_electricity/resource/ElectricalComponents.qml b/src/activities/digital_electricity/resource/ElectricalComponents.qml index cd744f0f4..c513ff2e8 100644 --- a/src/activities/digital_electricity/resource/ElectricalComponents.qml +++ b/src/activities/digital_electricity/resource/ElectricalComponents.qml @@ -1,461 +1,461 @@ /* GCompris * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (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.0 +import QtQuick 2.3 QtObject { property variant components : [ { "imgName": "zero.svg", "imgWidth": 0.12, "imgHeight": 0.2, "toolTipText": qsTr("Zero input"), "terminalSize": 0.205, "inputTerminals": [], "outputTerminals": [ { "posX": 0.91, "posY": 0.5, "value": 0 } ], "information": qsTr("Digital electronics is a branch of electronics that handle digital signals " + "(i.e discrete signals instead of continous signals). Therefore all values within " + "a range or band represent the same numeric value. In most cases, the number of " + "these states is two and they are represented by two voltage bands: one near a " + "reference value (typically termed as 'ground' or zero volts), and other value near " + "the supply voltage. These correspond to the 'false' ('0') and 'true' ('1') values " + "of the Boolean domain respectively (named after its inventor, George Boole). " + "In this activity, you can give '0' and '1' as input to other logical devices, " + "and see their output through an output device."), "truthTable": [] }, { "imgName": "one.svg", "imgWidth": 0.12, "imgHeight": 0.2, "toolTipText": qsTr("One input"), "terminalSize": 0.218, "inputTerminals": [], "outputTerminals": [ { "posX": 0.91, "posY": 0.5, "value": 1 } ], "information": qsTr("Digital electronics is a branch of electronics that handle digital signals " + "(i.e discrete signals instead of continous signals). Therefore all values within " + "a range or band represent the same numeric value. In most cases, the number of " + "these states is two and they are represented by two voltage bands: one near a " + "reference value (typically termed as 'ground' or zero volts), and other value near " + "the supply voltage. These correspond to the 'false' ('0') and 'true' ('1') values " + "of the Boolean domain respectively (named after its inventor, George Boole). " + "In this activity, you can give '0' and '1' as input to other logical devices, " + "and see their output through an output device."), "truthTable": [] }, { "imgName": "BCDTo7Segment.svg", "imgWidth": 0.3, "imgHeight": 0.4, "toolTipText": qsTr("BCD To 7 Segment"), "terminalSize": 0.097, "inputTerminals": [ { "posX": 0.031, "posY": 0.057 }, { "posX": 0.031, "posY": 0.35 }, { "posX": 0.031, "posY": 0.649 }, { "posX": 0.031, "posY": 0.935 } ], "outputTerminals": [ { "posX": 0.969, "posY": 0.048 }, { "posX": 0.969, "posY": 0.198 }, { "posX": 0.969, "posY": 0.353 }, { "posX": 0.968, "posY": 0.509 }, { "posX": 0.969, "posY": 0.664 }, { "posX": 0.969, "posY": 0.812 }, { "posX": 0.969, "posY": 0.952 } ], "information": qsTr("BCD to 7 segment converter takes 4 binary inputs in its input terminals and gives " + "7 binary outputs. The 4 binary inputs represents a BCD number (binary-coded decimal). " + "The converter converts this BCD number to corresponding bits, which are used to " + "display the decimal number (represented by the BCD number) on the 7 segment display. " + "The truth table for BCD To 7 Segment converted is:"), "truthTable": [['A','B','C','D','a','b','c','d','e','f','g'], ['0','0','0','0','1','1','1','1','1','1','0'], ['0','0','0','1','0','1','1','0','0','0','0'], ['0','0','1','0','1','1','0','1','1','0','1'], ['0','0','1','1','1','1','1','1','0','0','1'], ['0','1','0','0','0','1','1','0','0','1','1'], ['0','1','0','1','1','0','1','1','0','1','1'], ['0','1','1','0','1','0','1','1','1','1','1'], ['0','1','1','1','1','1','1','0','0','0','0'], ['1','0','0','0','1','1','1','1','1','1','1'], ['1','0','0','1','1','1','1','1','0','1','1']] }, { - "imgName": "sevenSegmentDisplay.svg", + "imgName": "sevenSegmentDisplay.svgz", "imgWidth": 0.18, "imgHeight": 0.4, "toolTipText": qsTr("7 Segment Display"), "terminalSize": 0.116, "inputTerminals": [ { "posX": 0.06, "posY": 0.058 }, { "posX": 0.06, "posY": 0.195 }, { "posX": 0.06, "posY": 0.337 }, { "posX": 0.06, "posY": 0.484 }, { "posX": 0.06, "posY": 0.636 }, { "posX": 0.06, "posY": 0.791 }, { "posX": 0.06, "posY": 0.942 } ], "outputTerminals": [], "information": qsTr("7 segment display takes 7 binary inputs in its input terminals. The display " + "consists of 7 segments and each segment gets lighted according to the input. " + "By generating different combination of binary inputs, the display can be used to " + "display various different symbols. The diagram is:"), "truthTable": [] }, { "imgName": "comparator.svg", "imgWidth": 0.3, "imgHeight": 0.25, "toolTipText": qsTr("Comparator"), "terminalSize": 0.214, "inputTerminals": [ { "posX": 0.039, "posY": 0.211 }, { "posX": 0.039, "posY": 0.784 } ], "outputTerminals": [ { "posX": 0.961, "posY": 0.128 }, { "posX": 0.961, "posY": 0.481 }, { "posX": 0.961, "posY": 0.88 } ], "information": qsTr("Comparator takes 2 numbers as input, A and B. It compares them and outputs 3 " + "values. First value is true if A < B, else it is false. Second value is true " + "if A = B, else it is false. Third value is true if A > B, else it is false. " + "In digital electronics, true value is represented as 1, and false value is " + "represented as 0"), "truthTable": [] }, { "imgName": "switchOff.svg", "imgWidth": 0.18, "imgHeight": 0.15, "toolTipText": qsTr("Switch"), "terminalSize": 0.552, "inputTerminals": [ { "posX": 0.065, "posY": 0.503 } ], "outputTerminals": [ { "posX": 0.935, "posY": 0.497 } ], "information": qsTr("Switch is used to maintain easy connection between two terminals. If the switch is " + "turned on, then the two terminals are connected and current can flow through the " + "switch. If the switch is turned off, then the connection between terminal is broken, " + "and current can not flow through it."), "truthTable": [] }, { "imgName": "gateAnd.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("AND gate"), "terminalSize": 0.246, "inputTerminals": [ { "posX": 0.045, "posY": 0.219 }, { "posX": 0.045, "posY": 0.773 } ], "outputTerminals": [ { "posX": 0.955, "posY": 0.5 } ], "information": qsTr("AND gate takes 2 or more binary input in its input terminals and outputs a single " + "value. The output is 0 if any of the input is 0, else it is 1. In this activity, " + "a 2 input AND gate is shown. Truth table for 2 input AND gate is:"), "truthTable": [['A','B',"A.B"], ['0','0','0'], ['0','1','0'], ['1','0','0'], ['1','1','1']] }, { "imgName": "gateNand.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("NAND gate"), "terminalSize": 0.273, "inputTerminals": [ { "posX": 0.045, "posY": 0.174 }, { "posX": 0.045, "posY": 0.786 } ], "outputTerminals": [ { "posX": 0.955, "posY": 0.484 } ], "information": qsTr("NAND gate takes 2 or more binary input in its input terminals and outputs a single " + "value. It is the complement of AND gate. In this activity, a 2 input NAND gate is " + "shown. Truth table for 2 input NAND gate is:"), "truthTable": [['A','B',"~(A.B)"], ['0','0','1'], ['0','1','1'], ['1','0','1'], ['1','1','0']] }, { "imgName": "gateNor.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("NOR gate"), "terminalSize": 0.251, "inputTerminals": [ { "posX": 0.045, "posY": 0.205 }, { "posX": 0.045, "posY": 0.769 } ], "outputTerminals": [ { "posX": 0.955, "posY": 0.491 } ], "information": qsTr("NOR gate takes 2 or more binary input in its input terminals and outputs a single " + "value. It is the complement of OR gate. In this activity, a 2 input NOR gate is " + "shown. Truth table for 2 input NOR gate is:"), "truthTable": [['A','B',"~(A+B)"], ['0','0','1'], ['0','1','0'], ['1','0','0'], ['1','1','0']] }, { "imgName": "gateNot.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("Not gate"), "terminalSize": 0.261, "inputTerminals": [ { "posX": 0.046, "posY": 0.503 } ], "outputTerminals": [ { "posX": 0.954, "posY": 0.492 } ], "information": qsTr("Not gate (also known as inverter) takes a binary input in its input terminal and " + "outputs a single value. The output is the complement of the input value, that is, it " + "is 0 if input is 1, and 1 if input is 0. Truth table for NOT gate is:"), "truthTable": [['A',"~A"], ['0','1'], ['1','0']] }, { "imgName": "gateOr.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("Or gate"), "terminalSize": 0.251, "inputTerminals": [ { "posX": 0.045, "posY": 0.223 }, { "posX": 0.045, "posY": 0.786 } ], "outputTerminals": [ { "posX": 0.955, "posY": 0.509 } ], "information": qsTr("OR gate takes 2 or more binary input in its input terminals and outputs a single " + "value. The output is 1 if any of the input is 1, else it is 0. In this activity, a " + "2 input OR gate is shown. Truth table for 2 input OR gate is:"), "truthTable": [['A','B',"A+B"], ['0','0','0'], ['0','1','1'], ['1','0','1'], ['1','1','1']] }, { "imgName": "gateXor.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("Xor gate"), "terminalSize": 0.229, "inputTerminals": [ { "posX": 0.045, "posY": 0.248 }, { "posX": 0.045, "posY": 0.762 } ], "outputTerminals": [ { "posX": 0.955, "posY": 0.509 } ], "information": qsTr("XOR gate takes 2 or more binary input in its input terminals and outputs a single " + "value. The output is 1 if number of '1' in input is odd, and 0 if number of '1' in " + "input is even. In this activity, a 2 input XOR gate is shown. Truth table for " + "2 input XOR gate is:"), "truthTable": [['A','B',"A^B"], ['0','0','0'], ['0','1','1'], ['1','0','1'], ['1','1','0']] }, { "imgName": "ledOff.svg", "imgWidth": 0.16, "imgHeight": 0.2, "toolTipText": qsTr("LED"), "terminalSize": 0.111, "inputTerminals": [ { "posX": 0.319, "posY": 0.945 }, { "posX": 0.776, "posY": 0.698 } ], "outputTerminals": [], "information": qsTr("LED (Light-emitting diode) is a two-lead semiconductor light source. It emits " + "light when activated. LED has 2 input terminals, the longer terminal is the " + "positive terminal (anode) and smaller terminal is the negative terminal (cathode)" + ". LED is activated when anode has a higher potential than cathode. In digital " + "electronics LED can be used to check the output of the components. Connect " + "the cathode of LED to ground ('0') and anode of LED to the output of the " + "component. If output is 1, the LED will be activated (emit light), and if " + "output is 0, the LED will be deactivated."), "truthTable": [] } ] } diff --git a/src/activities/digital_electricity/resource/battery.svg b/src/activities/digital_electricity/resource/battery.svg deleted file mode 100644 index a96e22249..000000000 --- a/src/activities/digital_electricity/resource/battery.svg +++ /dev/null @@ -1,594 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - image/svg+xml - - - - - Openclipart - - - AA-battery - 2013-01-22T05:51:05 - AA-battery - https://openclipart.org/detail/174380/aa-battery-by-iyo-174380 - - - Iyo - - - - - AA - batterij - battery - cell - electricity - energy - negative - positive - power - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplay.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplay.svg deleted file mode 100644 index bacad6022..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplay.svg +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - Seven segment display gray 7 - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplay.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplay.svgz new file mode 100644 index 000000000..7be9e7cea Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplay.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayA.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayA.svg deleted file mode 100644 index 82eac18ad..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayA.svg +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayA.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayA.svgz new file mode 100644 index 000000000..6713a16ef Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayA.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayB.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayB.svg deleted file mode 100644 index 3cd0ad2fa..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayB.svg +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayB.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayB.svgz new file mode 100644 index 000000000..b0cff2388 Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayB.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayC.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayC.svg deleted file mode 100644 index 8a1aebaac..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayC.svg +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayC.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayC.svgz new file mode 100644 index 000000000..09b31dff7 Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayC.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayD.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayD.svg deleted file mode 100644 index 511219324..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayD.svg +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayD.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayD.svgz new file mode 100644 index 000000000..4a945b2f8 Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayD.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayE.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayE.svg deleted file mode 100644 index 066eb9ed4..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayE.svg +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayE.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayE.svgz new file mode 100644 index 000000000..1f500dd2e Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayE.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayF.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayF.svg deleted file mode 100644 index 1ed42cea0..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayF.svg +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayF.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayF.svgz new file mode 100644 index 000000000..1ee8fe9b6 Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayF.svgz differ diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayG.svg b/src/activities/digital_electricity/resource/sevenSegmentDisplayG.svg deleted file mode 100644 index 677bfe04f..000000000 --- a/src/activities/digital_electricity/resource/sevenSegmentDisplayG.svg +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - Openclipart - - - - 2012-03-15T11:54:43 - A simple seven segment display - https://openclipart.org/detail/168838/seven-segment-display-gray-7-by-alex8664 - - - alex8664 - - - - - display - lcd - number - seven segment - - - - - - - - - - - diff --git a/src/activities/digital_electricity/resource/sevenSegmentDisplayG.svgz b/src/activities/digital_electricity/resource/sevenSegmentDisplayG.svgz new file mode 100644 index 000000000..1cb988707 Binary files /dev/null and b/src/activities/digital_electricity/resource/sevenSegmentDisplayG.svgz differ