-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDragItem.qml
155 lines (144 loc) · 3.56 KB
/
DragItem.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import QtQuick 2.14
import QtQuick.Controls 1.4
Item {
id: item
anchors.fill: parent
property color objColor: "red"
property string name: ""
property int index: 0
property var snappedPoi: null
property bool currentItem: false
property var snap: snapPoint
property var indexes: null
property var action: "undefined"
property var target: "undefined"
property var targetDisplay: "undefined"
property bool done: false
property bool doneSim: false
opacity: 1
z:10
visible: true
Item{
id: snapPoint
x:0
y:0
Rectangle{
id: snapRect
color: objColor
width: 20
height: width
radius: width/2
x:-width/2
y:-height/2
opacity: 1
}
onXChanged: {
timerTarget.start()
}
}
Rectangle{
x:snapPoint.x-width/2
y:snapPoint.y-height/2
z:30
width: 8*snapRect.width
height: 8*snapRect.height
color: "transparent"
rotation: -displayView.rotation
Label{
id: actionDisplay
text:action+" "+targetDisplay
font.bold: true
font.pixelSize: 40
style: Text.Outline
styleColor: "black"
color: "white"
}
}
Timer{
id:timerTarget
interval: 100
onTriggered: {
if(snappedPoi !== null){
target = snappedPoi.name
}
else{
target = getPoints()
}
}
}
function snapTo(x,y){
snapPoint.x=x
snapPoint.y=y
}
Component.onDestruction: {
pubCommand("remove;"+name+":"+parseInt(index))
indexes.splice(indexes.indexOf(index), 1);
timerUpdateActions.restart()
}
Component.onCompleted: {
objColor = figures.colors[index]
currentItem = true
}
function selected(val){
currentItem = val
}
function setIndex(val){
index = val
currentItem = false
currentItem = true
timerUpdateActions.restart()
}
function setIndexes(val){
indexes = val
}
onTargetChanged: {
if (name === "surface")
targetDisplay = figures.colorNames[index]+" Area"
else
targetDisplay = target.replace("_"," ")
gamePlan.update()
}
onCurrentItemChanged: {
if(currentItem){
objColor = Qt.lighter(objColor,1.3)
if(figures.currentItem !== null && figures.currentItem !== item)
figures.currentItem.selected(false)
figures.currentItem = item
paint()
}
else{
objColor = figures.colors[index]
paint()
}
}
function getAction(){
var a ={}
a.name = item.action
a.target = item.target
a.targetDisplay = item.targetDisplay
a.order = item.index
a.color = item.objColor
a.done = done || doneSim
a.img1 = "none_"
a.img2 = a.name
if(a.target.includes(','))
a.img3 = "unknown_ "
else
a.img3 = a.target
return [a]
}
function testDone(act, t){
if(action === act && target === t){
if(globalStates.state === "simulation")
doneSim = true
else
done = true
}
return false
}
function testDelete(){
return done || currentItem
}
function poiUpdated(){
}
}