Warning, /education/gcompris/src/activities/analog_electricity/components/TerminalPoint.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - TerminalPoint.qml
0002  *
0003  * SPDX-FileCopyrightText: 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port)
0008  *   Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com> (AnalogElectricity activity)
0009  *
0010  *   SPDX-License-Identifier: GPL-3.0-or-later
0011  */
0012 import QtQuick 2.12
0013 import GCompris 1.0
0014 
0015 import "../analog_electricity.js" as Activity
0016 
0017 Image {
0018     id: terminalPoint
0019 
0020     property double posX
0021     property double posY
0022     property double size: parent.terminalSize
0023     property bool selected: false
0024     property int value: 0
0025     property var wires: []
0026     property int colorIndex: -1
0027     property int initialIndex: 0
0028     property int netlistIndex: 0
0029     property string terminalType: "noPolarity"
0030 
0031     width: size * Math.max(parent.paintedHeight, parent.paintedWidth)
0032     height: width
0033     source: Activity.urlDigital + "tPoint.svg"
0034     sourceSize.width: width
0035     sourceSize.height: width
0036     antialiasing: true
0037 
0038     x: (parent.width - parent.paintedWidth) / 2 + posX * parent.paintedWidth - width / 2
0039     y: (parent.height - parent.paintedHeight) / 2 + posY * parent.paintedHeight - height / 2
0040 
0041     property double xCenter: terminalPoint.parent.x + terminalPoint.x + width/2
0042     property double yCenter: terminalPoint.parent.y + terminalPoint.y + height/2
0043     property double xCenterFromComponent: terminalPoint.x + width/2 - terminalPoint.parent.width / 2
0044     property double yCenterFromComponent: terminalPoint.y + height/2 - terminalPoint.parent.height / 2
0045 
0046     function updateNetlistIndex(netlistIndex_, colorIndex_) {
0047         if(initialIndex === 0) {
0048             initialIndex = netlistIndex_;
0049         }
0050         terminalPoint.netlistIndex = netlistIndex_;
0051         parent.externalNetlistIndex[index] = netlistIndex_;
0052         if(colorIndex_ !== undefined) {
0053             colorIndex = colorIndex_;
0054         }
0055         propagateNetlistIndex(netlistIndex_, colorIndex);
0056     }
0057 
0058     function propagateNetlistIndex(netlistIndex_, colorIndex_) {
0059         for(var i = 0; i < wires.length; ++i) {
0060             if(wires[i].node1.netlistIndex != netlistIndex_)
0061                 wires[i].node1.updateNetlistIndex(netlistIndex_, colorIndex_);
0062             if(wires[i].node2.netlistIndex != netlistIndex_)
0063                 wires[i].node2.updateNetlistIndex(netlistIndex_, colorIndex_);
0064         }
0065     }
0066 
0067     function resetIndex() {
0068             updateNetlistIndex(initialIndex);
0069     }
0070 
0071     Rectangle {
0072         id: boundary
0073         anchors.centerIn: terminalPoint
0074         width: terminalPoint.width * 2
0075         height: width
0076         visible: selected
0077         radius: width / 2
0078         color: "#08D050"
0079         z: -1
0080     }
0081 
0082     MouseArea {
0083         id: mouseArea
0084         anchors.fill: parent
0085         onPressed: {
0086             selected = true;
0087              Activity.terminalPointSelected(terminalPoint);
0088         }
0089     }
0090 }