Warning, /education/gcompris/src/activities/analog_electricity/components/ElectricalComponent.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - ElectricalComponent.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 "../../../core" 0016 import "../analog_electricity.js" as Activity 0017 0018 Image { 0019 id: electricalComponent 0020 property double posX 0021 property double posY 0022 property double imgWidth 0023 property double imgHeight 0024 property string information 0025 property string toolTipTxt 0026 property string labelText1: "" 0027 property string labelText2: "" 0028 property int componentIndex 0029 property int noOfConnectionPoints 0030 property var terminalConnected: 0 0031 property int rotationAngle: 0 0032 property int initialAngle: 0 0033 property int startingAngle: 0 0034 property double terminalSize 0035 property bool destructible 0036 property bool showLabel: false 0037 0038 property alias rotateComponent: rotateComponent 0039 0040 x: posX * parent.width 0041 y: posY * parent.height 0042 sourceSize.width: imgWidth * parent.sizeMultiplier 0043 sourceSize.height: imgHeight * parent.sizeMultiplier 0044 width: sourceSize.width 0045 height: sourceSize.height 0046 fillMode: Image.PreserveAspectFit 0047 0048 z: 2 0049 mipmap: true 0050 antialiasing: true 0051 0052 onPaintedWidthChanged: { 0053 updateDragConstraints(); 0054 Activity.updateWires(componentIndex); 0055 } 0056 0057 PropertyAnimation { 0058 id: rotateComponent 0059 target: electricalComponent 0060 property: "rotation" 0061 from: initialAngle; to: initialAngle + rotationAngle 0062 duration: 1 0063 onStarted:{ Activity.animationInProgress = true } 0064 onStopped: { 0065 initialAngle = initialAngle + rotationAngle; 0066 Activity.updateWires(componentIndex); 0067 if(initialAngle == startingAngle + rotationAngle * 45) { 0068 if(initialAngle == 360 || initialAngle == -360) 0069 initialAngle = 0; 0070 startingAngle = initialAngle; 0071 Activity.animationInProgress = false; 0072 updateDragConstraints(); 0073 } 0074 else 0075 rotateComponent.start(); 0076 } 0077 easing.type: Easing.InOutQuad; 0078 } 0079 0080 function updateDragConstraints() { 0081 if(initialAngle == 0 || initialAngle == 180 || initialAngle == 360 || initialAngle == -360 0082 || initialAngle == -180) { 0083 mouseArea.drag.minimumX = (electricalComponent.paintedWidth - electricalComponent.width)/2; 0084 mouseArea.drag.minimumY = (electricalComponent.paintedHeight - electricalComponent.height)/2; 0085 0086 mouseArea.drag.maximumX = electricalComponent.parent.width - 0087 (electricalComponent.width + electricalComponent.paintedWidth)/2; 0088 mouseArea.drag.maximumY = electricalComponent.parent.height - 0089 (electricalComponent.height + electricalComponent.paintedHeight)/2; 0090 } 0091 else { 0092 mouseArea.drag.minimumX = (electricalComponent.paintedHeight - electricalComponent.width)/2; 0093 mouseArea.drag.minimumY = (electricalComponent.paintedWidth - electricalComponent.height)/2; 0094 0095 mouseArea.drag.maximumX = electricalComponent.parent.width - 0096 (electricalComponent.width + electricalComponent.paintedHeight)/2; 0097 mouseArea.drag.maximumY = electricalComponent.parent.height - 0098 (electricalComponent.height + electricalComponent.paintedWidth)/2; 0099 } 0100 } 0101 0102 MouseArea { 0103 id: mouseArea 0104 width: parent.paintedWidth 0105 height: parent.paintedHeight 0106 anchors.centerIn: parent 0107 drag.target: electricalComponent 0108 onPressed: { 0109 Activity.updateToolTip(toolTipTxt); 0110 Activity.componentSelected(componentIndex); 0111 } 0112 onClicked: { 0113 if(Activity.toolDelete) { 0114 if (destructible) { 0115 Activity.removeComponent(componentIndex); 0116 } else { 0117 Activity.deselect(); 0118 } 0119 } else if(typeof isBroken !== "undefined") { 0120 // Repair broken bulb and LED on click 0121 if(isBroken && terminalConnected < noOfConnectionPoints) 0122 repairComponent(); 0123 } 0124 } 0125 onReleased: { 0126 parent.posX = parent.x / parent.parent.width; 0127 parent.posY = parent.y / parent.parent.height; 0128 Activity.updateToolTip(""); 0129 } 0130 0131 onPositionChanged: { 0132 updateDragConstraints(); 0133 Activity.updateWires(componentIndex); 0134 } 0135 } 0136 0137 Rectangle { 0138 id: componentLabel 0139 z: 100 0140 width: 80 * ApplicationInfo.ratio 0141 height: 40 * ApplicationInfo.ratio 0142 radius: height * 0.5 0143 anchors.horizontalCenter: parent.horizontalCenter 0144 anchors.top: parent.bottom 0145 color: "#80000000" 0146 visible: showLabel 0147 rotation: electricalComponent.rotation * -1 0148 GCText { 0149 anchors.centerIn: parent 0150 width: parent.width 0151 height: parent.height 0152 font.pointSize: NaN // need to clear font.pointSize explicitly 0153 fontSizeMode: Text.Fit 0154 minimumPixelSize: 10 0155 font.pixelSize: componentLabel.width * 0.2 0156 color: "white" 0157 text: labelText1 + "<br>" + labelText2 0158 verticalAlignment: Text.AlignVCenter 0159 horizontalAlignment: Text.AlignHCenter 0160 } 0161 } 0162 }