Commit a43d7e07 authored by Aiswarya Kaitheri Kandoth's avatar Aiswarya Kaitheri Kandoth Committed by Timothée Giet

analog_electricity, merge branch

add new activity analog_electricity
parent 0d9270b8
......@@ -9,6 +9,7 @@ algorithm
align4
align4-2players
alphabet-sequence
analog_electricity
baby_keyboard
babymatch
babyshapes
......
This diff is collapsed.
/* GCompris - ActivityInfo.qml
*
* Copyright (C) 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
*
* 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 <https://www.gnu.org/licenses/>.
*/
import GCompris 1.0
ActivityInfo {
name: "analog_electricity/AnalogElectricity.qml"
difficulty: 6
icon: "analog_electricity/analog_electricity.svg"
author: "Aiswarya Kaitheri Kandoth &lt;aiswaryakk29@gmail.com&gt;"
//: Activity title
title: qsTr("Analog Electricity")
//: Help title
description: qsTr("Create and simulate an analog electric schema")
//intro: "Learn how analog electricity works and create your own circuit."
//: Help goal
goal: qsTr("Create an analog electric schema with a real time simulation.")
//: Help prerequisite
prerequisite: qsTr("Requires some basic understanding of the concept of electricity.")
//: Help manual
manual: qsTr("Drag electrical components from the selector and drop them in the working area. In the working area, you can move the components by dragging them.") + " " + qsTr("To delete a component or wire, select the deletion tool on top of the component selector, and select the component or wire.") + " " + qsTr("You can click on the component and then on the rotate buttons to rotate it or on the info button to get information about it.") + " " + qsTr("You can click on the switch to open and close it. You can change the rheostat value by dragging its slider.") + " " + qsTr("To connect two terminals, click on the first terminal, then on the second terminal. To deselect a terminal, click on any empty area.") + " " + qsTr("In order to repair a broken bulb or LED, click on it after deconnecting it from the circuit. The simulation is updated in real time by any user action.")
credit: qsTr("The electric simulation engine is from edX: ") +
"&lt;https://github.com/edx/edx-platform/blob/master/common/lib/xmodule/xmodule/js/src/capa/schematic.js&gt;."
section: "sciences experiment"
createdInVersion: 9800
}
/* GCompris - AnalogElectricity.qml
*
* Copyright (C) 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
*
* Authors:
* Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
* Pulkit Gupta <pulkitnsit@gmail.com> (DigitalElectricity code)
* Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> (DigitalElectricity code)
* Timothée Giet <animtim@gmail.com> (mouse drag refactoring)
* Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com> (Qt Quick port of AnalogElectricity)
*
* 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 <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import GCompris 1.0
import "../../core"
import "analog_electricity.js" as Activity
ActivityBase {
id: activity
onStart: focus = true
onStop: {}
pageComponent: Image {
id: background
anchors.fill: parent
source: Activity.urlDigital + "texture02.png"
fillMode: Image.Tile
signal start
signal stop
onWidthChanged: resizeTimer.restart();
onHeightChanged: resizeTimer.restart();
Timer {
id: resizeTimer
interval: 200
repeat: false
running: false
triggeredOnStart: false
onTriggered: Activity.updateWiresOnResize();
}
Timer {
id: netlistTimer
interval: 500
repeat: false
running: false
triggeredOnStart: false
onTriggered: Activity.createNetlist();
}
property bool hori: background.width >= background.height
Component.onCompleted: {
activity.start.connect(start);
activity.stop.connect(stop);
}
Keys.onPressed: {
// if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && okButton.enabled) {
// Activity.checkAnswer()
// }
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;
}
}
onHoriChanged: {
if (hori === true) {
playArea.x += items.toolsMargin;
playArea.y -= items.toolsMargin;
} else {
playArea.x -= items.toolsMargin;
playArea.y += items.toolsMargin;
}
}
// Add here the QML items you need to access in javascript
QtObject {
id: items
property Item main: activity.main
property alias background: background
property alias bar: bar
property alias bonus: bonus
property alias playArea: playArea
property alias mousePan: mousePan
property alias availablePieces: availablePieces
property alias tutorialDataset: tutorialDataset
property alias toolTip: toolTip
property alias infoTxt: infoTxt
property alias infoImage: infoImage
property alias dataset: dataset
property alias netlistTimer: netlistTimer
property real toolsMargin: 90 * ApplicationInfo.ratio
property real zoomLvl: 0.25
}
Loader {
id: dataset
asynchronous: false
}
TutorialDataset {
id: tutorialDataset
}
onStart: Activity.start(items);
onStop: Activity.stop();
Rectangle {
id: visibleArea
color: "#00000000"
width: background.hori ? background.width - items.toolsMargin - 10 : background.width - 10
height: background.hori ? background.height - bar.height - items.toolsMargin - 10 : background.height - bar.height - 10
anchors {
fill: undefined
top: background.hori ? parent.top : inputComponentsContainer.bottom
topMargin: 5
right: parent.right
rightMargin: 5
left: background.hori ? inputComponentsContainer.right : parent.left
leftMargin: 5
bottom: bar.top
bottomMargin: 20
}
z: 6
GCText {
id: infoTxt
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: 2
}
fontSizeMode: Text.Fit
minimumPixelSize: 10
font.pixelSize: 150
color: "white"
horizontalAlignment: Text.AlignHLeft
width: Math.min(implicitWidth, 0.90 * parent.width)
height: Math.min(implicitHeight, 0.7 * parent.height)
wrapMode: TextEdit.WordWrap
visible: false
z: 4
}
Rectangle {
id: infoTxtContainer
anchors.fill: parent
opacity: 1
radius: 10
color: "#373737"
border.width: 2
border.color: "#F2F2F2"
visible: infoTxt.visible
MouseArea {
anchors.fill: parent
onClicked: infoTxt.visible = false
}
z: 3
}
Image {
id: infoImage
property bool imgVisible: false
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: infoTxtContainer.horizontalCenter
}
z: 5
}
}
Rectangle {
id: playArea
color: "#10000000"
x: background.hori ? items.toolsMargin : 0
y: background.hori ? 0 : items.toolsMargin
width: background.hori ?
background.width * 4 - items.toolsMargin : background.width * 4
height: background.hori ?
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: - playArea.width * items.zoomLvl
drag.maximumX: background.hori ? items.toolsMargin : 0
drag.minimumY: - playArea.height * items.zoomLvl
drag.maximumY: background.hori ? 0 : items.toolsMargin
onClicked: {
Activity.deselect();
availablePieces.hideToolbar();
}
}
}
}
Rectangle {
id: inputComponentsContainer
width: background.hori ? items.toolsMargin : background.width
height: background.hori ? background.height : items.toolsMargin
color: "#4A3823"
anchors.left: parent.left
Image {
anchors.fill: parent
anchors.rightMargin: background.hori ? 3 * ApplicationInfo.ratio : 0
anchors.bottomMargin: background.hori ? 0 : 3 * ApplicationInfo.ratio
source: Activity.urlDigital + "texture01.png"
fillMode: Image.Tile
ListWidget {
id: availablePieces
hori: background.hori
}
}
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: 0
radius: 10
z: 100
border.width: 2
border.color: "#F2F2F2"
property alias text: toolTipTxt.text
Behavior on opacity { NumberAnimation { duration: 120 } }
function show(newText) {
if(newText) {
text = newText;
opacity = 1;
} else {
opacity = 0;
}
}
GCText {
id: toolTipTxt
anchors.centerIn: parent
fontSize: regularSize
color: "white"
horizontalAlignment: Text.AlignHCenter
wrapMode: TextEdit.WordWrap
}
}
DialogHelp {
id: dialogHelp
onClose: home();
}
Bar {
id: bar
content: BarEnumContent { value: help | home | level | reload }
onHelpClicked: displayDialog(dialogHelp);
onPreviousLevelClicked: Activity.previousLevel();
onNextLevelClicked: Activity.nextLevel();
onHomeClicked: activity.home();
onReloadClicked: Activity.initLevel();
}
Bonus {
id: bonus
Component.onCompleted: win.connect(Activity.nextLevel);
}
}
}
GCOMPRIS_ADD_RCC(activities/analog_electricity *.qml *.svg *.js resource/* components/*)
/* gcompris - DragListItem.qml
*
* Copyright (C) 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
*
* Authors:
* Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
* Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port)
* Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com> (AnalogElectricity activity)
*
* 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 <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import GCompris 1.0
import "analog_electricity.js" as Activity
Item {
id: item
width: tile.width
height: tile.height
property string source: componentSrc
property string imageName: imgName
property string toolTipTxt: toolTipText
property double imageWidth: imgWidth
property double imageHeight: imgHeight
property double heightInColumn
property double widthInColumn
property double tileWidth
property double tileHeight
property bool selected: false
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 * playArea.width
property double fullHeight: imgHeight * playArea.height
property QtObject tileImageParent
property bool small: true
function toSmall() {
width = smallWidth;
height = smallHeight;
small = true;
}
function toFull() {
width = fullWidth * Activity.currentZoom;
height = fullHeight * Activity.currentZoom;
small = false;
}
MultiPointTouchArea {
id: mouseArea
touchPoints: [ TouchPoint { id: point1 } ]
property real startX
property real startY
property bool pressedOnce
anchors.fill: parent
onPressed: {
tileImage.anchors.centerIn = undefined;
startX = point1.x;
startY = point1.y;
tileImage.toFull();
toolTip.show(toolTipText);
pressedOnce = true;
item.selected = true;
Activity.disableToolDelete();
}
onUpdated: {
var moveX = point1.x - startX;
var moveY = point1.y - startY;
parent.x = parent.x + moveX;
parent.y = parent.y + moveY;
}
onReleased: {
if (pressedOnce) {
pressedOnce = false;
item.selected = false;
var coord = playArea.mapFromItem(tileImage.parent, parent.x, parent.y);
if(coord.x > 0 && ((playArea.width/Activity.currentZoom) - coord.x > tileImage.fullWidth))
Activity.createComponent(coord.x, coord.y, index);
tileImage.anchors.centerIn = tile;
tileImage.toSmall();
toolTip.show("");
}
}
}
}
}
}
/* gcompris - ListWidget.qml
*
* Copyright (C) 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
*
* Authors:
* Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
* Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port)
* Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com> (AnalogElectricity activity)
* 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 <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import GCompris 1.0
import "../../core"
import "analog_electricity.js" as Activity
Item {
id: listWidget
anchors.fill: parent
anchors.topMargin: 5 * ApplicationInfo.ratio
anchors.leftMargin: 5 * ApplicationInfo.ratio
z: 10
property bool hori
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
property alias zoomInBtn: zoomInBtn
property alias zoomOutBtn: zoomOutBtn
signal hideToolbar
onHideToolbar: toolButton.showToolBar = false;