-
Notifications
You must be signed in to change notification settings - Fork 0
/
CanvasItem.js
179 lines (103 loc) · 2.53 KB
/
CanvasItem.js
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* @author rafael
*/
function CanvasItem(X,Y,W,H,color,track,scene,view) {
CanvasItem.superclass.call(this, X,Y,W,H); //call superclass constructor
this.itemColor = color;
var defaultColor = color;
var pen = new QPen(new QColor(61,61,61,180));
var pen2 = new QPen(new QColor(150,200,240));
pen2.setWidth(5);
var self = this;
var menu = null;
var selectionCircle;
var isSelected = false;
var brush = new QBrush(this.itemColor);
var scaleFactor = 0.9;
this.clickedMe = false;
pen.setWidth(1);
this.setPen(pen);
this.setBrush(brush);
this.track = track;
this.X = X;
this.Y = Y;
this.W = W;
this.H = H;
var scene = scene;
var view = view;
this.setAcceptHoverEvents(true);
this.infoRect = null;
this.getTrack = function(){
return this.track;
}
this.setPosition = function(x,y){
this.setPos(x,y);
this.X = x;
this.Y = y;
}
this.invertSelection = function(){
this.setSelected(!this.isSelected);
}
this.setClickedMe = function(flag){
this.clickedMe = flag;
}
this.getW = function(){
return this.W;
}
this.getH = function(){
return this.H;
}
this.getX = function(){
return this.X;
}
this.getY = function(){
return this.Y;
}
this.getScene = function(){
return scene;
}
this.getView = function(){
return view;
}
this.hoverEnterEvent = function(event){
if(!this.infoRect){
this.infoRect = new InfoRect(parseInt(this.X+W),parseInt(this.Y-W),300,120,this);
}
this.infoRect.draw();
this.setColor(new QColor(150,200,240));
msg(this.ItemIsSelectable);
}
this.mousePressEvent = function(event){
this.clickedMe = true;
// parent.inverseSelect(this);
msg("clicou na bola");
}
this.hoverLeaveEvent = function(event){
if (!this.clickedMe) {
this.infoRect.remove();
}
this.setColor(defaultColor);
}
this.setColor = function(color){
this.itemColor = color;
brush.setColor(this.itemColor);
this.setBrush(brush);
}
this.setSelected = function(flag){
if(flag){
this.isSelected = true;
selectionCircle = new QGraphicsEllipseItem(this.X-1,this.Y-1,this.W+1,this.H+1);
selectionCircle.setPen(pen2);
selectionCircle.setZValue(2);
scene.addItem(selectionCircle);
}
else{
this.isSelected = false;
if(selectionCircle){
scene.removeItem(selectionCircle);
selectionCircle = null;
}
}
}
}
extend(CanvasItem, QGraphicsEllipseItem);