2
* wbwidget.h - a widget for processing and showing whiteboard
4
* Copyright (C) 2006 Joonas Govenius
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this library; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include "../sxe/sxesession.h"
28
#include "wbnewitem.h"
30
#include <QSvgRenderer>
32
#include <QGraphicsView>
35
#include <QFileDialog>
38
/*! \brief The whiteboard widget.
39
* Visualizes the whiteboard scene and provides different modes for editing and adding new elements.
40
* Local edits to existing elements are handled by the elements themselves
41
* as mouse events are passed on to them but new items are temporarily
42
* added to the scene while being drawn and only when finished, added to
48
class WbWidget : public QGraphicsView
53
* Indicates the mode the widget is in.
55
enum Mode { Select, Translate, Rotate, Scale, Scroll, Erase, DrawPath, DrawLine, DrawRectangle, DrawEllipse, DrawCircle, DrawPolyline, DrawText, DrawImage };
57
/*! \brief Constructor
58
* Constructs a new widget with \a session and parent \a parent.
60
WbWidget(SxeSession* session, QWidget* parent = 0);
61
/*! \brief Returns the session this widget is visualizing.*/
62
SxeSession* session();
63
/*! \brief Returns the mode this widget is in.*/
65
/*! \brief Sets the mode which determines how to react to user interaction.*/
66
void setMode(Mode mode);
67
/*! \brief Sets the size of the whiteboard.*/
68
void setSize(const QSize &s);
69
/*! \brief Sets the stroke color of new items.*/
70
void setStrokeColor(const QColor &color);
71
/*! \brief Sets the stroke color of new items.*/
72
void setFillColor(const QColor &color);
73
/*! \brief Sets the stroke width of new items.*/
74
void setStrokeWidth(int width);
76
/*! \brief Returns the size set by setSize().*/
77
virtual QSize sizeHint() const;
80
/*! \brief Clears the whiteboard. */
84
/*! \brief Makes sure that area outside the whiteboard is not shown by zooming if necessary.*/
85
virtual void resizeEvent(QResizeEvent * event);
86
/*! \brief Passes events to items as specified by the mode.*/
87
virtual void mousePressEvent(QMouseEvent * event);
88
/*! \brief Passes events to items as specified by the mode.*/
89
virtual void mouseMoveEvent(QMouseEvent * event);
90
/*! \brief Passes events to items as specified by the mode.*/
91
virtual void mouseReleaseEvent(QMouseEvent * event);
94
/*! \brief Returns the item representing the node (if any).*/
95
WbItem* wbItem(const QDomNode &node);
97
/*! \brief The SxeSession synchronizing the document.*/
99
/*! \brief The WbScene used for visualizing the document.*/
101
/*! \brief The user interaction mode the widget is in.*/
103
/*! \brief The stroke color used for new items.*/
105
/*! \brief The fill color used for new items.*/
107
/*! \brief The stroke width used for new items.*/
110
/*! \brief A list of existing WbItems */
111
QList<WbItem*> items_;
112
// /*! \brief A list of WbItems to be deleted. */
113
// QList<WbItem*> deletionQueue_;
114
/*! \brief A list of QDomNode's that were added since last documentUpdated() signal received. */
115
QList<QDomNode> recentlyRelocatedNodes_;
116
/*! \brief A list of WbItem's whose nodes don't have 'id' attributes. */
117
QList<WbItem*> idlessItems_;
118
/*! \brief Pointer to a new item that is being drawn.*/
119
WbNewItem* newWbItem_;
120
/*! \brief Boolean used to force adding a vertex to a path being drawn.*/
122
/*! \brief Timer used for forcing the addition of a new vertex.*/
124
/*! \brief The primary renderer used for rendering the document.*/
125
QSvgRenderer renderer_;
128
/*! \brief Tries to add 'id' attributes to nodes in deletionQueue_ if they still don't have them.*/
129
void handleDocumentUpdated(bool remote);
130
/*! \brief Ensures that an item for the nodes in the inspection queue exist
131
* iff they're children of the root <svg/>.*/
133
/*! \brief Adds a node to the list of nodes that will be processed by inspectNodes() at next documentUpdated().*/
134
void queueNodeInspection(const QDomNode &node);
135
/*! \brief Removes the item representing the node (if any).
136
* Doesn't affect \a node.
138
void removeWbItem(const QDomNode &node);
139
/*! \brief Removes the item from the scene.
140
* Doesn't affect the underlying node.
142
void removeWbItem(WbItem *wbitem);
143
/*! \brief Tries to add 'id' attributes to nodes in idlessItems_ if they still don't have them.*/
145
/*! \brief Adds the item associated with node to idlessItems_. */
146
void addToIdLess(const QDomElement &element);
147
/*! \brief If node is an 'id' attribute node, adds the ownerElement to idlessItems_. */
148
void checkForRemovalOfId(QDomNode node);
149
/*! \brief Checks if \a node is the 'viewbox' attribute of the <svg/> element.
150
* If so, the scene size is adjusted accordingly.
152
void checkForViewBoxChange(const QDomNode &node);
153
// /*! \brief Deletes the WbItem's in the deletion queue. */
154
// void flushDeletionQueue();
157
/*! \brief Rerenders the contents of the document.*/