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
/*
* Copyright (C) 2013 Open Education Foundation
*
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
* l'Education Numérique en Afrique (GIP ENA)
*
* This file is part of OpenBoard.
*
* OpenBoard 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, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard 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 OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGRAPHICSWIDGETITEM_H
#define UBGRAPHICSWIDGETITEM_H
#include <QtGui>
#include <QtWebKit>
#include <QDomElement>
#include "core/UB.h"
#include "UBItem.h"
#include "UBResizableGraphicsItem.h"
class UBWidgetUniboardAPI;
class UBGraphicsScene;
class UBW3CWidgetAPI;
class UBW3CWidgetWebStorageAPI;
class UBGraphiscItem;
class UBGraphiscItemDelegate;
struct UBWidgetType
{
enum Enum
{
W3C = 0, Apple, Other
};
};
class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBResizableGraphicsItem, public UBGraphicsItem
{
Q_OBJECT
public:
UBGraphicsWidgetItem(const QUrl &pWidgetUrl = QUrl(), QGraphicsItem *parent = 0);
~UBGraphicsWidgetItem();
enum { Type = UBGraphicsItemType::GraphicsWidgetItemType };
virtual int type() const { return Type; }
virtual void initialize();
virtual void resize(qreal w, qreal h);
virtual void resize(const QSizeF & size);
virtual QSizeF size() const;
QUrl mainHtml();
void loadMainHtml();
QUrl widgetUrl();
void widgetUrl(QUrl url) { mWidgetUrl = url; }
QString mainHtmlFileName();
bool canBeContent();
bool canBeTool();
QString preference(const QString& key) const;
void setPreference(const QString& key, QString value);
QMap<QString, QString> preferences() const;
void removePreference(const QString& key);
void removeAllPreferences();
QString datastoreEntry(const QString& key) const;
void setDatastoreEntry(const QString& key, QString value);
QMap<QString, QString> datastoreEntries() const;
void removeDatastoreEntry(const QString& key);
void removeAllDatastoreEntries();
void removeScript();
void processDropEvent(QGraphicsSceneDragDropEvent *event);
bool isDropableData(const QMimeData *data) const;
virtual QUrl getOwnFolder() const;
virtual void setOwnFolder(const QUrl &newFolder);
virtual void setSnapshotPath(const QUrl &newFilePath);
virtual QUrl getSnapshotPath();
virtual void clearSource();
virtual void setUuid(const QUuid &pUuid);
QSize nominalSize() const;
bool hasLoadedSuccessfully() const;
bool freezable();
bool resizable();
bool isFrozen();
QPixmap snapshot();
void setSnapshot(const QPixmap& pix);
QPixmap takeSnapshot();
virtual UBItem* deepCopy() const = 0;
virtual UBGraphicsScene* scene();
static int widgetType(const QUrl& pUrl);
static QString widgetName(const QUrl& pUrl);
static QString iconFilePath(const QUrl& pUrl);
public slots:
void freeze();
void unFreeze();
protected:
enum OSType
{
type_NONE = 0, // 0000
type_WIN = 1, // 0001
type_MAC = 2, // 0010
type_UNIX = 4, // 0100
type_ALL = 7 // 0111
};
bool mFirstReleaseAfterMove;
bool mInitialLoadDone;
bool mIsFreezable;
bool mIsResizable;
bool mLoadIsErronous;
bool mMouseIsPressed;
int mCanBeContent;
int mCanBeTool;
QSize mNominalSize;
QString mMainHtmlFileName;
QUrl mMainHtmlUrl;
QUrl mWidgetUrl;
QMap<QString, QString> mDatastore;
QMap<QString, QString> mPreferences;
virtual bool event(QEvent *event);
virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void sendJSEnterEvent();
virtual void sendJSLeaveEvent();
virtual void injectInlineJavaScript();
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
protected slots:
void geometryChangeRequested(const QRect& geom);
virtual void javaScriptWindowObjectCleared();
void mainFrameLoadFinished(bool ok);
private slots:
void onLinkClicked(const QUrl& url);
void initialLayoutCompleted();
private:
bool mIsFrozen;
bool mIsTakingSnapshot;
bool mShouldMoveWidget;
UBWidgetUniboardAPI* mUniboardAPI;
QPixmap mSnapshot;
QPointF mLastMousePos;
QUrl ownFolder;
QUrl SnapshotFile;
static bool sInlineJavaScriptLoaded;
static QStringList sInlineJavaScripts;
};
class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
{
Q_OBJECT
public:
UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsAppleWidgetItem();
virtual void copyItemParameters(UBItem *copy) const;
virtual void setUuid(const QUuid &pUuid);
virtual UBItem* deepCopy() const;
};
class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
{
Q_OBJECT
public:
class PreferenceValue
{
public:
PreferenceValue()
{
/* NOOP */
}
PreferenceValue(const QString& pValue, bool pReadonly)
{
value = pValue;
readonly = pReadonly;
}
bool readonly;
QString value;
};
class Metadata
{
public:
QString id;
QString name;
QString description;
QString author;
QString authorEmail;
QString authorHref;
QString version;
};
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsW3CWidgetItem();
virtual void setUuid(const QUuid &pUuid);
virtual UBItem* deepCopy() const;
virtual void copyItemParameters(UBItem *copy) const;
QMap<QString, PreferenceValue> preferences();
Metadata metadatas() const;
static QString freezedWidgetFilePath();
static QString createNPAPIWrapper(const QString& url, const QString& pMimeType = QString(), const QSize& sizeHint = QSize(300, 150), const QString& pName = QString());
static QString createNPAPIWrapperInDir(const QString& url, const QDir& pDir, const QString& pMimeType = QString(), const QSize& sizeHint = QSize(300, 150), const QString& pName = QString());
static QString createHtmlWrapperInDir(const QString& html, const QDir& pDir, const QSize& sizeHint, const QString& pName);
static QString freezedWidgetPage();
static bool hasNPAPIWrapper(const QString& pMimeType);
Metadata mMetadatas;
private slots:
virtual void javaScriptWindowObjectCleared();
private:
static void loadNPAPIWrappersTemplates();
static QString textForSubElementByLocale(QDomElement rootElement, QString subTagName, QLocale locale);
UBW3CWidgetAPI* mW3CWidgetAPI;
QMap<QString, PreferenceValue> mPreferences;
static bool sTemplateLoaded;
static QString sNPAPIWrappperConfigTemplate;
static QMap<QString, QString> sNPAPIWrapperTemplates;
};
#endif // UBGRAPHICSWIDGETITEM_H