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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* 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 UBGRAPHICSITEMDELEGATE_H_
#define UBGRAPHICSITEMDELEGATE_H_
#define UB_FREE_CONTROL(Object, Scene) \
if (Object) { \
if (Scene) { \
Scene->removeItem(Object); \
} \
Object->deleteLater(); \
Object = 0; \
} \
#include <QtGui>
#include <QtSvg>
#include <QMimeData>
#include <QGraphicsVideoItem>
#include "core/UB.h"
#include "core/UBSettings.h"
class QGraphicsSceneMouseEvent;
class QGraphicsItem;
class UBGraphicsScene;
class UBGraphicsProxyWidget;
class UBGraphicsDelegateFrame;
class UBGraphicsWidgetItem;
class UBGraphicsMediaItem;
class DelegateButton: public QGraphicsSvgItem
{
Q_OBJECT
public:
DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0, Qt::WindowFrameSection section = Qt::TopLeftSection);
virtual ~DelegateButton();
enum { Type = UBGraphicsItemType::DelegateButtonType };
virtual int type() const { return Type; }
void setTransparentToMouseEvent(bool tr)
{
mIsTransparentToMouseEvent = tr;
}
void setFileName(const QString & fileName);
void setShowProgressIndicator(bool pShow) {mShowProgressIndicator = pShow;}
bool testShowProgresIndicator() const {return mShowProgressIndicator;}
void setSection(Qt::WindowFrameSection section) {mButtonAlignmentSection = section;}
Qt::WindowFrameSection getSection() const {return mButtonAlignmentSection;}
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void timerEvent(QTimerEvent *event);
void modified();
private slots:
void startShowProgress();
private:
QGraphicsItem* mDelegated;
QTime mPressedTime;
bool mIsTransparentToMouseEvent;
bool mIsPressed;
int mProgressTimerId;
int mPressProgres;
bool mShowProgressIndicator;
Qt::WindowFrameSection mButtonAlignmentSection;
signals:
void clicked (bool checked = false);
void longClicked();
};
/*
Code of this class is copied from QT QLCDNumber class sources
See src\gui\widgets\qlcdnumber.cpp for original code
*/
class MediaTimer: public QGraphicsRectItem
{
public:
MediaTimer(QGraphicsItem * parent = 0);
~MediaTimer();
void positionHandles();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void display(const QString &str);
void setNumDigits(int nDigits);
private:
static const char* getSegments(char);
void drawString(const QString& s, QPainter &, QBitArray * = 0, bool = true);
void drawDigit(const QPoint &, QPainter &, int, char, char = ' ');
void drawSegment(const QPoint &, char, QPainter &, int, bool = false);
void addPoint(QPolygon&, const QPoint&);
void internalSetString(const QString& s);
static char segments [][8];
int ndigits;
QString digitStr;
QBitArray points;
double val;
uint shadow : 1;
uint smallPoint : 1;
int digitSpace;
int xSegLen;
int ySegLen;
int segLen;
int xAdvance;
int xOffset;
int yOffset;
};
class DelegateMediaControl: public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
DelegateMediaControl(UBGraphicsMediaItem* pDelegated, QGraphicsItem * parent = 0);
virtual ~DelegateMediaControl()
{
// NOOP
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
QPainterPath shape() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void update();
void positionHandles();
void updateTicker(qint64 time);
void totalTimeChanged(qint64 newTotalTime);
signals:
void used();
protected:
void seekToMousePos(QPointF mousePos);
UBGraphicsMediaItem* mDelegate;
bool mDisplayCurrentTime;
qint64 mCurrentTimeInMs;
qint64 mTotalTimeInMs;
private:
int mStartWidth;
int mSeecAreaBorderHeight;
QRectF mSeecArea;
QRectF mLCDTimerArea;
MediaTimer *lcdTimer;
QString mDisplayFormat;
};
class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject
{
public:
UBGraphicsToolBarItem(QGraphicsItem * parent = 0);
virtual ~UBGraphicsToolBarItem() {;}
bool isVisibleOnBoard() const { return mVisible; }
void setVisibleOnBoard(bool visible) { mVisible = visible; }
bool isShifting() const { return mShifting; }
void setShifting(bool shifting) { mShifting = shifting; }
QList<QGraphicsItem*> itemsOnToolBar() const { return mItemsOnToolBar; }
void setItemsOnToolBar(QList<QGraphicsItem*> itemsOnToolBar) { mItemsOnToolBar = itemsOnToolBar;}
int minWidth() { return mMinWidth; }
void positionHandles();
void update();
int getElementsPadding(){return mElementsPadding;}
private:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
bool mShifting;
bool mVisible;
int mMinWidth;
int mInitialHeight;
int mElementsPadding;
QList<QGraphicsItem*> mItemsOnToolBar;
};
class UBGraphicsItemDelegate : public QObject
{
Q_OBJECT
public:
UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0, UBGraphicsFlags fls = 0);
virtual ~UBGraphicsItemDelegate();
virtual void createControls();
virtual void freeControls();
virtual void showControls();
virtual bool controlsExist() const;
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual bool wheelEvent(QGraphicsSceneWheelEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual bool keyPressEvent(QKeyEvent *event);
virtual bool keyReleaseEvent(QKeyEvent *event);
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change,
const QVariant &value);
virtual UBGraphicsScene *castUBGraphicsScene();
virtual void postpaint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void printMessage(const QString &mess) {qDebug() << mess;}
QGraphicsItem* delegated();
virtual void positionHandles();
void setZOrderButtonsVisible(bool visible);
void startUndoStep();
void commitUndoStep();
UBGraphicsDelegateFrame* frame() {return mFrame;}
bool isLocked() const;
QMimeData* mimeData(){ return mMimeData; }
void setMimeData(QMimeData* mimeData);
void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;}
void setLocked(bool pLocked);
void setButtonsVisible(bool visible);
UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; }
qreal antiScaleRatio() const { return mAntiScaleRatio; }
virtual void update() {positionHandles();}
UBGraphicsFlags ubflags() const {return mFlags;}
bool testUBFlags(UBGraphicsFlags pf) const {return mFlags & pf;}
void setUBFlags(UBGraphicsFlags pf);
void setUBFlag(UBGraphicsFlags pf, bool set = true);
virtual void showToolBar(bool autohide = true) {Q_UNUSED(autohide);}
signals:
void showOnDisplayChanged(bool shown);
void lockChanged(bool locked);
public slots:
virtual void remove(bool canUndo = true);
void showMenu();
virtual void showHide(bool show);
virtual void lock(bool lock);
virtual void duplicate();
void increaseZLevelUp();
void increaseZLevelDown();
void increaseZlevelTop();
void increaseZlevelBottom();
void onZoomChanged();
protected:
virtual void buildButtons();
virtual void freeButtons();
virtual void decorateMenu(QMenu *menu);
virtual void updateMenuActionState();
void showHideRecurs(const QVariant &pShow, QGraphicsItem *pItem);
QList<DelegateButton*> buttons() {return mButtons;}
QGraphicsItem* mDelegated;
//buttons from the top left section of delegate frame
DelegateButton* mDeleteButton;
DelegateButton* mDuplicateButton;
DelegateButton* mMenuButton;
//buttons from the bottom left section of delegate frame
DelegateButton *mZOrderUpButton;
DelegateButton *mZOrderDownButton;
QMenu* mMenu;
QAction* mLockAction;
QAction* mShowOnDisplayAction;
QAction* mGotoContentSourceAction;
UBGraphicsDelegateFrame* mFrame;
qreal mFrameWidth;
qreal mAntiScaleRatio;
QList<DelegateButton*> mButtons;
QList<DelegateButton*> mToolBarButtons;
UBGraphicsToolBarItem* mToolBarItem;
protected slots:
virtual void gotoContentSource();
private:
void updateFrame();
void updateButtons(bool showUpdated = false);
QPointF mOffset;
QTransform mPreviousTransform;
QPointF mPreviousPosition;
QPointF mDragStartPosition;
qreal mPreviousZValue;
QSizeF mPreviousSize;
QMimeData* mMimeData;
QPixmap mDragPixmap;
bool mMoved;
UBGraphicsFlags mFlags;
};
#endif /* UBGRAPHICSITEMDELEGATE_H_ */