make zooming more smooth (zooming on background)
[makneto-zunavac1.git] / src / ui-kde / wbitems.h
blob7246fdc592f7a2c20a69678a4cc7e1dbee7c6174
1 /*
2 * wbitems.h - the item classes for the SVG WB
3 * Copyright (C) 2006 Joonas Govenius
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.
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.
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
21 #ifndef WBITEMS_H
22 #define WBITEMS_H
23 #include <QDomDocument>
24 #include <QDomElement>
25 #include <QHash>
26 #include <QGraphicsPathItem>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneMouseEvent>
29 #include <QMenu>
30 #include <QTextEdit>
31 #include <QPushButton>
32 #include <QSplitter>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
35 #include <QColorDialog>
36 #include <QFontDialog>
37 #include <QPainter>
38 #include <QStyleOptionGraphicsItem>
39 #include <QtCrypto>
40 //#include "iconaction.h"
41 #include <cmath>
43 /*! \brief A class used for storing an edit while it's being queued.*/
44 class Edit {
45 public:
46 /*! \brief Describes which kind of edit item defines.*/
47 enum Type {NewEdit, MoveEdit, RemoveEdit, AttributeEdit, ParentEdit, ContentEdit};
48 /*! \brief Constructor
49 * Constructs an edit of \a type with \a xml.
51 Edit(Type type, const QDomElement &xml);
52 /*! \brief Constructor
53 * Constructs an AttributeEdit or ParentEdit with the given oldValue and target.
55 Edit(Type type, const QString &target, const QDomElement &edit, const QString &oldValue);
56 /*! \brief Constructor
57 * Constructs a ContentEdit with the given oldContent and target.
59 Edit(const QString &target, const QDomElement &edit, QDomNodeList oldContent);
60 /*! \brief The type of edit.*/
61 Type type;
62 /*! \brief The XML element representing the edit.*/
63 QDomElement xml;
64 /*! \brief The target of the edit.
65 * Only applicable with AttributeEdit, ContentEdit and ParentEdit.
67 QString target;
68 /*! \brief The attribute value before the edit.
69 * Only applicable with AttributeEdit
71 QString oldValue;
72 /*! \brief The content before the edit.
73 * Only applicable with ContentEdit
75 QDomNodeList oldContent;
76 /*! \brief The parent before the edit.
77 * Only applicable with ContentEdit
79 QString oldParent;
82 /*! \brief An undo structure to save a &lt;configure/&gt; undo item
83 * Stores the new version, the attribute name and the previous value.
84 * An instance of this class is created for each undo and stored in
85 * a list in the WbItem.
86 * \sa WbItem
88 class EditUndo {
89 public:
90 /*! \brief Constructor
91 * Constructs an EditUndo from the given version and Edit.
93 EditUndo(const int &version, const Edit &edit);
94 /*! \brief Constructor
95 * Constructs an AttributeEdit undo with the given version, attribute and oldValue.
97 EditUndo(const int &version, const QString &attribute, const QString &oldValue);
98 /*! \brief Constructor
99 * Constructs a ParentEdit undo with the given version and oldParent.
101 EditUndo(const int &version, const QString &oldParent);
102 /*! \brief Constructor
103 * Constructs a ContentEdit undo with the given version and oldContent.
105 EditUndo(const int &version, QDomNodeList oldContent);
107 /*! \brief The new version.*/
108 int version;
109 /*! \brief The type of undo.*/
110 Edit::Type type;
111 /*! \brief The changed attribute.*/
112 QString attribute;
113 /*! \brief The attribute value before the edit.*/
114 QString oldValue;
115 /*! \brief The content before the edit.*/
116 QDomNodeList oldContent;
117 /*! \brief The parent before the edit.*/
118 QString oldParent;
121 /*! \brief The context menu for WbItems
122 * This menu pops up when as the context menu for WbItems and displays
123 * \sa WbItem
125 class WbItemMenu : public QMenu {
126 Q_OBJECT
127 public:
128 /*! \brief Constructor
129 * Constructs a new empty menu.
131 WbItemMenu(QWidget* parent);
132 /*! \brief Destructor
133 * Deletes all the actiongroups and their actions.
135 ~WbItemMenu();
136 /*! \brief Add actiongroup to the menu.*/
137 void addActionGroup(QActionGroup*);
139 private slots:
140 /*! \brief Destruct self.*/
141 void destructSelf();
143 private:
144 /*! \brief The actiongroups that the menu shows.*/
145 QList<QActionGroup*> groups_;
148 /*! \brief The base class for all whiteboard items.
149 * Every whiteboard item class must inherit this along with QGraphicsItem
150 * if the class is visualized on the scene. The derived class must implement at least
151 * type() and, if it's visualised, graphicsItem() and QGraphicsItem::mouseMoveEvent()
152 * and QGraphicsItem::mouseReleaseEvent() which should pass the events to
153 * handleMouseMoveEvent() and handleMouseReleaseEvent() respectively.
155 * This class stores all SVG attributes and provides parsing for the common
156 * attributes. Also provide support for the basic operations (translate,
157 * rotate and scale).
159 * \sa WbPath
161 class WbItem : public QObject {
162 Q_OBJECT
164 public:
165 /*! \brief Constructor
166 * Constructs a new item with values \a id and \a index.
168 WbItem(const QString &id);
170 /*! \brief Return the ID of the parent item.*/
171 QString parentWbItem();
172 /*! \brief Set the parent.
173 * Used secondarily, if graphicsItem()->parentItem == 0
175 void setParentWbItem(const QString &, bool emitChanges = false);
176 /*! \brief Return the ID of the item.*/
177 QString id();
178 /*! \brief Return the index of the item.*/
179 qreal index();
180 /*! \brief Set the index of the item.*/
181 void setIndex(qreal index, bool emitChanges = false);
182 /*! \brief Construct a context menu with the default items.*/
183 WbItemMenu* constructContextMenu();
184 /*! \brief Set the 'stroke' attribute of the item.*/
185 virtual void setStrokeColor(QColor color);
186 /*! \brief Set the 'fill' attribute of the item.*/
187 virtual void setFillColor(QColor color);
188 /*! \brief Set the 'stroke-width' attribute of the item.*/
189 virtual void setStrokeWidth(int width);
190 /*! \brief Return the type of the item.*/
191 virtual int type() const = 0;
192 /*! \brief Return a pointer to the QGraphicsItem.*/
193 virtual QGraphicsItem* graphicsItem() { return 0; };
194 /*! \brief Return the item as an SVG element.*/
195 virtual QDomElement svg();
196 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
197 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
198 /*! \brief Regenerate and signal the SVG transformation matrix.*/
199 virtual void regenerateTransform();
200 /*! \brief Return the center of the item in item coordinates.*/
201 virtual QPointF center();
202 /*! \brief Returns a deep copy of this object but without a scene association.*/
203 virtual WbItem* clone() = 0;
205 /*! \brief The current version of the item.*/
206 int version;
207 /*! \brief A list of EditUndo objects that contain the history of the item.*/
208 QList<EditUndo> undos;
210 /* Parsing */
211 // General
212 // static QString xmlSimplify(const QString &str);
213 static QList<qreal> parseNumbersList(QString::const_iterator &itr);
214 static QList<qreal> parsePercentageList(QString::const_iterator &itr);
215 inline static bool isUnreserved(const QChar &c, bool first_char = false);
216 static QString idFromUrl(const QString &url);
217 static QMatrix parseTransformationMatrix(const QString &value);
218 static QColor resolveColor(const QString &colorStr);
219 static QColor constructColor(const QString &colorStr, const QString &opacity);
220 static qreal parseLength(const QString &str);
221 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);
222 // static QPen defaultPen;
224 signals:
225 /*! \brief Signals that an attribute of the element is changed.
226 * \param id The ID of this element.
227 * \param attribute The name of the changed attribute.
228 * \param value The new value of the attribute.
229 * \param oldvalue The old value of the attribute.
231 void attributeChanged(const QString &id, const QString &attribute, const QString &value, const QString &oldvalue);
232 /*! \brief Emitted when the parent of the element is changed.*/
233 void parentChanged(const QString &id, const QString &value, const QString &oldvalue);
234 /*! \brief Emitted when the content of the element is changed.*/
235 void contentChanged(const QString &id, const QDomNodeList &value, const QDomNodeList &oldvalue);
236 /*! \brief Emitted when the index of the element is changed.*/
237 void indexChanged(const QString &id, const qreal &deltaIndex);
239 protected:
240 /*! \brief Implements the default item interaction behaviour.
241 * The action depends on the modifier keys being pressed:
242 * \li Ctrl: Translate
243 * \li Ctrl + Alt: Rotate
244 * \li Ctrl + Shift: Scale
246 void handleMouseMoveEvent(QGraphicsSceneMouseEvent * event);
247 /*! \brief Implements the default item interaction behaviour.
248 * The action depends on the modifier keys being pressed:
249 * \li Ctrl: Translate
250 * \li Ctrl + Alt: Rotate
251 * \li Ctrl + Shift: Scale
253 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent * event);
254 /*! \brief Contains the SVG attributes of the element.*/
255 QHash<QString, QString> attributes;
257 /*! \brief Get items document. */
258 QDomDocument & document() ;
260 private:
261 /*! \brief The ID of the item.*/
262 QString id_;
263 /*! \brief The parent of the item.*/
264 QString parent_;
265 /*! \brief The index of the item.*/
266 qreal index_;
268 /*! \brief Shared document for elements */
269 QDomDocument document_;
272 /*! \brief An item for storing the unkown SVG elements.
273 * Inherits WbItem.
275 * The purpose of this item is to store the unkown element. It is not visualized.
276 * \sa WbItem
278 class WbUnknown : public WbItem
280 public:
281 /*! \brief Constructor
282 * Constructs a new root item.
284 WbUnknown(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
285 /*! \brief Returns the type of the item (0x87654999).*/
286 virtual int type() const { return 87654999; };
287 /*! \brief Returns the stored SVG element.*/
288 virtual QDomElement svg();
289 /*! \brief Saves the SVG element.*/
290 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
291 /*! \brief Returns a deep copy of this object but without a scene association.*/
292 virtual WbItem* clone();
294 private:
295 QDomElement svgElement_;
298 /*! \brief An item for storing the SVG root element.
299 * Inherits WbItem.
301 * The main function of the element is to store the root element's attributes.
302 * The item is not visualized on the scene.
303 * \sa WbItem
305 class WbRoot : public WbItem
307 public:
308 /*! \brief Constructor
309 * Constructs a new root item.
311 WbRoot(QGraphicsScene* scene);
312 /*! \brief Returns the type of the item (0x87654000).*/
313 virtual int type() const { return 87654000; };
314 /*! \brief Saves the SVG element.*/
315 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
316 /*! \brief Returns a deep copy of this object but without a scene association.*/
317 virtual WbItem* clone();
318 private:
319 QGraphicsScene* scene_;
322 /*! \brief An item for representing an SVG path element.
323 * Inherits QGraphicsPathItem and WbItem.
325 * Reimplements the methods dictated in WbItem's description.
327 * Provides parsing for the 'd' and 'fill-rule' attributes.
328 * Also provides lineTo() and quadTo() methods (note that they don't
329 * emit an attributeChanged().)
331 * \sa WbItem
333 class WbPath : public QGraphicsPathItem, public WbItem
335 public:
336 /*! \brief Constructor
337 * Constructs a new item with values \a id, \a index, \a parent and
338 * \a scene with other attributes parsed from the SVG element \a svg.
340 WbPath(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
342 /*! \brief Returns the type of the item (0x87654001).*/
343 virtual int type() const { return 87654001; };
344 /*! \brief Returns a corrected version of the shape.*/
345 virtual QPainterPath shape() const;
346 /*! \brief Returns a QGraphicsItem* to self.*/
347 virtual QGraphicsItem* graphicsItem() { return this; };
348 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
349 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
350 /*! \brief Returns a deep copy of this object but without a scene association.*/
351 virtual WbItem* clone();
353 /*! \brief Adds a line to to the end of the path.*/
354 void lineTo(const QPointF &newPoint);
355 /*! \brief Adds a quadratic bezier curve to the end of the path.*/
356 void quadTo(const QPointF &controlPoint, const QPointF &newPoint);
358 static bool parsePathDataFast(const QString &data, QPainterPath &path);
359 static void pathArcSegment(QPainterPath &path, qreal xc, qreal yc, qreal th0, qreal th1, qreal rx, qreal ry, qreal xAxisRotation);
360 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);
362 protected:
363 /*! \brief Constructs and popsup the default context menu.*/
364 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
365 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
366 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
368 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
369 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
370 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
372 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
375 /*! \brief An item for an SVG ellipse element.
376 * Inherits QGraphicsEllipseItem and WbItem.
378 * Reimplements the methods dictated in WbItem's description.
380 * Provides parsing for the 'rx' and 'ry' attributes.
382 * \sa WbItem
384 class WbEllipse : public QGraphicsEllipseItem, public WbItem {
385 public:
386 /*! \brief Constructor
387 * Constructs a new item with values \a id, \a index, \a parent and
388 * \a scene with other attributes parsed from the SVG element \a svg.
390 WbEllipse(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
392 /*! \brief Returns the type of the item (0x87654002).*/
393 virtual int type() const { return 87654002; };
394 /*! \brief Returns a QGraphicsItem* to self.*/
395 virtual QGraphicsItem* graphicsItem() { return this; };
396 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
397 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
398 /*! \brief Returns a deep copy of this object but without a scene association.*/
399 virtual WbItem* clone();
401 protected:
402 /*! \brief Constructs and popsup the default context menu.*/
403 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
404 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
405 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
407 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
408 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
409 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
411 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
414 /*! \brief An item for an SVG circle element.
415 * Inherits WbEllipse.
417 * Provides parsing for the r attribute.
419 * \sa WbItem
421 class WbCircle : public WbEllipse {
422 public:
423 /*! \brief Constructor
424 * Constructs a new item with values \a id, \a index, \a parent and
425 * \a scene with other attributes parsed from the SVG element \a svg.
427 WbCircle(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
429 /*! \brief Returns the type of the item (0x87654003).*/
430 virtual int type() const { return 87654003; };
431 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
432 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
433 /*! \brief Returns a deep copy of this object but without a scene association.*/
434 virtual WbItem* clone();
437 /*! \brief An item for an SVG rectangle element.
438 * Inherits QGraphicsRectItem and WbItem.
440 * Reimplements the methods dictated in WbItem's description.
442 * Provides parsing for the 'width' and 'height' attributes.
444 * \sa WbItem
446 class WbRectangle : public QGraphicsRectItem, public WbItem {
447 public:
448 /*! \brief Constructor
449 * Constructs a new item with values \a id, \a index, \a parent and
450 * \a scene with other attributes parsed from the SVG element \a svg.
452 WbRectangle(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
454 /*! \brief Returns the type of the item (0x87654002).*/
455 virtual int type() const { return 87654004; };
456 /*! \brief Returns a QGraphicsItem* to self.*/
457 virtual QGraphicsItem* graphicsItem() { return this; };
458 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
459 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
460 /*! \brief Returns a deep copy of this object but without a scene association.*/
461 virtual WbItem* clone();
463 protected:
464 /*! \brief Constructs and popsup the default context menu.*/
465 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
466 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
467 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
469 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
470 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
471 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
473 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
476 /*! \brief An item for representing an SVG line element.
477 * Inherits QGraphicsPathItem and WbItem.
479 * Reimplements the methods dictated in WbItem's description.
481 * Provides parsing for the 'x1', 'y1', 'x2', 'y2' attributes.
483 * \sa WbItem
485 class WbLine : public QGraphicsPathItem, public WbItem
487 public:
488 /*! \brief Constructor
489 * Constructs a new item with values \a id, \a index, \a parent and
490 * \a scene with other attributes parsed from the SVG element \a svg.
492 WbLine(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
494 /*! \brief Returns the type of the item (0x87654005).*/
495 virtual int type() const { return 87654005; };
496 /*! \brief Returns a corrected version of the shape.*/
497 virtual QPainterPath shape() const;
498 /*! \brief Returns a QGraphicsItem* to self.*/
499 virtual QGraphicsItem* graphicsItem() { return this; };
500 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
501 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
502 /*! \brief Returns a deep copy of this object but without a scene association.*/
503 virtual WbItem* clone();
505 protected:
506 /*! \brief Constructs and popsup the default context menu.*/
507 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
508 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
509 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
511 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
512 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
513 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
515 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
518 /*! \brief An item for representing an SVG polyline element.
519 * Inherits QGraphicsPathItem and WbItem.
521 * Reimplements the methods dictated in WbItem's description.
523 * Provides parsing for the 'points' attribute.
525 * \sa WbItem
527 class WbPolyline : public QGraphicsPathItem, public WbItem
529 public:
530 /*! \brief Constructor
531 * Constructs a new item with values \a id, \a index, \a parent and
532 * \a scene with other attributes parsed from the SVG element \a svg.
534 WbPolyline(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
536 /*! \brief Returns the type of the item (0x87654006).*/
537 virtual int type() const { return 87654006; };
538 /*! \brief Returns a corrected version of the shape.*/
539 virtual QPainterPath shape() const;
540 /*! \brief Returns a QGraphicsItem* to self.*/
541 virtual QGraphicsItem* graphicsItem() { return this; };
542 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
543 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
544 /*! \brief Returns a deep copy of this object but without a scene association.*/
545 virtual WbItem* clone();
547 protected:
548 /*! \brief Constructs and popsup the default context menu.*/
549 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
550 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
551 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
553 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
554 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
555 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
557 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
560 /*! \brief An item for an SVG circle element.
561 * Inherits WbEllipse.
563 * Provides parsing for the r attribute.
565 * \sa WbItem
567 class WbPolygon : public WbPolyline {
568 public:
569 /*! \brief Constructor
570 * Constructs a new item with values \a id, \a index, \a parent and
571 * \a scene with other attributes parsed from the SVG element \a svg.
573 WbPolygon(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
575 /*! \brief Returns the type of the item (0x87654007).*/
576 virtual int type() const { return 87654007; };
577 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
578 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
579 /*! \brief Returns a deep copy of this object but without a scene association.*/
580 virtual WbItem* clone();
583 class WbText;
585 /*! \brief The visualized part of WbText.
586 * This class provides the QGraphicsItem for the WbText because multiple inheritance doesn't work
587 * when both WbItem and and QGraphicsTextItem inherit from QObject.
589 * \sa WbItem
591 class WbGraphicsTextItem : public QGraphicsTextItem {
592 public:
593 /*! \brief Constructor
594 * Constructs a new visualized item for \a wbtext on \a scene.
596 WbGraphicsTextItem(WbText* wbtext, QGraphicsScene* scene = 0);
598 protected:
599 /*! \brief Constructs and popsup the context menu.*/
600 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
601 /*! \brief Causes the text to be checked for changes.*/
602 virtual void focusOutEvent (QFocusEvent *);
603 /*! \brief Makes the text editable.*/
604 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
605 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
606 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
608 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
609 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
610 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
612 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
614 private:
615 /*! \brief A pointer to the "parent" WbItem.*/
616 WbText* wbText_;
619 /*! \brief An item for an SVG text element.
620 * Inherits WbItem and implements WbGraphicsTextItem as a friend class.
622 * Reimplements the methods dictated in WbItem's description.
624 * Provides parsing for the text content of the text element.
626 * \sa WbItem
628 class WbText : public WbItem {
629 Q_OBJECT
630 friend class WbGraphicsTextItem;
631 public:
632 /*! \brief Constructor
633 * Constructs a new item with values \a id, \a index, \a parent and
634 * \a scene with other attributes parsed from the SVG element \a svg.
636 WbText(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
637 /*! \brief Destructor*/
638 virtual ~WbText();
640 /*! \brief Returns the type of the item (0x87654101).*/
641 virtual int type() const { return 87654101; };
642 /*! \brief Returns a QGraphicsItem* to self.*/
643 virtual QGraphicsItem* graphicsItem() { return graphicsitem_; };
644 /*! \brief Return the item as an SVG element.*/
645 virtual QDomElement svg();
646 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
647 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
648 /*! \brief Returns a deep copy of this object but without a scene association.*/
649 virtual WbItem* clone();
650 /*! \brief Checks if the text has changed and emits a signal accordingly.*/
651 void checkTextChanges();
653 QFont font();
655 WbItemMenu* constructContextMenu();
657 public slots:
658 /*! \brief Popup a font dialog and sets the selected font.*/
659 void setFont();
661 void setFont(QFont font);
663 private:
664 /*! \brief The character data content of the element.*/
665 QString text_;
666 WbGraphicsTextItem* graphicsitem_;
669 /*! \brief An item for representing an SVG image element.
670 * Inherits QGraphicsPixmapItem and WbItem.
672 * Reimplements the methods dictated in WbItem's description.
674 * Provides parsing for the 'points' attribute.
676 * \sa WbItem
678 class WbImage : public QGraphicsPixmapItem, public WbItem
680 public:
681 /*! \brief Constructor
682 * Constructs a new item with values \a id, \a index, \a parent and
683 * \a scene with other attributes parsed from the SVG element \a svg.
685 WbImage(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
687 /*! \brief Returns the type of the item (0x87654102).*/
688 virtual int type() const { return 87654102; };
689 /*! \brief Returns a QGraphicsItem* to self.*/
690 virtual QGraphicsItem* graphicsItem() { return this; };
691 /*! \brief Parses the item specific SVG properties and returns the list of changed attributes.*/
692 virtual QList<QString> parseSvg(QDomElement &, bool emitChanges = false);
693 /*! \brief Returns a deep copy of this object but without a scene association.*/
694 virtual WbItem* clone();
696 protected:
697 /*! \brief Constructs and popsup the default context menu.*/
698 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
699 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
700 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
702 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
703 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
704 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
706 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
709 /*! \brief An item for representing an SVG group element.
710 * Inherits QGraphicsGroupItem and WbItem.
712 * Reimplements the methods dictated in WbItem's description.
714 * Note that calling svg() of this class won't return the child elements
716 * \sa WbItem
718 class WbGroup : public QGraphicsItem, public WbItem
720 public:
721 /*! \brief Constructor
722 * Constructs a new item with values \a id, \a index, \a parent and
723 * \a scene with other attributes parsed from the SVG element \a svg.
725 WbGroup(QDomElement &svg, const QString &id, const qreal &index, const QString &parent = "root", QGraphicsScene * scene = 0);
727 /*! \brief Returns the type of the item (0x87654201).*/
728 virtual int type() const { return 87654201; };
729 /*! \brief Returns a QGraphicsItem* to self.*/
730 virtual QGraphicsItem* graphicsItem() { return this; };
731 /*! \brief Returns a deep copy of this object but without a scene association.*/
732 virtual WbItem* clone();
734 /*! \brief Paints the bounding rect if selected.*/
735 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
736 /*! \brief Returns the bounding rectangle containing all group member items.*/
737 virtual QRectF boundingRect() const;
739 protected:
740 /*! \brief Updates the bounding rectangle when children are added or removed.*/
741 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
743 /*! \brief Constructs and popsup the default context menu.*/
744 virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *);
745 /*! \brief Passes the event to WbItem::handleMousMoveEvent.
746 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
748 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
749 /*! \brief Passes the event to WbItem::handleMousReleaseEvent.
750 * The event is also passed to QGraphicsItem::mouseMoveEvent if not accepted..
752 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
754 private:
755 void addToBoundingRect(const QRectF &itemRect);
756 QRectF boundingRect_;
759 #endif