Changeset View
Changeset View
Standalone View
Standalone View
src/activities/analog_electricity/DragListItem.qml
- This file was added.
1 | /* GCompris - DragListItem.qml | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright (C) 2019 Deepak Kumar <deepakdk2431@gmail.com> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or modify | ||||
6 | * it under the terms of the GNU General Public License as published by | ||||
7 | * the Free Software Foundation; either version 3 of the License, or | ||||
8 | * (at your option) any later version. | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License | ||||
16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | ||||
17 | */ | ||||
18 | import QtQuick 2.6 | ||||
19 | import GCompris 1.0 | ||||
20 | import "analog_electricity.js" as Activity | ||||
21 | | ||||
22 | Item { | ||||
23 | id: item | ||||
24 | | ||||
25 | width: tile.width | ||||
26 | height: tile.height | ||||
27 | | ||||
28 | property string source: componentSrc | ||||
29 | property string imageName: imgName | ||||
30 | property string toolTipTxt: toolTipText | ||||
31 | property double imageWidth: imgWidth | ||||
32 | property double imageHeight: imgHeight | ||||
33 | property double heightInColumn | ||||
34 | property double widthInColumn | ||||
35 | property double tileWidth | ||||
36 | property double tileHeight | ||||
37 | property bool selected: false | ||||
38 | | ||||
39 | signal pressed | ||||
40 | | ||||
41 | Rectangle { | ||||
42 | id: tile | ||||
43 | width: tileWidth | ||||
44 | height: tileHeight | ||||
45 | color: (parent.selected && tileImage.parent == tile) ? "#33FF294D" : "transparent" | ||||
46 | border.color: (parent.selected && tileImage.parent == tile) ? "white" : "transparent" | ||||
47 | border.width: 3 | ||||
48 | radius: 2 | ||||
49 | | ||||
50 | property double xCenter: tile.x + tile.width / 2 | ||||
51 | property double yCenter: tile.y + tile.height / 2 | ||||
52 | property bool selected: false | ||||
53 | | ||||
54 | Image { | ||||
55 | anchors.centerIn: parent | ||||
56 | width: widthInColumn | ||||
57 | height: heightInColumn | ||||
58 | fillMode: Image.PreserveAspectFit | ||||
59 | source: Activity.url + imgName | ||||
60 | } | ||||
61 | | ||||
62 | Image { | ||||
63 | id: tileImage | ||||
64 | anchors.centerIn: parent | ||||
65 | width: smallWidth | ||||
66 | height: smallHeight | ||||
67 | fillMode: Image.PreserveAspectFit | ||||
68 | source: Activity.url + imgName | ||||
69 | mipmap: true | ||||
70 | antialiasing: true | ||||
71 | | ||||
72 | property double smallWidth: widthInColumn | ||||
73 | property double smallHeight: heightInColumn | ||||
74 | property double fullWidth: imgWidth * playArea.width | ||||
75 | property double fullHeight: imgHeight * playArea.height | ||||
76 | property QtObject tileImageParent | ||||
77 | property bool small: true | ||||
78 | | ||||
79 | function toSmall() { | ||||
80 | width = smallWidth | ||||
81 | height = smallHeight | ||||
82 | small = true | ||||
83 | } | ||||
84 | | ||||
85 | function toFull() { | ||||
86 | width = fullWidth * Activity.currentZoom | ||||
87 | height = fullHeight * Activity.currentZoom | ||||
88 | small = false | ||||
89 | } | ||||
90 | | ||||
91 | MultiPointTouchArea { | ||||
92 | id: mouseArea | ||||
93 | touchPoints: [ TouchPoint { id: point1 } ] | ||||
94 | property real startX | ||||
95 | property real startY | ||||
96 | property bool pressedOnce | ||||
97 | | ||||
98 | anchors.fill: parent | ||||
99 | | ||||
100 | onPressed: { | ||||
101 | tileImage.anchors.centerIn = undefined | ||||
102 | startX = point1.x | ||||
103 | startY = point1.y | ||||
104 | tileImage.toFull() | ||||
105 | toolTip.show(toolTipText) | ||||
106 | pressedOnce = true | ||||
107 | item.selected = true | ||||
108 | } | ||||
109 | | ||||
110 | onUpdated: { | ||||
111 | var moveX = point1.x - startX | ||||
112 | var moveY = point1.y - startY | ||||
113 | parent.x = parent.x + moveX | ||||
114 | parent.y = parent.y + moveY | ||||
115 | } | ||||
116 | | ||||
117 | onReleased: { | ||||
118 | if (pressedOnce) { | ||||
119 | pressedOnce = false | ||||
120 | item.selected = false | ||||
121 | var coord = playArea.mapFromItem(tileImage.parent, parent.x, parent.y) | ||||
122 | if(coord.x > 0 && ((playArea.width/Activity.currentZoom) - coord.x > tileImage.fullWidth)) | ||||
123 | Activity.createComponent(coord.x, coord.y, index) | ||||
124 | tileImage.anchors.centerIn = tile | ||||
125 | tileImage.toSmall() | ||||
126 | toolTip.show("") | ||||
127 | } | ||||
128 | } | ||||
129 | } | ||||
130 | } | ||||
131 | } | ||||
132 | } |