Developer Documentation
Loading...
Searching...
No Matches
graphicsScene.hh
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43
44#ifndef VSI_GRAPHICSSCENE_HH
45#define VSI_GRAPHICSSCENE_HH
46
47//== INCLUDES =================================================================
48
49#include <QGraphicsScene>
50#include <QPointF>
51#include <QDomDocument>
52#include <QDomElement>
53
54//== FORWARDDECLARATIONS ======================================================
55class QGraphicsRectItem;
56class QMimeData;
57
58
59//== NAMESPACES ===============================================================
60
61namespace VSI {
62
63//== FORWARDDECLARATIONS ======================================================
64class Context;
65class SceneElement;
66class SceneTools;
67class ElementArea;
68class WayFind;
69class ElementFunction;
70class GraphicsView;
71class Connection;
72
73
74//== CLASS DEFINITION =========================================================
75
79class GraphicsScene : public QGraphicsScene
80{
81 Q_OBJECT
82
83 public:
84
86 GraphicsScene (VSI::Context *_ctx, ElementFunction *_function = NULL);
87
90
92 GraphicsView *graphicsView () { return view_; };
93
95 qreal getNewZ ();
96
98 void moveElements (qreal _dx, qreal _dy, bool _selected = false);
99
101 void scaleElements (qreal _delta);
102
104 void scaleElements (qreal _delta, QPointF _center);
105
107 void addElement (SceneElement *_element);
108
110 bool removeElement (SceneElement *_element);
111
113 void mouseMove (QPointF _pos);
114
116 void mouseRelease (QPointF _pos, QGraphicsItem *_item);
117
119 QRectF elementsBoundingRect ();
120
122 ElementArea *elementArea () const { return elementArea_; };
123
125 const QList<SceneElement *>& elements () const;
126
128 QString generateCode (QString &errors, bool _codeOnly = false);
129
131 WayFind *wayFind () { return wayFind_; };
132
134 void saveToXml (QDomDocument &_doc, QDomElement &_root);
135
137 void loadFromXml (QDomElement& _domElement);
138
140 ElementFunction *function () { return function_; };
141
143 void setActiveConnection (Connection *_conn) { activeConnection_ = _conn; };
144
145 signals:
148
149 public slots:
151 void contentChange ();
152
154 void clearScene (bool _start = false);
155
156 protected:
157
158 // draw background
159 virtual void drawBackground(QPainter *_painter, const QRectF &_rect);
160
161 // handle draging of elements from tool box
162 void dragEnterEvent (QGraphicsSceneDragDropEvent *_event);
163 void dragLeaveEvent (QGraphicsSceneDragDropEvent *_event);
164 void dragMoveEvent (QGraphicsSceneDragDropEvent *_event);
165 void dropEvent (QGraphicsSceneDragDropEvent *_event);
166
167 // handle mouse for selection
168 void mousePressEvent (QGraphicsSceneMouseEvent *_event);
169 void mouseMoveEvent (QGraphicsSceneMouseEvent *_event);
170 void mouseReleaseEvent (QGraphicsSceneMouseEvent *_event);
171
172 private slots:
173 // update all connections in the scene
174 void updateConnections ();
175
176 // scene has been resized
177 void sceneResized (const QRectF &_rect);
178
179 private:
180
181 // Mark all inputs that are connected to the outputs of _from as valid (used during code generation)
182 QString updateConnections (SceneElement *_from, bool _isStart);
183
184 // Checks for supported mimetype
185 bool validMimeData (const QMimeData *);
186
187 // gets the element name from the mimetype data
188 QString mimeDataElementName (const QMimeData *);
189
190 // gets the mouse hotspot from the mimetype data
191 QPoint mimeDataPoint (const QMimeData *);
192
193 // load element from xml
194 void loadElement (QDomElement& _domElement,std::vector<QString>& _connections);
195
196 // load connections from xml
197 void loadConnection (QString& _connections);
198
199 // returns all scene elements. Also all elements of sub-functions
200 QList<SceneElement *> getAllElements ();
201
202 private:
203
204 Context *ctx_;
205 ElementFunction *function_;
206 GraphicsView *view_;
207
208 SceneElement *dndElement_;
209 SceneTools *tools_;
210
211 ElementArea *elementArea_;
212
213 QGraphicsRectItem *selection_;
214 QPointF selectionStart_;
215 bool selectionActive_;
216
217 bool dontMoveStart_;
218 bool blockChanges_;
219
220 Connection *activeConnection_;
221
222 qreal currentZ_;
223
224 WayFind *wayFind_;
225};
226
227//=============================================================================
228}
229//=============================================================================
230
231#endif
232
void contentChange()
handle content changes
QRectF elementsBoundingRect()
Bounding rectangle of all scene elements.
void loadFromXml(QDomElement &_domElement)
Load from xml.
void clearScene(bool _start=false)
clear the whole scene (_start = keep start element)
WayFind * wayFind()
WayFind object.
void contentChanged()
Informs about content changes.
ElementFunction * function()
Associated function.
QString generateCode(QString &errors, bool _codeOnly=false)
Generate textual script code (_codeOnly = only pure code block)
qreal getNewZ()
Returns a new Z value that is above all elements.
void mouseMove(QPointF _pos)
Redirect mouse movement to tools area.
void addElement(SceneElement *_element)
Add the element to the scene.
void scaleElements(qreal _delta)
Scale all elements with scaling center in the center of the scene.
void setActiveConnection(Connection *_conn)
Sets the active connection.
const QList< SceneElement * > & elements() const
Scene elements.
void mouseRelease(QPointF _pos, QGraphicsItem *_item)
Redirect mouse release to tools area.
bool removeElement(SceneElement *_element)
Remove the element from the scene.
ElementArea * elementArea() const
Element area.
~GraphicsScene()
Destructor.
void saveToXml(QDomDocument &_doc, QDomElement &_root)
Save to xml.
void moveElements(qreal _dx, qreal _dy, bool _selected=false)
Moves all elements.
GraphicsView * graphicsView()
Graphics view of the scene.