Frapper  1.0a
ConnectionGraphicsItem.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of FRAPPER
4 research.animationsinstitut.de
5 sourceforge.net/projects/frapper
6 
7 Copyright (c) 2008-2009 Filmakademie Baden-Wuerttemberg, Institute of Animation
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; version 2.1 of the License.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
21 -----------------------------------------------------------------------------
22 */
23 
32 
33 #ifndef CONNECTIONGRAPHICSITEM_H
34 #define CONNECTIONGRAPHICSITEM_H
35 
36 #include "FrapperPrerequisites.h"
37 #include "Connection.h"
38 #include "NodeGraphicsItem.h"
39 #include <QtGui/QGraphicsLineItem>
40 #include <QtGui/QGraphicsSceneContextMenuEvent>
41 #include <QtGui/QWidget>
42 #include <QtGui/QPainter>
43 #include <QtGui/QMenu>
44 
45 namespace Frapper {
46 
66 class FRAPPER_CORE_EXPORT ConnectionGraphicsItem : public QObject, public QGraphicsLineItem
67 {
68 
69  Q_OBJECT
70 
71 private: // static data
72 
78 
79 public: // static functions
80 
87  static ConnectionGraphicsItem * getTempItem ();
88 
95  static void setTempItem ( ConnectionGraphicsItem *connection );
96 
102  static bool isConnectionCreated ();
103 
104 public: // constructors and destructors
105 
114  ConnectionGraphicsItem ( const QString &name, const QColor &color, const QPointF &startPoint, const QPointF &endPoint );
115 
120 
121 public: // functions
122 
128  virtual QRectF boundingRect () const;
129 
133  virtual QPainterPath shape () const;
134 
140  void setEnabled ( bool enabled );
141 
149  virtual void paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0 );
150 
155  void updatePath ();
156 
162  Connection * getConnection () const;
163 
169  void setConnection ( Connection *connection );
170 
174  //QMap<QString, Connection *> getConnections ();
175 
179  //void addConnection ( Connection *connection );
180 
184  //void removeConnection ( const QString &name );
185 
189  NodeGraphicsItem * getStartNodeItem ();
190 
194  void setStartNodeItem ( NodeGraphicsItem *item );
195 
199  NodeGraphicsItem * getEndNodeItem() const;
200 
204  void setEndNodeItem ( NodeGraphicsItem *item );
205 
209  QPointF getStartPoint () const;
210 
214  void setStartPoint ( const QPointF &startPos );
215 
219  QPointF getEndPoint () const;
220 
224  void setEndPoint ( const QPointF &endPos );
225 
232  void updatePosition ( const QPointF &scenePosition );
233 
234  public slots: //
235 
241  //void contextClicked ( QAction *action );
242 
243 signals: //
244 
250  void nodeGraphicsItemSelected ( const QString &name );
251 
255  void destroyed ( Connection *connection );
256 
260  void destroyed ( ConnectionGraphicsItem *connectionItem );
261 
262 protected: // functions
263 
267  void hoverEnterEvent ( QGraphicsSceneHoverEvent *event );
268 
272  void hoverLeaveEvent ( QGraphicsSceneHoverEvent *event );
273 
277  //QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
278 
279 private: // functions
280 
284  void setTemp ( bool temp );
285 
289  //void contextMenuEvent ( QGraphicsSceneContextMenuEvent *event );
290 
291 private: // data
292 
296  QString m_name;
297 
301  QColor m_color;
302 
306  QPainterPath m_mainPath;
307 
311  QPainterPath m_shadowPath;
312 
317 
321  QPainterPath m_shapePath;
322 
326  QPointF m_startPoint;
327 
331  QPointF m_endPoint;
332 
338 
343 
347  QMap<QString, Connection *> m_connections;
348 
353 
358 
362  //QMenu m_contextMenu;
363 
367  bool m_temp;
368 
372  bool m_hovered;
373 
374 };
375 
376 } // end namespace Frapper
377 
378 #endif