| 1 |
/* GCompris - SevenSegment.qml |
| 2 |
* |
| 3 |
* SPDX-FileCopyrightText: 2016 Pulkit Gupta <[email protected]> |
| 4 |
* |
| 5 |
* Authors: |
| 6 |
* Bruno Coudoin <[email protected]> (GTK+ version) |
| 7 |
* Pulkit Gupta <[email protected]> (Qt Quick port) |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 10 |
*/ |
| 11 |
import QtQuick |
| 12 |
import core 1.0 |
| 13 |
|
| 14 |
import "../digital_electricity.js" as Activity |
| 15 |
|
| 16 |
ElectricalComponent { |
| 17 |
id: sevenSegmentDisplay |
| 18 |
terminalSize: 0.125 |
| 19 |
noOfInputs: 7 |
| 20 |
noOfOutputs: 0 |
| 21 |
property var inputTerminalPosY: [0.066, 0.211, 0.355, 0.5, 0.645, 0.789, 0.934] |
| 22 |
property var redBars: ["sevenSegmentDisplayA.svg","sevenSegmentDisplayB.svg","sevenSegmentDisplayC.svg", |
| 23 |
"sevenSegmentDisplayD.svg","sevenSegmentDisplayE.svg","sevenSegmentDisplayF.svg", |
| 24 |
"sevenSegmentDisplayG.svg"] |
| 25 |
|
| 26 |
information: qsTr("A 7 segment display takes 7 binary inputs. The display " + |
| 27 |
"consists of 7 segments and each segment is lighted according to the input. " + |
| 28 |
"By generating different combinations of binary inputs, the display can be used to " + |
| 29 |
"display numbers from 0 to 9 and a few letters. The diagram is:") |
| 30 |
|
| 31 |
property string infoImageSrc: "7SegmentDisplay.svg" |
| 32 |
|
| 33 |
property alias inputTerminals: inputTerminals |
| 34 |
|
| 35 |
Repeater { |
| 36 |
id: inputTerminals |
| 37 |
model: 7 |
| 38 |
delegate: inputTerminal |
| 39 |
Component { |
| 40 |
id: inputTerminal |
| 41 |
TerminalPoint { |
| 42 |
posX: 0.06 |
| 43 |
posY: inputTerminalPosY[index] |
| 44 |
type: "In" |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
function updateOutput(wireVisited) { |
| 50 |
for(var i = 0 ; i < noOfInputs ; ++i) { |
| 51 |
if(inputTerminals.itemAt(i).value == 1) |
| 52 |
outputBar.itemAt(i).visible = true; |
| 53 |
else |
| 54 |
outputBar.itemAt(i).visible = false; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
Repeater { |
| 59 |
id: outputBar |
| 60 |
model: 7 |
| 61 |
delegate: outputBarImages |
| 62 |
Component { |
| 63 |
id: outputBarImages |
| 64 |
Image { |
| 65 |
source: Activity.url + redBars[index] |
| 66 |
visible: false //code[0] == 1 |
| 67 |
anchors.centerIn: parent |
| 68 |
height: parent.height |
| 69 |
width: parent.width |
| 70 |
sourceSize.height: height |
| 71 |
sourceSize.width: width |
| 72 |
fillMode: Image.PreserveAspectFit |
| 73 |
antialiasing: true |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |