Warning, /education/gcompris/src/activities/digital_electricity/components/SignalGenerator.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - SignalGenerator.qml 0002 * 0003 * SPDX-FileCopyrightText: 2016 Pulkit Gupta <pulkitnsit@gmail.com> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 import GCompris 1.0 0013 import "../digital_electricity.js" as Activity 0014 import "../../../core" 0015 0016 ElectricalComponent { 0017 id: signalGenerator 0018 terminalSize: 0.25 0019 noOfInputs: 0 0020 noOfOutputs: 1 0021 0022 information: qsTr("A signal generator is used to generate alternating signals of 0 and 1. " + 0023 "The time between two changes can be modified by pressing the arrows on the generator.") 0024 0025 property alias outputTerminals: outputTerminals 0026 property double period: 1 0027 property var periodFraction: ["1/4","1/2","1","2"] 0028 property int periodIndex: 2 0029 0030 Repeater { 0031 id: outputTerminals 0032 model: 1 0033 delegate: outputTerminal 0034 Component { 0035 id: outputTerminal 0036 TerminalPoint { 0037 posX: 0.94 0038 posY: 0.5 0039 value: 0 0040 type: "Out" 0041 } 0042 } 0043 } 0044 0045 function updateOutput(wireVisited) { 0046 var terminal = outputTerminals.itemAt(0) 0047 terminal.value = terminal.value == 1 ? 0 : 1 0048 for(var i = 0 ; i < terminal.wires.length ; ++i) 0049 terminal.wires[i].to.value = terminal.value 0050 0051 var componentVisited = [] 0052 for(var i = 0 ; i < terminal.wires.length ; ++i) { 0053 var wire = terminal.wires[i] 0054 var component = wire.to.parent 0055 if(componentVisited[component] != true && wireVisited[wire] != true) { 0056 componentVisited[component] = true 0057 wireVisited[wire] = true 0058 component.updateOutput(wireVisited) 0059 } 0060 } 0061 } 0062 0063 Timer { 0064 id: timer 0065 interval: 1000 * signalGenerator.period 0066 running: true 0067 repeat: true 0068 onTriggered: Activity.updateComponent(signalGenerator.index) 0069 } 0070 0071 Image { 0072 source: Activity.url + "arrowUp.svg" 0073 height: 0.437 * parent.height 0074 width: 0.208 * parent.width 0075 sourceSize.height: height 0076 sourceSize.width: width 0077 property double posX: 0.6 0078 property double posY: 0.28 0079 x: (parent.width - parent.paintedWidth) / 2 + posX * parent.paintedWidth - width / 2 0080 y: (parent.height - parent.paintedHeight) / 2 + posY * parent.paintedHeight - height / 2 0081 fillMode: Image.PreserveAspectFit 0082 antialiasing: true 0083 opacity: 0 0084 MouseArea { 0085 anchors.fill: parent 0086 anchors.centerIn: parent 0087 enabled: signalGenerator.period != 2 0088 onPressed: { 0089 parent.opacity = 1 0090 signalGenerator.period *= 2 0091 periodIndex++ 0092 timer.restart() 0093 outputTerminals.itemAt(0).value = 1 0094 Activity.updateComponent(signalGenerator.index) 0095 } 0096 onReleased: { 0097 parent.opacity = 0 0098 } 0099 } 0100 } 0101 0102 Image { 0103 source: Activity.url + "arrowDown.svg" 0104 height: 0.437 * parent.height 0105 width: 0.208 * parent.width 0106 sourceSize.height: height 0107 sourceSize.width: width 0108 property double posX: 0.6 0109 property double posY: 0.72 0110 x: (parent.width - parent.paintedWidth) / 2 + posX * parent.paintedWidth - width / 2 0111 y: (parent.height - parent.paintedHeight) / 2 + posY * parent.paintedHeight - height / 2 0112 fillMode: Image.PreserveAspectFit 0113 antialiasing: true 0114 opacity: 0 0115 MouseArea { 0116 anchors.fill: parent 0117 anchors.centerIn: parent 0118 enabled: signalGenerator.period != 0.25 0119 onPressed: { 0120 parent.opacity = 1 0121 signalGenerator.period /= 2 0122 periodIndex-- 0123 timer.restart() 0124 outputTerminals.itemAt(0).value = 1 0125 Activity.updateComponent(signalGenerator.index) 0126 } 0127 onReleased: { 0128 parent.opacity = 0 0129 } 0130 } 0131 } 0132 0133 Rectangle { 0134 height: 0.625 * parent.height 0135 width: 0.35 * parent.width 0136 color: "#00000000" 0137 property double posX: 0.25 0138 property double posY: 0.5 0139 x: (parent.width - parent.paintedWidth) / 2 + posX * parent.paintedWidth - width / 2 0140 y: (parent.height - parent.paintedHeight) / 2 + posY * parent.paintedHeight - height / 2 0141 GCText { 0142 id: value 0143 anchors.centerIn: parent 0144 fontSizeMode: Text.Fit 0145 minimumPointSize: 6 0146 font.pointSize: 32 0147 color: "#3f6f71" 0148 horizontalAlignment: Text.AlignHCenter 0149 verticalAlignment: Text.AlignVCenter 0150 height: parent.height - 10 0151 width: parent.width - 10 0152 text: qsTr("%1 s").arg(signalGenerator.periodFraction[periodIndex]) 0153 } 0154 } 0155 }