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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBWIDGETAPI_H
#define UBWIDGETAPI_H
#include <QtCore>
#include <QGraphicsSceneDragDropEvent>
#include "UBW3CWidgetAPI.h"
#include "core/UBDownloadManager.h"
class UBGraphicsScene;
class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem;
class UBWidgetMessageAPI;
class UBDatastoreAPI;
class UBDocumentDatastoreAPI;
class UBWidgetUniboardAPI : public QObject
{
Q_OBJECT
/**
* The number of pages in the current document
*/
Q_PROPERTY(int pageCount READ pageCount SCRIPTABLE true)
/**
* The page number of the current page
*/
Q_PROPERTY(int currentPageNumber READ currentPageNumber SCRIPTABLE true)
/**
* instance UUID, return a unique identifier for the widget, this value is guaranted to be unique
* and constant for a widget, deprecated, use window.widget.uuid instead
*/
Q_PROPERTY(QString uuid READ uuid SCRIPTABLE true)
/**
* Returns the language and eventually the country of this locale as a string of the form
* "language-country" or only "language" if the country is unknown,
* where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase,
* two-letter ISO 3166 country code.
*
* some potential values are
*
* en
* en-UK
* fr
* fr-CH
* fr-FR
*
*/
Q_PROPERTY(QString lang READ lang SCRIPTABLE true)
Q_PROPERTY(QObject* messages READ messages SCRIPTABLE true)
Q_PROPERTY(QObject* datastore READ datastore SCRIPTABLE true)
public:
UBWidgetUniboardAPI(UBGraphicsScene *pScene, UBGraphicsWidgetItem *widget = 0);
~UBWidgetUniboardAPI();
QObject* messages();
QObject* datastore();
public slots:
void setScene(UBGraphicsScene* pScene)
{
mScene = pScene;
}
// global
/**
* Set the tool (pen, marker, arrow, line)
*/
void setTool(const QString& toolString);
/**
* an HTML color (red, blue, ...) or rgb (#FF0000) or a default Uniboard color (1, 2, 3, 4)
*/
void setPenColor(const QString& penColor);
/**
* an HTML color (red, blue, ...) or rgba (#FF000077) or a default Uniboard color (1, 2, 3, 4)
*/
void setMarkerColor(const QString& penColor);
/**
* return the url of the thumbnail of a page
*/
QString pageThumbnail(const int pageNumber);
//view based
/**
* Zoom the current view port centered on scene position x/y
*/
void zoom(const qreal factor, const qreal x, const qreal y);
/**
* move the view port of x/y pixels
*/
void move(const qreal x, const qreal y);
//scene based
/**
* move the control to position x/y in scene coordinate
*/
void moveTo(const qreal x, const qreal y);
/**
* draw a line from current pos to x/y in scene coordinate
*/
void drawLineTo(const qreal x, const qreal y, const qreal pWidth);
/**
* erase any line from current pos to x/y in scene coordinate
*/
void eraseLineTo(const qreal x, const qreal y, const qreal pWidth);
/**
* remove all drawing/object from current scene
*/
void clear();
/**
* set the scene backgroung to black/white with crossing or not
*/
void setBackground(bool pIsDark, bool pIsCrossed);
/**
* add any supported objects (pictures/video/widget) centered at scene position x/y.
* width and height may be supplied, this is useful for flash (.swf) objects
* if background is true, the object is not selectable and sits in the lowest z pos possible
*
*/
void addObject(QString pUrl, int width = 0, int height = 0, int x = 0, int y = 0, bool background = false);
/**
* The widget notify the container to resized to width/height in scene (DOM) coordintates
*/
void resize(qreal width, qreal height);
// widget based
/**
* Returns the language and eventually the country of this locale as a string of the form
* "language_country" or only "language" if the country is unknown,
* where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase,
* two-letter ISO 3166 country code.
*
* some potential values are
*
* en
* en_UK
* fr
* fr_CH
* fr_FR
*
* deprecated as it does not folow xml normas, replaced by property 'lang'
*
*/
QString locale();
/**
* Save a preference for this widget instance
*/
void setPreference(const QString& key, QString value);
/**
* retreive widget instance preference
*/
QString preference(const QString& key, const QString& pDefault = QString());
/**
* retreive a list of widget instance preferences
*/
QStringList preferenceKeys();
/**
* Display a message on the top bottom corner of the board
*/
void showMessage(const QString& message);
/**
* Center the scene coordinates within the display port
*
*/
void centerOn(const qreal x, const qreal y);
/**
* Write some text on the board
*/
void addText(const QString& text, const qreal x, const qreal y, const int height = -1, const QString& font = ""
, bool bold = false, bool italic = false);
void returnStatus(const QString& method, const QString& status);
void usedMethods(QStringList methods);
void response(bool correct);
/**
* Give the file metadata to Sankore. The format must be
* <metbadata>
* <key>File Size</<key>
* <value>1024</value>
* </metadata>
*/
void sendFileMetadata(QString metaData);
// widget download
/**
* If the widget support a the drop of an object it will notify sankore about this.
*/
void enableDropOnWidget (bool enable = true);
/**
* When an object is dropped on a widget, this one send us the informations to download it locally.
* this method download the object on the widget directory and return the path of the downloaded object
*/
void ProcessDropEvent(QGraphicsSceneDragDropEvent *);
bool isDropableData(const QMimeData *pMimeData) const;
private slots:
void onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData);
private:
inline void registerIDWidget(int id){webDownloadIds.append(id);}
inline bool takeIDWidget(int id);
private:
QString uuid();
QString lang();
int pageCount();
int currentPageNumber();
QString getObjDir();
QString createMimeText(bool downloaded, const QString &mimeType, const QString &fileName);
bool supportedTypeHeader(const QString &) const;
QString boolToStr(bool value) const {return value ? "true" : "false";}
UBGraphicsScene* mScene;
UBGraphicsWidgetItem* mGraphicsWidget;
bool mIsVisible;
UBWidgetMessageAPI* mMessagesAPI;
UBDatastoreAPI* mDatastoreAPI;
QList<int> webDownloadIds;
};
class UBDatastoreAPI : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* document READ document SCRIPTABLE true)
public:
UBDatastoreAPI(UBGraphicsW3CWidgetItem *widget);
virtual ~UBDatastoreAPI(){;}
QObject* document();
private:
UBDocumentDatastoreAPI* mDocumentDatastore;
};
class UBDocumentDatastoreAPI : public UBW3CWebStorage
{
Q_OBJECT
public:
UBDocumentDatastoreAPI(UBGraphicsW3CWidgetItem *graphicsWidget);
virtual ~UBDocumentDatastoreAPI();
public slots:
virtual QString key(int index);
virtual QString getItem(const QString& key);
virtual void setItem(const QString& key, const QString& value);
virtual void removeItem(const QString& key);
virtual void clear();
protected:
virtual int length();
private:
UBGraphicsW3CWidgetItem* mGraphicsW3CWidget;
};
#endif // UBWIDGETAPI_H