~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/wbscene.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
 
 * wbscene.h - an SVG whiteboard scene class
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
 
#ifndef WBSCENE_H
21
 
#define WBSCENE_H
22
 
#include <QPointer>
23
 
#include "wbitems.h"
24
 
 
25
 
/*! \brief The scene class for whiteboard items.
26
 
 *  Inherits QGraphicsScene.
27
 
 *
28
 
 *  Processes remote whiteboard edits.
29
 
 *
30
 
 *  This class also provides methods for queueing new edits and
31
 
 *  emits a signal with the corresponding whiteboard element.
32
 
 *
33
 
 *  \sa WbWidget
34
 
 *  \sa WbItem
35
 
 */
36
 
class WbScene : public QGraphicsScene
37
 
{
38
 
        Q_OBJECT
39
 
 
40
 
public:
41
 
        /*! \brief Constructor
42
 
         *  Constructs a new scene with parent \a parent.
43
 
         */
44
 
        WbScene(const QString &session, const QString &ownJid, QObject * parent = 0);
45
 
        /*! \brief Returns the session this widget is visualizing.*/
46
 
        QString session();
47
 
        /*! \brief Returns the JID used by the user in the session.*/
48
 
        const QString & ownJid() const;
49
 
        /*! \brief Processes an incoming whiteboard element.*/
50
 
        bool processWb(const QDomElement &wb);
51
 
        /*! \brief Returns a pointer to the item with ID \a id*/
52
 
        WbItem* findWbItem(const QString &id) const;
53
 
        /*! \brief Returns a pointer to the item with graphicsitem() \a item*/
54
 
        WbItem* findWbItem(QGraphicsItem* item) const;
55
 
        /*! \brief Returns the SVG element representing the item with ID \a id*/
56
 
        QDomElement element(const QString &id) const;
57
 
        /*! \brief Returns the a list of all the elements on the whiteboard*/
58
 
        QList<WbItem*> elements() const;
59
 
 
60
 
        /*! \brief Adds the given item to scene.
61
 
         *  Connects the necessary signals so all items added to the board must be passed to this method.
62
 
         */
63
 
        void addWbItem(WbItem *);
64
 
        /*! \brief Removes the element with ID \a id.*/
65
 
        bool removeElement(const QString &id, bool emitChanges = false);
66
 
 
67
 
        /*! \brief Return a new unique ID.*/
68
 
        QString newId();
69
 
        /*! \brief Return a new index value that will be the highest in the whiteboard.*/
70
 
        qreal newIndex();
71
 
 
72
 
        /*! \brief Appends the given item on the pendigTransformations_ list.*/
73
 
        void queueTransformationChange(WbItem* item);
74
 
        /*! \brief Regenerate and signal the SVG transformation matrices for items on pendigTransformations_ list.*/
75
 
        void regenerateTransformations();
76
 
 
77
 
        /*! \brief If set true, all configure edits are accepted regardless of version.
78
 
         *  Default is false. Should be set true if the session state is Negotiation::DocumentBegun.
79
 
         */
80
 
        bool importing;
81
 
 
82
 
signals:
83
 
        /*! \brief Emitted when a new whiteboard element is ready to be sent.*/
84
 
        void newWb(const QDomElement &wb);
85
 
 
86
 
public slots:
87
 
        /*! \brief Popsup a color dialog and sets color of the selected items.*/
88
 
        void setStrokeColor();
89
 
        /*! \brief Popsup a color dialog and sets fill color of the selected items.*/
90
 
        void setFillColor();
91
 
        /*! \brief Overload: Sets the width of selected items based on the QAction->data().*/
92
 
        void setStrokeWidth(QAction*);
93
 
        /*! \brief Brings the selected items \a n levels forward.
94
 
         *  If n < 0, the items are brought to the front.
95
 
         */
96
 
        void bringForward(int n = 1);
97
 
        /*! \brief Same as bringForward(-1).*/
98
 
        void bringToFront();
99
 
        /*! \brief Sends the selected items \a n levels backwards.
100
 
         *  If n < 0, the items are sent to the back.
101
 
         */
102
 
        void sendBackwards(int n = 1);
103
 
        /*! \brief Same as bringsendBackwardsForward(-1).*/
104
 
        void sendToBack();
105
 
        /*! \brief Groups the selected items.*/
106
 
        void group();
107
 
        /*! \brief Ungroups the selected item groups.*/
108
 
        void ungroup();
109
 
 
110
 
        /*! \brief Composes queued edits and emits a new whiteboard element.*/
111
 
        void sendWb();
112
 
        /*! \brief Queue a new element edit.*/
113
 
        void queueNew(const QString &id, const qreal &index, const QDomElement &svg);
114
 
        /*! \brief Queue an attribute edit.*/
115
 
        void queueAttributeEdit(const QString &target, const QString &attribute, const QString &value, QString oldValue, int from = -1, int to = -1);
116
 
        /*! \brief Queue a parent edit.*/
117
 
        void queueParentEdit(const QString &target, const QString &value, QString oldValue);
118
 
        /*! \brief Queue a content edit.*/
119
 
        void queueContentEdit(const QString &target, const QDomNodeList &value, QDomNodeList oldValue);
120
 
        /*! \brief Queue a move edit.*/
121
 
        void queueMove(const QString &target, qreal di);
122
 
        /*! \brief Queue a remove edit.*/
123
 
        void queueRemove(const QString &target);
124
 
 
125
 
private:
126
 
        /*! \brief Adds or replaces specified element with the given SVG element.*/
127
 
        bool setElement(QDomElement &element, const QString &parent, const QString &id, const qreal &index);
128
 
 
129
 
        /*! \brief Processes an incoming new element edit.*/
130
 
        bool processNew(const QDomElement &New);
131
 
        /*! \brief Processes an incoming configure edit.*/
132
 
        bool processConfigure(const QDomElement &configure);
133
 
        /*! \brief Processes an incoming move edit.*/
134
 
        bool processMove(const QDomElement &move);
135
 
        /*! \brief Processes an incoming remove edit.*/
136
 
        bool processRemove(const QDomElement &remove);
137
 
 
138
 
        /*! \brief Removes specified edits from the queue.
139
 
         *  Removes queued edits that have the specified \a target and \a attribute.
140
 
         *  Sets the \a oldValue to the value at the time of last sent or received edit.
141
 
         */
142
 
        void removeFromQueue(const QString &target, const QString &attribute, QString &oldValue);
143
 
        /*! \brief Removes specified edits from the queue.
144
 
         *  Removes queued edits that have the specified \a target and set a new parent.
145
 
         *  Sets the \a oldParent to the value at the time of last sent or received edit.
146
 
         */
147
 
        void removeFromQueue(const QString &target, QString &oldParent);
148
 
        /*! \brief Removes specified edits from the queue.
149
 
         *  Removes queued edits that have the specified \a target and set content.
150
 
         *  Sets the \a oldContent to the value at the time of last sent or received edit.
151
 
         */
152
 
        void removeFromQueue(const QString &target, QDomNodeList &oldContent);
153
 
 
154
 
        /*! \brief The whiteboard session being visualized.*/
155
 
        QString session_;
156
 
        /*! \brief The JID used in creation of IDs.*/
157
 
        QString ownJid_;
158
 
        /*! \brief The highest index found in the whiteboard (with decimals cropped).*/
159
 
        int highestIndex_;
160
 
        /*! \brief The highest primary part of and ID found in the whiteboard.*/
161
 
        int highestId_;
162
 
 
163
 
        /*! \brief The list containing the queued edits.*/
164
 
        QList<Edit> queue_;
165
 
 
166
 
        /*! \brief A hash of element IDs and pointers to them.*/
167
 
        QHash<QString, WbItem*> elements_;
168
 
 
169
 
        /*! \brief A list of items whose transformation matrix has been changed and are waiting for the corresponding edit to be sent.*/
170
 
        QList< QPointer<WbItem> > pendingTranformations_;
171
 
};
172
 
 
173
 
#endif
174