-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfoRect.js
208 lines (108 loc) · 3.26 KB
/
InfoRect.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* @author rafael
*/
function InfoRect(x,y,w,h,parent){
var self = this;
var X = x;
var Y = y;
var bolaW = parent.getW();
var bolaH = parent.getH();
var track = parent.getTrack();
var sceneRef = parent.getScene();
var viewRef = parent.getView();
var canvasWidth = viewRef.width;
var canvasHeight = viewRef.height;
var textTitle = track.getTitle();
var textArtist = track.getArtist();
var textAlbum = track.getAlbumName();
if(textTitle.length > 9){
textTitle = cropString(textTitle,19);
}
if(textArtist.length > 17){
textArtist = cropString(textArtist,10);
}
if(textAlbum.length > 17){
textAlbum = cropString(textAlbum,10);
}
if(x + w > canvasWidth){
msg("flip");
X = x - (bolaW + w);
}
else if(x < 0){
msg("flip");
X = bolaW ;
}
if(y + h > canvasHeight){
msg("flip");
Y = y -((y+h) - canvasHeight);
}
else if(y < 0){
msg("flip");
Y = bolaH ;
}
var rect = new QGraphicsRectItem(new QRectF(X,Y,w,h));
var fontBrush = new QBrush(new QColor(200,200,200,200));
var brush = new QBrush(new QColor(56,56,56,150));
var pen = new QPen(new QColor(87,87,87,200));
pen.setWidth(2);
var font = new QFont("Verdana",10,QFont.Bold);
var font2 = new QFont("Verdana",9,QFont.Bold);
rect.setBrush(brush);
rect.setPen(pen);
rect.setZValue(7);
rect.setAcceptHoverEvents(true);
if (!track.getVisualData()) {
track.newVisualData();
var image = track.getVisualData().setAlbumImageItem(track.getAlbumImagePath(),100);
var trackTitle = track.getVisualData().setTitleTextItem(textTitle);
var trackArtist = track.getVisualData().setArtistTextItem(textArtist);
var trackAlbum = track.getVisualData().setAlbumTextItem(textAlbum);
}
var image = track.getVisualData().getAlbumImageItem();
var trackTitle = track.getVisualData().getTitleTextItem();
var trackArtist = track.getVisualData().getArtistTextItem();
var trackAlbum = track.getVisualData().getAlbumTextItem();
image.setPos(X+10,Y+10);
image.setZValue(8);
trackTitle.setFont(font);
trackTitle.setBrush(fontBrush);
trackTitle.setPos(X+120,Y+40);
trackTitle.setZValue(8);
trackArtist.setFont(font2);
trackArtist.setBrush(fontBrush);
trackArtist.setPos(X+120,Y+60);
trackArtist.setZValue(8);
trackAlbum.setFont(font2);
trackAlbum.setBrush(fontBrush);
trackAlbum.setPos(X+120,Y+80);
trackAlbum.setZValue(8);
trackTitle.mousePressEvent = function(){
addTrack(track.getID());
stMsg("Música " +track.getTitle()+" foi adicionada à Playlist");
}
image.mousePressEvent = function(){
addAlbum(track.getAlbumID());
stMsg("Album "+track.getAlbumName()+" foi adicionado à Playlist");
}
trackArtist.mousePressEvent = function(){
addArtist(track.getArtistID());
}
rect.hoverLeaveEvent = function(event){
self.remove();
parent.setClickedMe(false);
}
this.draw = function(){
sceneRef.addItem(rect);
sceneRef.addItem(image);
sceneRef.addItem(trackTitle)
sceneRef.addItem(trackArtist);
sceneRef.addItem(trackAlbum);
}
this.remove = function(){
sceneRef.removeItem(rect);
sceneRef.removeItem(image);
sceneRef.removeItem(trackTitle);
sceneRef.removeItem(trackArtist);
sceneRef.removeItem(trackAlbum);
}
}