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

0001 /* gcompris - DragListItem.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 import "analog_electricity.js" as Activity
0015 
0016 Item {
0017     id: item
0018 
0019     width: tile.width
0020     height: tile.height
0021 
0022     property string source: componentSrc
0023     property string imageName: imgName
0024     property string toolTipTxt: toolTipText
0025     property double imageWidth: imgWidth
0026     property double imageHeight: imgHeight
0027     property double heightInColumn
0028     property double widthInColumn
0029     property double tileWidth
0030     property double tileHeight
0031     property bool selected: false
0032 
0033     signal pressed
0034 
0035     Rectangle {
0036         id: tile
0037         width: tileWidth
0038         height: tileHeight
0039         color: (parent.selected && tileImage.parent == tile) ? "#33FF294D" : "transparent"
0040         border.color: (parent.selected && tileImage.parent == tile) ? "white" : "transparent"
0041         border.width: 3
0042         radius: 2
0043 
0044         property double xCenter: tile.x + tile.width / 2
0045         property double yCenter: tile.y + tile.height / 2
0046         property bool selected: false
0047 
0048         Image {
0049             anchors.centerIn: parent
0050             sourceSize.width: widthInColumn
0051             sourceSize.height: heightInColumn
0052             width: widthInColumn
0053             height: heightInColumn
0054             fillMode: Image.PreserveAspectFit
0055             mipmap: true
0056             antialiasing: true
0057             source: Activity.url + imgName
0058         }
0059 
0060         Image {
0061             id: tileImage
0062             anchors.centerIn: parent
0063             sourceSize.width: fullWidth * 0.5
0064             sourceSize.height: fullHeight * 0.5
0065             width: widthInColumn
0066             height: heightInColumn
0067             fillMode: Image.PreserveAspectFit
0068             source: Activity.url + imgName
0069             mipmap: true
0070             antialiasing: true
0071             opacity: 0
0072 
0073             property double fullWidth: imgWidth * playArea.sizeMultiplier
0074             property double fullHeight: imgHeight * playArea.sizeMultiplier
0075             property QtObject tileImageParent
0076 
0077             function toSmall() {
0078                 item.z = 1;
0079                 opacity = 0;
0080                 width = widthInColumn;
0081                 height = heightInColumn;
0082             }
0083 
0084             function toFull() {
0085                 item.z = 100;
0086                 width = fullWidth * Activity.currentZoom;
0087                 height = fullHeight * Activity.currentZoom;
0088                 opacity = 1;
0089             }
0090 
0091             MultiPointTouchArea {
0092                 id: mouseArea
0093                 touchPoints: [ TouchPoint { id: point1 } ]
0094                 property real startX
0095                 property real startY
0096                 property bool pressedOnce
0097 
0098                 anchors.fill: parent
0099 
0100                 onPressed: {
0101                     tileImage.anchors.centerIn = undefined;
0102                     tileImage.toFull();
0103                     startX = point1.x;
0104                     startY = point1.y;
0105                     toolTip.show(toolTipText);
0106                     pressedOnce = true;
0107                     item.selected = true;
0108                     Activity.disableToolDelete();
0109                 }
0110 
0111                 onUpdated: {
0112                     var moveX = point1.x - startX;
0113                     var moveY = point1.y - startY;
0114                     parent.x = parent.x + moveX;
0115                     parent.y = parent.y + moveY;
0116                 }
0117 
0118                 onReleased: {
0119                     if (pressedOnce) {
0120                         pressedOnce = false;
0121                         item.selected = false;
0122                         var coord = playArea.mapFromItem(tileImage.parent, parent.x, parent.y);
0123                         if(coord.x > 0 && coord.y > 0 && ((playArea.width/Activity.currentZoom) - coord.x > tileImage.fullWidth))
0124                             Activity.createComponent(coord.x, coord.y, index);
0125                         tileImage.anchors.centerIn = tile;
0126                         tileImage.toSmall();
0127                         toolTip.show("");
0128                     }
0129                 }
0130             }
0131         }
0132     }
0133 }