Debian Codegraph @

src/activities/analog_electricity/components/TerminalPoint.qml

raw
1 /* GCompris - TerminalPoint.qml
2 *
3 * SPDX-FileCopyrightText: 2020 Aiswarya Kaitheri Kandoth <[email protected]>
4 *
5 * Authors:
6 * Bruno Coudoin <[email protected]> (GTK+ version)
7 * Pulkit Gupta <[email protected]> (Qt Quick port)
8 * Aiswarya Kaitheri Kandoth <[email protected]> (AnalogElectricity activity)
9 *
10 * SPDX-License-Identifier: GPL-3.0-or-later
11 */
12 import QtQuick
13 import core 1.0
14
15 import "../analog_electricity.js" as Activity
16
17 Image {
18 id: terminalPoint
19
20 property double posX
21 property double posY
22 property double size: parent ? parent.terminalSize : 1
23 property bool selected: false
24 property int value: 0
25 property var wires: []
26 property int colorIndex: -1
27 property int initialIndex: 0
28 property int netlistIndex: 0
29 property string terminalType: "noPolarity"
30
31 width: parent ? size * Math.max(parent.paintedHeight, parent.paintedWidth) : 1
32 height: width
33 source: Activity.urlDigital + "tPoint.svg"
34 sourceSize.width: width
35 sourceSize.height: width
36 antialiasing: true
37
38 x: parent ? (parent.width - parent.paintedWidth) * 0.5 + posX * parent.paintedWidth - width * 0.5 : 1
39 y: parent ? (parent.height - parent.paintedHeight) * 0.5 + posY * parent.paintedHeight - height * 0.5 : 1
40
41 property double xCenter: parent ? terminalPoint.parent.x + terminalPoint.x + width * 0.5 : 1
42 property double yCenter: parent ? terminalPoint.parent.y + terminalPoint.y + height * 0.5 : 1
43 property double xCenterFromComponent: parent ? terminalPoint.x + width * 0.5 - terminalPoint.parent.width * 0.5 : 1
44 property double yCenterFromComponent: parent ? terminalPoint.y + height * 0.5 - terminalPoint.parent.height * 0.5 : 1
45
46 function updateNetlistIndex(netlistIndex_: int, colorIndex_: int) {
47 if(initialIndex === 0) {
48 initialIndex = netlistIndex_;
49 }
50 terminalPoint.netlistIndex = netlistIndex_;
51 parent.externalNetlistIndex[index] = netlistIndex_;
52 if(colorIndex_ !== undefined) {
53 colorIndex = colorIndex_;
54 }
55 propagateNetlistIndex(netlistIndex_, colorIndex);
56 }
57
58 function propagateNetlistIndex(netlistIndex_: int, colorIndex_: int) {
59 for(var i = 0; i < wires.length; ++i) {
60 if(wires[i].node1.netlistIndex !== netlistIndex_)
61 wires[i].node1.updateNetlistIndex(netlistIndex_, colorIndex_);
62 if(wires[i].node2.netlistIndex !== netlistIndex_)
63 wires[i].node2.updateNetlistIndex(netlistIndex_, colorIndex_);
64 }
65 }
66
67 function resetIndex() {
68 updateNetlistIndex(initialIndex);
69 }
70
71 Rectangle {
72 id: boundary
73 anchors.centerIn: terminalPoint
74 width: terminalPoint.width * 2
75 height: width
76 visible: selected
77 radius: width / 2
78 color: "#08D050"
79 z: -1
80 }
81
82 MouseArea {
83 id: mouseArea
84 anchors.fill: parent
85 onPressed: {
86 selected = true;
87 Activity.terminalPointSelected(terminalPoint);
88 }
89 }
90 }