~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to src/whiteboarding/wbwidget.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * wbwidget.h - a widget for processing and showing whiteboard
 
3
 *              messages.
 
4
 * Copyright (C) 2006  Joonas Govenius
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 *
 
20
 */
 
21
 
 
22
#ifndef WBWIDGET_H
 
23
#define WBWIDGET_H
 
24
 
 
25
#include "../sxe/sxesession.h"
 
26
#include "wbscene.h"
 
27
#include "wbitem.h"
 
28
#include "wbnewitem.h"
 
29
 
 
30
#include <QSvgRenderer>
 
31
#include <QWidget>
 
32
#include <QGraphicsView>
 
33
#include <QTimer>
 
34
#include <QTime>
 
35
#include <QFileDialog>
 
36
 
 
37
 
 
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
 
43
 *  the WbScene.
 
44
 *
 
45
 *  \sa WbScene
 
46
 *  \sa WbDlg
 
47
 */
 
48
class WbWidget : public QGraphicsView
 
49
{
 
50
        Q_OBJECT
 
51
public:
 
52
        /*! \brief Mode
 
53
         *  Indicates the mode the widget is in.
 
54
         */
 
55
        enum Mode { Select, Translate, Rotate, Scale, Scroll, Erase, DrawPath, DrawLine, DrawRectangle, DrawEllipse, DrawCircle, DrawPolyline, DrawText, DrawImage };
 
56
 
 
57
        /*! \brief Constructor
 
58
         *  Constructs a new widget with \a session and parent \a parent.
 
59
         */
 
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.*/
 
64
        Mode mode();
 
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);
 
75
 
 
76
        /*! \brief Returns the size set by setSize().*/
 
77
        virtual QSize sizeHint() const;
 
78
 
 
79
public slots:
 
80
        /*! \brief Clears the whiteboard. */
 
81
        void clear();
 
82
 
 
83
protected:
 
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);
 
92
 
 
93
private:
 
94
        /*! \brief Returns the item representing the node (if any).*/
 
95
        WbItem* wbItem(const QDomNode &node);
 
96
 
 
97
        /*! \brief The SxeSession synchronizing the document.*/
 
98
        SxeSession* session_;
 
99
        /*! \brief The WbScene used for visualizing the document.*/
 
100
        WbScene* scene_;
 
101
        /*! \brief The user interaction mode the widget is in.*/
 
102
        Mode mode_;
 
103
        /*! \brief The stroke color used for new items.*/
 
104
        QColor strokeColor_;
 
105
        /*! \brief The fill color used for new items.*/
 
106
        QColor fillColor_;
 
107
        /*! \brief The stroke width used for new items.*/
 
108
        int strokeWidth_;
 
109
 
 
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.*/
 
121
        bool addVertex_;
 
122
        /*! \brief Timer used for forcing the addition of a new vertex.*/
 
123
        QTimer* adding_;
 
124
        /*! \brief The primary renderer used for rendering the document.*/
 
125
    QSvgRenderer renderer_;
 
126
 
 
127
private slots:
 
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/>.*/
 
132
        void inspectNodes();
 
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.
 
137
         */
 
138
        void removeWbItem(const QDomNode &node);
 
139
        /*! \brief Removes the item from the scene.
 
140
     *  Doesn't affect the underlying node.
 
141
     */
 
142
        void removeWbItem(WbItem *wbitem);
 
143
        /*! \brief Tries to add 'id' attributes to nodes in idlessItems_ if they still don't have them.*/
 
144
        void addIds();
 
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.
 
151
     */
 
152
    void checkForViewBoxChange(const QDomNode &node);
 
153
    // /*! \brief Deletes the WbItem's in the deletion queue. */
 
154
    // void flushDeletionQueue();
 
155
 
 
156
 
 
157
        /*! \brief Rerenders the contents of the document.*/
 
158
        void rerender();
 
159
};
 
160
 
 
161
#endif