-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileList.cpp
315 lines (244 loc) · 7.01 KB
/
FileList.cpp
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
* File: FileList.cpp
* Author: scribble
*
* Created on February 11, 2013, 4:07 AM
*/
#include "FileList.h"
#include "ScreenInterpreter.h"
#include "Sender.h"
FileList::FileList() {
}
FileList::FileList(const FileList& orig) {
}
FileList::~FileList() {
for (uint i = 0; i < buttonArray->size(); i++) {
delete buttonArray->at(i);
}
buttonArray->clear();
delete buttonArray;
for (uint i = 0; i < fileTable->size(); i++) {
delete fileTable->at(i);
}
fileTable->clear();
delete fileTable;
}
FileList::FileList(int x_, int y_, int w_, int h_) {
start = 0;
size = 0;
numberOfPages = 0;
page = 0;
x = x_;
y = y_;
width = w_;
height = h_;
std::string fileName = "FileListBG.png";
imagePath = fileName.insert(0, IMAGE_PATH);
buttonArray = new std::vector<FileListButton *>;
fileTable = new std::vector<FileListCell *>;
for (int i = 0; i < 2; ++i) {
int type;
int action;
int btnx;
int btny;
int btnw;
int btnh;
std::string buttonImage;
switch (i) {
case 0:
type = MOMENTARY;
action = NEXT_PAGE_FL;
buttonImage = "NextPage.png";
btnx = 604;
btny = 688;
btnw = 40;
btnh = 40;
break;
case 1:
type = MOMENTARY;
action = PREVIOUS_PAGE_FL;
buttonImage = "PreviousPage.png";
btnx = 559;
btny = 688;
btnw = 40;
btnh = 40;
break;
case 2:
type = MOMENTARY;
action = NEW_DOCUMENT_FL;
buttonImage = "AddDocument.png";
btnx = 604;
btny = 9;
btnw = 40;
btnh = 40;
break;
default:
type = MOMENTARY;
action = NULL;
buttonImage = "";
btnx = 0;
btny = 0;
btnw = 0;
btnh = 0;
break;
}
FileListButton *btn = new FileListButton(btnx + x, btny + y, btnw, btnh, type, action, NULL, NULL, NULL, NULL, buttonImage.insert(0, IMAGE_PATH));
buttonArray->push_back(btn);
}
}
int FileList::getX() {
return x;
}
int FileList::getY() {
return y;
}
int FileList::getWidth() {
return width;
}
int FileList::getHeight() {
return height;
}
std::string FileList::getImagePath() {
return imagePath;
}
/*! Screen Press Event
*
* \param *point A pointer to a Point object
*
* This function initializes the lastPoint and enables scribbling in Write mode, or tries to delete a path on which the point passes through in Erase mode
*/
void FileList::screenPressEvent(Point* point) {
//if point is NULL return, nothing to do
if (point == NULL) {
return;
}
for (int i = 0; i < buttonArray->size(); ++i) {
if (buttonArray->at(i)->pointInsideArea(point) == 1) {
switch (buttonArray->at(i)->getMode()) {
case MOMENTARY:
callAction(buttonArray->at(i)->getAction());
break;
case TOGGLE:
callAction(buttonArray->at(i)->getAction());
break;
case PICKER:
break;
default:
break;
}
}
}
for (int i = 0; i < fileTable->size(); ++i) {
if (fileTable->at(i)->pointInsideArea(point) == 1) {
screenInterpreter->showLoading(1);
screenInterpreter->getScribbleArea()->getSender()->sendDownloadFile(fileTable->at(i)->getFileName());
while (screenInterpreter->getScribbleArea()->getNetworkActivity() == ScribbleArea::NetworkActivity::WAITING_FOR_FILE_DOWNLOAD);
screenInterpreter->getMenu()->setPageIndicator();
screenInterpreter->showLoading(0);
screenInterpreter->showFilelist(0);
}
}
delete point;
point = NULL;
}
/*! Screen Move Event
*
* \param *point A pointer to a Point object
*
* This function draws a line between a last point and the new point in Write mode or tries to delete a path on which the point passes through in Erase mode
*/
void FileList::screenMoveEvent(Point* point) {
}
/*! Screen Release Event
*
* This function disables scribbling and informs the ScribbleArea that nothing is touching the screen anymore
*/
void FileList::screenReleaseEvent(/*Points *point*/) {
}
void FileList::callAction(int action) {
switch (action) {
case NEW_DOCUMENT_FL:
std::cout << "new_document" << std::endl;
break;
case NEXT_PAGE_FL:
if (page < numberOfPages - 1) {
page += 1;
start = page * 10;
if (page + 1 == numberOfPages) {
size = fileList.size() % 10;
} else {
size = 10;
}
createTable();
}
break;
case PREVIOUS_PAGE_FL:
if (page > 0) {
page -= 1;
start = page * 10;
if (page + 1 == numberOfPages) {
size = fileList.size() % 10;
} else {
size = 10;
}
createTable();
}
break;
default:
break;
}
}
void FileList::setScreenInterpreter(ScreenInterpreter *s) {
screenInterpreter = s;
}
std::vector <FileListButton *> * FileList::getButtonArray() {
return buttonArray;
}
std::vector <std::string> FileList::getFileList() {
return fileList;
}
void FileList::setFileList(std::vector <std::string> fl) {
fileList = fl;
if (fileList.size() % 10 == 0) {
numberOfPages = (fileList.size() / 10);
}
else {
numberOfPages = (fileList.size() / 10) + 1;
}
std::cout << fileList.size();
if (fileList.size() <= 10) {
size = fileList.size();
} else {
size = 10;
}
createTable();
}
std::vector <FileListCell *> *FileList::getFileListTable() {
return fileTable;
}
void FileList::createTable() {
int type = MOMENTARY;
int action = SELECTED_CELL_C;
int btnx = 0;
int btny = 60;
int btnw = 656;
int btnh = 62;
for (uint i = 0; i < fileTable->size(); i++) {
delete fileTable->at(i);
}
fileTable->clear();
for (uint i = 0; i < size; ++i) {
FileListCell *cell = new FileListCell(btnx + x, btny * (i + 1) + 2 * i + y, btnw, btnh, type, action, NULL, NULL, NULL, NULL, fileList.at(start + i), start + i);
fileTable->push_back(cell);
}
}
std::string FileList::getNumberOfPages() {
std::stringstream ss;
ss << numberOfPages;
return ss.str();
}
std::string FileList::getCurrentPage() {
std::stringstream ss;
ss << page + 1;
return ss.str();
}