~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/wbitems.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * wbitems.h - the item classes for the SVG WB
 
3
 * Copyright (C) 2006  Joonas Govenius
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef WBITEMS_H
 
22
#define WBITEMS_H
 
23
#include <QDomElement>
 
24
#include <QHash>
 
25
#include <QGraphicsPathItem>
 
26
#include <QGraphicsScene>
 
27
#include <QGraphicsSceneMouseEvent>
 
28
#include <QMenu>
 
29
#include <QTextEdit>
 
30
#include <QPushButton>
 
31
#include <QSplitter>
 
32
#include <QHBoxLayout>
 
33
#include <QVBoxLayout>
 
34
#include <QColorDialog>
 
35
#include <QFontDialog>
 
36
#include <QPainter>
 
37
#include <QStyleOptionGraphicsItem>
 
38
#include <QtCrypto>
 
39
#include "iconaction.h"
 
40
#include <cmath>
 
41
 
 
42
/*! \brief A class used for storing an edit while it's being queued.*/
 
43
class Edit {
 
44
public:
 
45
        /*! \brief Describes which kind of edit item defines.*/
 
46
        enum Type {NewEdit, MoveEdit, RemoveEdit, AttributeEdit, ParentEdit, ContentEdit};
 
47
        /*! \brief Constructor
 
48
         *  Constructs an edit of \a type with \a xml.
 
49
         */
 
50
        Edit(Type type, const QDomElement &xml);
 
51
        /*! \brief Constructor
 
52
         *  Constructs an AttributeEdit or ParentEdit with the given oldValue and target.
 
53
         */
 
54
        Edit(Type type, const QString &target, const QDomElement &edit, const QString &oldValue);
 
55
        /*! \brief Constructor
 
56
         *  Constructs a ContentEdit with the given oldContent and target.
 
57
         */
 
58
        Edit(const QString &target, const QDomElement &edit, QDomNodeList oldContent);
 
59
        /*! \brief The type of edit.*/
 
60
        Type type;
 
61
        /*! \brief The XML element representing the edit.*/
 
62
        QDomElement xml;
 
63
        /*! \brief The target of the edit.
 
64
         *  Only applicable with AttributeEdit, ContentEdit and ParentEdit.
 
65
         */
 
66
        QString target;
 
67
        /*! \brief The attribute value before the edit.
 
68
         *  Only applicable with AttributeEdit
 
69
         */
 
70
        QString oldValue;
 
71
        /*! \brief The content before the edit.
 
72
         *  Only applicable with ContentEdit
 
73
         */
 
74
        QDomNodeList oldContent;
 
75
        /*! \brief The parent before the edit.
 
76
         *  Only applicable with ContentEdit
 
77
         */
 
78
        QString oldParent;
 
79
};
 
80
 
 
81
/*! \brief An undo structure to save a &lt;configure/&gt; undo item
 
82
 *  Stores the new version, the attribute name and the previous value.
 
83
 *  An instance of this class is created for each undo and stored in
 
84
 *  a list in the WbItem.
 
85
 *  \sa WbItem
 
86
 */
 
87
class EditUndo {
 
88
public:
 
89
        /*! \brief Constructor
 
90
         *  Constructs an EditUndo from the given version and Edit.
 
91
         */
 
92
        EditUndo(const int &version, const Edit &edit);
 
93
        /*! \brief Constructor
 
94
         *  Constructs an AttributeEdit undo with the given version, attribute and oldValue.
 
95
         */
 
96
        EditUndo(const int &version, const QString &attribute, const QString &oldValue);
 
97
        /*! \brief Constructor
 
98
         *  Constructs a ParentEdit undo with the given version and oldParent.
 
99
         */
 
100
        EditUndo(const int &version, const QString &oldParent);
 
101
        /*! \brief Constructor
 
102
         *  Constructs a ContentEdit undo with the given version and oldContent.
 
103
         */
 
104
        EditUndo(const int &version, QDomNodeList oldContent);
 
105
        /*! \brief The new version.*/
 
106
        int version;
 
107
        /*! \brief The type of undo.*/
 
108
        Edit::Type type;
 
109
        /*! \brief The changed attribute.*/
 
110
        QString attribute;
 
111
        /*! \brief The attribute value before the edit.*/
 
112
        QString oldValue;
 
113
        /*! \brief The content before the edit.*/
 
114
        QDomNodeList oldContent;
 
115
        /*! \brief The parent before the edit.*/
 
116
        QString oldParent;
 
117
};
 
118
 
 
119
/*! \brief The context menu for WbItems
 
120
 *  This menu pops up when as the context menu for WbItems and displays
 
121
 *  \sa WbItem
 
122
 */
 
123
class WbItemMenu : public QMenu {
 
124
        Q_OBJECT
 
125
public:
 
126
        /*! \brief Constructor
 
127
         *  Constructs a new empty menu.
 
128
         */
 
129
        WbItemMenu(QWidget* parent);
 
130
        /*! \brief Destructor
 
131
         *  Deletes all the actiongroups and their actions.
 
132
         */
 
133
        ~WbItemMenu();
 
134
        /*! \brief Add actiongroup to the menu.*/
 
135
        void addActionGroup(QActionGroup*);
 
136
 
 
137
private slots:
 
138
        /*! \brief Destruct self.*/
 
139
        void destructSelf();
 
140
 
 
141
private:
 
142
        /*! \brief The actiongroups that the menu shows.*/
 
143
        QList<QActionGroup*> groups_;
 
144
};
 
145
 
 
146
/*! \brief The base class for all whiteboard items.
 
147
 *  Every whiteboard item class must inherit this along with QGraphicsItem
 
148
 *  if the class is visualized on the scene. The derived class must implement at least
 
149
 *  type() and, if it's visualised, graphicsItem() and QGraphicsItem::mouseMoveEvent()
 
150
 *  and QGraphicsItem::mouseReleaseEvent() which should pass the events to 
 
151
 *  handleMouseMoveEvent() and handleMouseReleaseEvent() respectively.
 
152
 *
 
153
 *  This class stores all SVG attributes and provides parsing for the common
 
154
 *  attributes. Also provide support for the basic operations (translate,
 
155
 *  rotate and scale).
 
156
 *
 
157
 *  \sa WbPath
 
158
 */
 
159
class WbItem : public QObject {
 
160
        Q_OBJECT
 
161
 
 
162
public:
 
163
        /*! \brief Constructor
 
164
         *  Constructs a new item with values \a id and \a index.
 
165
         */
 
166
        WbItem(const QString &id);
 
167
 
 
168
        /*! \brief Return the ID of the parent item.*/
 
169
        QString parentWbItem();
 
170
        /*! \brief Set the parent.
 
171
         *  Used secondarily, if graphicsItem()->parentItem == 0
 
172
         */
 
173
        void setParentWbItem(const QString &, bool emitChanges = false);
 
174
        /*! \brief Return the ID of the item.*/
 
175
        QString id();
 
176
        /*! \brief Return the index of the item.*/
 
177
        qreal index();
 
178
        /*! \brief Set the index of the item.*/
 
179
        void setIndex(qreal index,  bool emitChanges = false);
 
180
        /*! \brief Construct a context menu with the default items.*/
 
181
        WbItemMenu* constructContextMenu();
 
182
        /*! \brief Set the 'stroke' attribute of the item.*/
 
183
        virtual void setStrokeColor(QColor color);
 
184
        /*! \brief Set the 'fill' attribute of the item.*/
 
185
        virtual void setFillColor(QColor color);
 
186
        /*! \brief Set the 'stroke-width' attribute of the item.*/
 
187
        virtual void setStrokeWidth(int width);
 
188
        /*! \brief Return the type of the item.*/
 
189
        virtual int type() const = 0;
 
190
        /*! \brief Return a pointer to the QGraphicsItem.*/
 
191
        virtual QGraphicsItem* graphicsItem() { return 0; };
 
192
        /*! \brief Return the item as an SVG element.*/
 
193
        virtual QDomElement svg();
 
194
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
195
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
196
        /*! \brief Regenerate and signal the SVG transformation matrix.*/
 
197
        virtual void regenerateTransform();
 
198
        /*! \brief Return the center of the item in item coordinates.*/
 
199
        virtual QPointF center();
 
200
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
201
        virtual WbItem* clone() = 0;
 
202
 
 
203
        /*! \brief The current version of the item.*/
 
204
        int version;
 
205
        /*! \brief A list of EditUndo objects that contain the history of the item.*/
 
206
        QList<EditUndo> undos;
 
207
 
 
208
        /* Parsing */
 
209
        // General
 
210
//      static QString xmlSimplify(const QString &str);
 
211
        static QList<qreal> parseNumbersList(QString::const_iterator &itr);
 
212
        static QList<qreal> parsePercentageList(QString::const_iterator &itr);
 
213
        inline static bool isUnreserved(const QChar &c, bool first_char = false);
 
214
        static QString idFromUrl(const QString &url);
 
215
        static QMatrix parseTransformationMatrix(const QString &value);
 
216
        static QColor resolveColor(const QString &colorStr);
 
217
        static QColor constructColor(const QString &colorStr, const QString &opacity);
 
218
        static qreal parseLength(const QString &str);
 
219
        static QPen parseQPen(QString stroke, const QString &dashArray, const QString &dashOffset, const QString &linecap, const QString &linejoin, const QString &miterlimit, QString strokeopacity, QString opacity, const QString &width);
 
220
//      static QPen defaultPen;
 
221
 
 
222
signals:
 
223
        /*! \brief Signals that an attribute of the element is changed.
 
224
         *  \param id The ID of this element.
 
225
         *  \param attribute The name of the changed attribute.
 
226
         *  \param value The new value of the attribute.
 
227
         *  \param oldvalue The old value of the attribute.
 
228
         */
 
229
        void attributeChanged(const QString &id, const QString &attribute, const QString &value, const QString &oldvalue);
 
230
        /*! \brief Emitted when the parent of the element is changed.*/
 
231
        void parentChanged(const QString &id, const QString &value, const QString &oldvalue);
 
232
        /*! \brief Emitted when the content of the element is changed.*/
 
233
        void contentChanged(const QString &id, const QDomNodeList &value, const QDomNodeList &oldvalue);
 
234
        /*! \brief Emitted when the index of the element is changed.*/
 
235
        void indexChanged(const QString &id, const qreal &deltaIndex);
 
236
 
 
237
protected:
 
238
        /*! \brief Implements the default item interaction behaviour.
 
239
         *  The action depends on the modifier keys being pressed:
 
240
         *  \li Ctrl: Translate
 
241
         *  \li Ctrl + Alt: Rotate
 
242
         *  \li Ctrl + Shift: Scale
 
243
         */
 
244
        void handleMouseMoveEvent(QGraphicsSceneMouseEvent * event);
 
245
        /*! \brief Implements the default item interaction behaviour.
 
246
         *  The action depends on the modifier keys being pressed:
 
247
         *  \li Ctrl: Translate
 
248
         *  \li Ctrl + Alt: Rotate
 
249
         *  \li Ctrl + Shift: Scale
 
250
         */
 
251
        void handleMouseReleaseEvent(QGraphicsSceneMouseEvent * event);
 
252
        /*! \brief Contains the SVG attributes of the element.*/
 
253
        QHash<QString, QString> attributes;
 
254
 
 
255
private:
 
256
        /*! \brief The ID of the item.*/
 
257
        QString id_;
 
258
        /*! \brief The parent of the item.*/
 
259
        QString parent_;
 
260
        /*! \brief The index of the item.*/
 
261
        qreal index_;
 
262
};
 
263
 
 
264
/*! \brief An item for storing the unkown SVG elements.
 
265
 *  Inherits WbItem.
 
266
 *
 
267
 *  The purpose of this item is to store the unkown element. It is not visualized.
 
268
 *  \sa WbItem
 
269
 */
 
270
class WbUnknown : public WbItem
 
271
{
 
272
public:
 
273
        /*! \brief Constructor
 
274
         *  Constructs a new root item.
 
275
         */
 
276
        WbUnknown(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
277
        /*! \brief Returns the type of the item (0x87654999).*/
 
278
        virtual int type() const { return 87654999; };
 
279
        /*! \brief Returns the stored SVG element.*/
 
280
        virtual QDomElement svg();
 
281
        /*! \brief Saves the SVG element.*/
 
282
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
283
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
284
        virtual WbItem* clone();
 
285
 
 
286
private:
 
287
        QDomElement svgElement_;
 
288
};
 
289
 
 
290
/*! \brief An item for storing the SVG root element.
 
291
 *  Inherits WbItem. 
 
292
 *
 
293
 *  The main function of the element is to store the root element's attributes.
 
294
 *  The item is not visualized on the scene.
 
295
 *  \sa WbItem
 
296
 */
 
297
class WbRoot : public WbItem
 
298
{
 
299
public:
 
300
        /*! \brief Constructor
 
301
         *  Constructs a new root item.
 
302
         */
 
303
        WbRoot(QGraphicsScene* scene);
 
304
        /*! \brief Returns the type of the item (0x87654000).*/
 
305
        virtual int type() const { return 87654000; };
 
306
        /*! \brief Saves the SVG element.*/
 
307
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
308
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
309
        virtual WbItem* clone();
 
310
private:
 
311
        QGraphicsScene* scene_;
 
312
};
 
313
 
 
314
/*! \brief An item for representing an SVG path element.
 
315
 *  Inherits QGraphicsPathItem and WbItem. 
 
316
 *
 
317
 *  Reimplements the methods dictated in WbItem's description.
 
318
 *
 
319
 *  Provides parsing for the 'd' and 'fill-rule' attributes.
 
320
 *  Also provides lineTo() and quadTo() methods (note that they don't
 
321
 *  emit an attributeChanged().)
 
322
 *
 
323
 *  \sa WbItem
 
324
 */
 
325
class WbPath : public QGraphicsPathItem, public WbItem
 
326
{
 
327
public:
 
328
        /*! \brief Constructor
 
329
         *  Constructs a new item with values \a id, \a index, \a parent and
 
330
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
331
         */
 
332
        WbPath(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
333
 
 
334
        /*! \brief Returns the type of the item (0x87654001).*/
 
335
        virtual int type() const { return 87654001; };
 
336
        /*! \brief Returns a corrected version of the shape.*/
 
337
        virtual QPainterPath shape() const;
 
338
        /*! \brief Returns a QGraphicsItem* to self.*/
 
339
        virtual QGraphicsItem* graphicsItem() { return this; };
 
340
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
341
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
342
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
343
        virtual WbItem* clone();
 
344
 
 
345
        /*! \brief Adds a line to to the end of the path.*/
 
346
        void lineTo(const QPointF &newPoint);
 
347
        /*! \brief Adds a quadratic bezier curve to the end of the path.*/
 
348
        void quadTo(const QPointF &controlPoint, const QPointF &newPoint);
 
349
 
 
350
        static bool parsePathDataFast(const QString &data, QPainterPath &path);
 
351
        static void pathArcSegment(QPainterPath &path, qreal xc, qreal yc, qreal th0, qreal th1, qreal rx, qreal ry, qreal xAxisRotation);
 
352
        static void pathArc(QPainterPath &path, qreal rx, qreal ry, qreal x_axis_rotation, int large_arc_flag, int sweep_flag, qreal x, qreal y, qreal curx, qreal cury);
 
353
 
 
354
protected:
 
355
        /*! \brief Constructs and popsup the default context menu.*/
 
356
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
357
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
358
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
359
         */
 
360
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
361
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
362
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
363
         */
 
364
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
365
};
 
366
 
 
367
/*! \brief An item for an SVG ellipse element.
 
368
 *  Inherits QGraphicsEllipseItem and WbItem. 
 
369
 *
 
370
 *  Reimplements the methods dictated in WbItem's description.
 
371
 *
 
372
 *  Provides parsing for the 'rx' and 'ry' attributes.
 
373
 *
 
374
 *  \sa WbItem
 
375
 */
 
376
class WbEllipse : public QGraphicsEllipseItem, public WbItem {
 
377
public:
 
378
        /*! \brief Constructor
 
379
         *  Constructs a new item with values \a id, \a index, \a parent and
 
380
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
381
         */
 
382
        WbEllipse(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
383
 
 
384
        /*! \brief Returns the type of the item (0x87654002).*/
 
385
        virtual int type() const { return 87654002; };
 
386
        /*! \brief Returns a QGraphicsItem* to self.*/
 
387
        virtual QGraphicsItem* graphicsItem() { return this; };
 
388
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
389
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
390
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
391
        virtual WbItem* clone();
 
392
 
 
393
protected:
 
394
        /*! \brief Constructs and popsup the default context menu.*/
 
395
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
396
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
397
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
398
         */
 
399
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
400
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
401
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
402
         */
 
403
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
404
};
 
405
 
 
406
/*! \brief An item for an SVG circle element.
 
407
 *  Inherits WbEllipse.
 
408
 *
 
409
 *  Provides parsing for the r attribute.
 
410
 *
 
411
 *  \sa WbItem
 
412
 */
 
413
class WbCircle : public WbEllipse {
 
414
public:
 
415
        /*! \brief Constructor
 
416
         *  Constructs a new item with values \a id, \a index, \a parent and
 
417
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
418
         */
 
419
        WbCircle(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
420
 
 
421
        /*! \brief Returns the type of the item (0x87654003).*/
 
422
        virtual int type() const { return 87654003; };
 
423
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
424
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
425
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
426
        virtual WbItem* clone();
 
427
};
 
428
 
 
429
/*! \brief An item for an SVG rectangle element.
 
430
 *  Inherits QGraphicsRectItem and WbItem. 
 
431
 *
 
432
 *  Reimplements the methods dictated in WbItem's description.
 
433
 *
 
434
 *  Provides parsing for the 'width' and 'height' attributes.
 
435
 *
 
436
 *  \sa WbItem
 
437
 */
 
438
class WbRectangle : public QGraphicsRectItem, public WbItem {
 
439
public:
 
440
        /*! \brief Constructor
 
441
         *  Constructs a new item with values \a id, \a index, \a parent and
 
442
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
443
         */
 
444
        WbRectangle(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
445
 
 
446
        /*! \brief Returns the type of the item (0x87654002).*/
 
447
        virtual int type() const { return 87654004; };
 
448
        /*! \brief Returns a QGraphicsItem* to self.*/
 
449
        virtual QGraphicsItem* graphicsItem() { return this; };
 
450
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
451
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
452
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
453
        virtual WbItem* clone();
 
454
 
 
455
protected:
 
456
        /*! \brief Constructs and popsup the default context menu.*/
 
457
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
458
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
459
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
460
         */
 
461
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
462
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
463
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
464
         */
 
465
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
466
};
 
467
 
 
468
/*! \brief An item for representing an SVG line element.
 
469
 *  Inherits QGraphicsPathItem and WbItem. 
 
470
 *
 
471
 *  Reimplements the methods dictated in WbItem's description.
 
472
 *
 
473
 *  Provides parsing for the 'x1', 'y1', 'x2', 'y2' attributes.
 
474
 *
 
475
 *  \sa WbItem
 
476
 */
 
477
class WbLine : public QGraphicsPathItem, public WbItem
 
478
{
 
479
public:
 
480
        /*! \brief Constructor
 
481
         *  Constructs a new item with values \a id, \a index, \a parent and
 
482
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
483
         */
 
484
        WbLine(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
485
 
 
486
        /*! \brief Returns the type of the item (0x87654005).*/
 
487
        virtual int type() const { return 87654005; };
 
488
        /*! \brief Returns a corrected version of the shape.*/
 
489
        virtual QPainterPath shape() const;
 
490
        /*! \brief Returns a QGraphicsItem* to self.*/
 
491
        virtual QGraphicsItem* graphicsItem() { return this; };
 
492
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
493
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
494
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
495
        virtual WbItem* clone();
 
496
 
 
497
protected:
 
498
        /*! \brief Constructs and popsup the default context menu.*/
 
499
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
500
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
501
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
502
         */
 
503
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
504
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
505
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
506
         */
 
507
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
508
};
 
509
 
 
510
/*! \brief An item for representing an SVG polyline element.
 
511
 *  Inherits QGraphicsPathItem and WbItem. 
 
512
 *
 
513
 *  Reimplements the methods dictated in WbItem's description.
 
514
 *
 
515
 *  Provides parsing for the 'points' attribute.
 
516
 *
 
517
 *  \sa WbItem
 
518
 */
 
519
class WbPolyline : public QGraphicsPathItem, public WbItem
 
520
{
 
521
public:
 
522
        /*! \brief Constructor
 
523
         *  Constructs a new item with values \a id, \a index, \a parent and
 
524
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
525
         */
 
526
        WbPolyline(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
527
 
 
528
        /*! \brief Returns the type of the item (0x87654006).*/
 
529
        virtual int type() const { return 87654006; };
 
530
        /*! \brief Returns a corrected version of the shape.*/
 
531
        virtual QPainterPath shape() const;
 
532
        /*! \brief Returns a QGraphicsItem* to self.*/
 
533
        virtual QGraphicsItem* graphicsItem() { return this; };
 
534
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
535
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
536
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
537
        virtual WbItem* clone();
 
538
 
 
539
protected:
 
540
        /*! \brief Constructs and popsup the default context menu.*/
 
541
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
542
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
543
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
544
         */
 
545
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
546
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
547
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
548
         */
 
549
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
550
};
 
551
 
 
552
/*! \brief An item for an SVG circle element.
 
553
 *  Inherits WbEllipse.
 
554
 *
 
555
 *  Provides parsing for the r attribute.
 
556
 *
 
557
 *  \sa WbItem
 
558
 */
 
559
class WbPolygon : public WbPolyline {
 
560
public:
 
561
        /*! \brief Constructor
 
562
         *  Constructs a new item with values \a id, \a index, \a parent and
 
563
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
564
         */
 
565
        WbPolygon(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
566
 
 
567
        /*! \brief Returns the type of the item (0x87654007).*/
 
568
        virtual int type() const { return 87654007; };
 
569
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
570
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
571
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
572
        virtual WbItem* clone();
 
573
};
 
574
 
 
575
class WbText;
 
576
 
 
577
/*! \brief The visualized part of WbText.
 
578
 *  This class provides the QGraphicsItem for the WbText because multiple inheritance doesn't work
 
579
 *  when both WbItem and and QGraphicsTextItem inherit from QObject.
 
580
 *
 
581
 *  \sa WbItem
 
582
 */
 
583
class WbGraphicsTextItem : public QGraphicsTextItem  {
 
584
public:
 
585
        /*! \brief Constructor
 
586
         *  Constructs a new visualized item for \a wbtext on \a scene.
 
587
         */
 
588
        WbGraphicsTextItem(WbText* wbtext, QGraphicsScene* scene = 0);
 
589
 
 
590
protected:
 
591
        /*! \brief Constructs and popsup the context menu.*/
 
592
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
593
        /*! \brief Causes the text to be checked for changes.*/
 
594
        virtual void focusOutEvent (QFocusEvent *);
 
595
        /*! \brief Makes the text editable.*/
 
596
        virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
 
597
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
598
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
599
         */
 
600
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
601
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
602
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
603
         */
 
604
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
605
 
 
606
private:
 
607
        /*! \brief A pointer to the "parent" WbItem.*/
 
608
        WbText* wbText_;
 
609
};
 
610
 
 
611
/*! \brief An item for an SVG text element.
 
612
 *  Inherits WbItem and implements WbGraphicsTextItem as a friend class.
 
613
 *
 
614
 *  Reimplements the methods dictated in WbItem's description.
 
615
 *
 
616
 *  Provides parsing for the text content of the text element.
 
617
 *
 
618
 *  \sa WbItem
 
619
 */
 
620
class WbText : public WbItem  {
 
621
        Q_OBJECT
 
622
        friend class WbGraphicsTextItem;
 
623
public:
 
624
        /*! \brief Constructor
 
625
         *  Constructs a new item with values \a id, \a index, \a parent and
 
626
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
627
         */
 
628
        WbText(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
629
        /*! \brief Destructor*/
 
630
        virtual ~WbText();
 
631
 
 
632
        /*! \brief Returns the type of the item (0x87654101).*/
 
633
        virtual int type() const { return 87654101; };
 
634
        /*! \brief Returns a QGraphicsItem* to self.*/
 
635
        virtual QGraphicsItem* graphicsItem() { return graphicsitem_; };
 
636
        /*! \brief Return the item as an SVG element.*/
 
637
        virtual QDomElement svg();
 
638
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
639
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
640
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
641
        virtual WbItem* clone();
 
642
        /*! \brief Checks if the text has changed and emits a signal accordingly.*/
 
643
        void checkTextChanges();
 
644
 
 
645
public slots:
 
646
        /*! \brief Popsup a font dialog and sets the selected font.*/
 
647
        void setFont();
 
648
 
 
649
private:
 
650
        /*! \brief The character data content of the element.*/
 
651
        QString text_;
 
652
        WbGraphicsTextItem* graphicsitem_;
 
653
};
 
654
 
 
655
/*! \brief An item for representing an SVG image element.
 
656
 *  Inherits QGraphicsPixmapItem and WbItem. 
 
657
 *
 
658
 *  Reimplements the methods dictated in WbItem's description.
 
659
 *
 
660
 *  Provides parsing for the 'points' attribute.
 
661
 *
 
662
 *  \sa WbItem
 
663
 */
 
664
class WbImage : public QGraphicsPixmapItem, public WbItem
 
665
{
 
666
public:
 
667
        /*! \brief Constructor
 
668
         *  Constructs a new item with values \a id, \a index, \a parent and
 
669
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
670
         */
 
671
        WbImage(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
672
 
 
673
        /*! \brief Returns the type of the item (0x87654102).*/
 
674
        virtual int type() const { return 87654102; };
 
675
        /*! \brief Returns a QGraphicsItem* to self.*/
 
676
        virtual QGraphicsItem* graphicsItem() { return this; };
 
677
        /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
 
678
        virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
 
679
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
680
        virtual WbItem* clone();
 
681
 
 
682
protected:
 
683
        /*! \brief Constructs and popsup the default context menu.*/
 
684
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
685
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
686
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
687
         */
 
688
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
689
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
690
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
691
         */
 
692
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
693
};
 
694
 
 
695
/*! \brief An item for representing an SVG group element.
 
696
 *  Inherits QGraphicsGroupItem and WbItem. 
 
697
 *
 
698
 *  Reimplements the methods dictated in WbItem's description.
 
699
 *
 
700
 *  Note that calling svg() of this class won't return the child elements
 
701
 *
 
702
 *  \sa WbItem
 
703
 */
 
704
class WbGroup : public QGraphicsItem, public WbItem
 
705
{
 
706
public:
 
707
        /*! \brief Constructor
 
708
         *  Constructs a new item with values \a id, \a index, \a parent and
 
709
         *  \a scene with other attributes parsed from the SVG element \a svg.
 
710
         */
 
711
        WbGroup(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
 
712
 
 
713
        /*! \brief Returns the type of the item (0x87654201).*/
 
714
        virtual int type() const { return 87654201; };
 
715
        /*! \brief Returns a QGraphicsItem* to self.*/
 
716
        virtual QGraphicsItem* graphicsItem() { return this; };
 
717
        /*! \brief Returns a deep copy of this object but without a scene association.*/
 
718
        virtual WbItem* clone();
 
719
 
 
720
        /*! \brief Paints the bounding rect if selected.*/
 
721
        virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
 
722
        /*! \brief Returns the bounding rectangle containing all group member items.*/
 
723
        virtual QRectF boundingRect() const;
 
724
 
 
725
protected:
 
726
        /*! \brief Updates the bounding rectangle when children are added or removed.*/
 
727
        virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
 
728
 
 
729
        /*! \brief Constructs and popsup the default context menu.*/
 
730
        virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
 
731
        /*! \brief Passes the event to WbItem::handleMousMoveEvent.
 
732
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
733
         */
 
734
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 
735
        /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
 
736
         *  The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
 
737
         */
 
738
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 
739
 
 
740
private:
 
741
        void addToBoundingRect(const QRectF &itemRect);
 
742
        QRectF boundingRect_;
 
743
};
 
744
 
 
745
#endif