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

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