Frapper  1.0a
NodeGraphicsItem.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 
33 
34 #ifndef NODEGRAPHICSITEM_H
35 #define NODEGRAPHICSITEM_H
36 
37 #include "FrapperPrerequisites.h"
38 #include "BaseRectItem.h"
39 #include "Node.h"
40 #include "FlagGraphicsItem.h"
41 #include "ViewFlagGraphicsItem.h"
42 #include "PinGraphicsItem.h"
43 #include "instancecountermacros.h"
44 #include <QtGui/QGraphicsSceneContextMenuEvent>
45 #include <QtGui/QWidget>
46 #include <QtGui/QMenu>
47 
48 namespace Frapper {
49 
53  class ConnectionGraphicsItem;
54 
55 
75  class FRAPPER_CORE_EXPORT NodeGraphicsItem : public QObject, public BaseRectItem
76  {
77 
78  Q_OBJECT
80 
81  public: // nested enumerations
82 
90  PDM_Collapsed
91  };
92 
93  public: // static constants
94 
98  static const int ItemWidth = 60;
99 
103  static const int ItemBaseHeight = 44;
104 
108  static const int ItemPinRowHeight = 12;
109 
110  private: // static data
111 
116 
117  public: // constructors and destructors
118 
126  NodeGraphicsItem ( Node *node, QPointF position, const QColor &color );
127 
131  ~NodeGraphicsItem ();
132 
133  public: // functions
134 
140  void setEnabled ( bool enabled );
141 
149  void paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0 );
150 
156  Node * getNode () const;
157 
167  void resetNode ();
168 
173  void bringToFront ();
174 
180  void addConnectionItem ( ConnectionGraphicsItem *item );
181 
188  void removeConnectionItem ( ConnectionGraphicsItem *item );
189 
194  void removeConnectionItems ();
195 
201  void setPinDisplayMode ( PinDisplayMode pinDisplayMode );
202 
203  public slots: //
204 
211  //void removeConnectionItem ( ConnectionGraphicsItem *item );
212 
222  void setSelected ( bool selected );
223 
231  void createConnection ( PinGraphicsItem *pinItem, Parameter *parameter );
232 
237  void refresh ();
238 
239 signals: //
240 
250  void connectionRequested ( Parameter *sourceParameter, Parameter *targetParameter );
251 
261  void connectionRequested ( Node *sourceNode, Node *targetNode );
262 
268  void nodeGraphicsItemMoved ( const QPointF &pos );
269 
270  protected: // functions
271 
277  void mousePressEvent ( QGraphicsSceneMouseEvent *event );
278 
284  void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event );
285 
291  void contextMenuEvent ( QGraphicsSceneContextMenuEvent *event );
292 
296  QVariant itemChange ( GraphicsItemChange change, const QVariant& value );
297 
298  private: // functions
299 
304  void updatePins ();
305 
315  void disableOtherPins ( PinGraphicsItem *pinItem, Parameter *parameter );
316 
328  void beginCreatingConnection ( PinGraphicsItem *pinItem, Parameter *parameter );
329 
342  void endCreatingConnection ( PinGraphicsItem *pinItem, Parameter *parameter );
343 
344  private slots: //
345 
349  void connectByNameClicked ();
350 
356  void updatePinDisplayMode ( QAction *action );
357 
358  private: // data
359 
364 
369 
374 
380 
384  QList<PinGraphicsItem *> m_inputPins;
385 
389  QList<PinGraphicsItem *> m_outputPins;
390 
394  QMap<unsigned int, ConnectionGraphicsItem *> m_connectionItems;
395 
400 
405 
406  };
407 
408 } // end namespace Frapper
409 
410 #endif