Warning, /education/gcompris/src/activities/adjacent_numbers/DraggableTile.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - DraggableTile.qml 0002 * 0003 * SPDX-FileCopyrightText: 2023 Alexandre Laurent <littlewhite.dev@gmail.com> 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 import QtQuick 2.12 0007 import QtQml.Models 2.12 0008 0009 import GCompris 1.0 0010 import "../../core" 0011 0012 /** 0013 * Could use guesscount/DragTile? 0014 */ 0015 MouseArea { 0016 id: draggableMouseArea 0017 width: 1 0018 height: width 0019 0020 property bool dropActive: true 0021 property int onGoingAnimationCount: 0 0022 0023 // For storing the initial position when dragged 0024 property point beginDragPosition 0025 property MouseArea originalParent 0026 property bool mouseHeld: false 0027 0028 // anchors.fill: parent 0029 0030 drag.target: dragableElement 0031 enabled: (!onGoingAnimationCount) && items.buttonsEnabled 0032 0033 onPressed: { 0034 z = 100 0035 draggableMouseArea.beginDragPosition = Qt.point(dragableElement.x, dragableElement.y) 0036 mouseHeld = true 0037 // Activity.targetColorReset() 0038 } 0039 onReleased: { 0040 z = 0 0041 dragableElement.Drag.drop() 0042 mouseHeld = false 0043 dragableElement.parent = draggableMouseArea 0044 0045 // The element may die on drop if removed, check if it exists 0046 if(dragableElement) { 0047 dragableElement.x = beginDragPosition.x 0048 dragableElement.y = beginDragPosition.y 0049 } 0050 } 0051 0052 Rectangle { 0053 id: dragableElement 0054 width: parent.width 0055 height: parent.height 0056 color: "white" 0057 opacity: 1 0058 radius: height * 0.1 0059 0060 Drag.keys: "" 0061 Drag.active: draggableMouseArea.drag.active 0062 Drag.hotSpot.x: width/2 0063 Drag.hotSpot.y: height/2 0064 0065 property string valueText: dragableValueText.text 0066 0067 GCText { 0068 id: dragableValueText 0069 text: value 0070 anchors.centerIn: parent 0071 height: parent.height * 0.6 0072 width: parent.width * 0.6 0073 fontSizeMode: Text.Fit 0074 fontSize: largeSize 0075 verticalAlignment: Text.AlignVCenter 0076 horizontalAlignment: Text.AlignHCenter 0077 } 0078 } 0079 }