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

0001 /* GCompris - Zone.qml
0002  *
0003  * SPDX-FileCopyrightText: 2016 Divyam Madaan <divyam3897@gmail.com>
0004  *
0005  * Authors:
0006  *   Divyam Madaan <divyam3897@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 import "../../core"
0014 import "categorization.js" as Activity
0015 
0016 Flow {
0017     id: zoneFlow
0018     width: parent.width/3
0019     height: parent.height
0020     property alias repeater: repeater
0021     property alias model: zoneModel
0022 
0023     ListModel {
0024         id: zoneModel
0025     }
0026 
0027     Repeater {
0028         id: repeater
0029         model: zoneModel
0030         Item {
0031             id: item
0032             width: itemWidth
0033             height: itemWidth
0034             opacity: 1
0035             Image {
0036                 id: image
0037                 fillMode: Image.PreserveAspectFit
0038                 sourceSize.width: itemWidth
0039                 width: sourceSize.width
0040                 height: sourceSize.width
0041                 source: name
0042                 MultiPointTouchArea {
0043                     id: dragArea
0044                     anchors.fill: parent
0045                     touchPoints: [ TouchPoint { id: point1 } ]
0046                     property real positionX
0047                     property real positionY
0048                     property real lastX
0049                     property real lastY
0050                     property bool isRight: isRight
0051                     property string currPosition: "middle"
0052                     property string imageSource: image.source.toString()
0053 
0054                     onPressed: {
0055                         items.instructionsVisible = false
0056                         positionX = point1.x
0057                         positionY = point1.y
0058                         var imagePos = image.mapToItem(null,0,0)
0059                         if(Activity.isDragInLeftArea(leftScreen.width, imagePos.x + parent.width)) {
0060                             currPosition = "left"
0061                         }
0062                         else if(Activity.isDragInRightArea(middleScreen.width + leftScreen.width,imagePos.x)) {
0063                             currPosition = "right"
0064                         }
0065                         else
0066                             currPosition = "middle"
0067                     }
0068 
0069                     onUpdated: {
0070                         var moveX = point1.x - positionX
0071                         var moveY = point1.y - positionY
0072                         parent.x = parent.x + moveX
0073                         parent.y = parent.y + moveY
0074                         var imagePos = image.mapToItem(null,0,0)
0075                         leftAreaContainsDrag = Activity.isDragInLeftArea(leftScreen.width, imagePos.x + parent.width)
0076                         rightAreaContainsDrag = Activity.isDragInRightArea(middleScreen.width + leftScreen.width,imagePos.x)
0077                         lastX = 0, lastY = 0
0078                     }
0079 
0080                     onReleased: {
0081                         var droppedPosition = "middle";
0082                         if(lastX == point1.x && lastY == point1.y)
0083                             return;
0084                         else if(leftAreaContainsDrag)
0085                             droppedPosition = "left"
0086                         else if(rightAreaContainsDrag)
0087                             droppedPosition = "right"
0088 
0089                         Activity.setValues()
0090 
0091                         // If we drop on same zone, we move it at its initial place
0092                         if(currPosition == droppedPosition) {
0093                             image.x = 0
0094                             image.y = 0
0095                         }
0096                         else {
0097                             Activity.dropControl(currPosition, droppedPosition, imageSource, index)
0098                             image.source = ""
0099                         }
0100 
0101                         lastX = point1.x
0102                         lastY = point1.y
0103                     }
0104                 }
0105             }
0106         }
0107     }
0108 }
0109