]> Creatis software - cpPlugins.git/blob - appli/cpPipelineEditor/Node.h
More on graph editor
[cpPlugins.git] / appli / cpPipelineEditor / Node.h
1 #ifndef __PIPELINEEDITOR__NODE__H__
2 #define __PIPELINEEDITOR__NODE__H__
3
4 #include <map>
5 #include <set>
6
7 #include <QGraphicsItem>
8 #include <QList>
9
10
11 #include <iostream>
12
13
14 // Some forward declarations
15 class QGraphicsSceneMouseEvent;
16 class QGraphicsSceneHoverEvent;
17
18 // Some forward declarations
19 namespace cpPlugins
20 {
21   namespace Interface
22   {
23     class Object;
24   }
25 }
26
27 namespace PipelineEditor
28 {
29   // Some other forward declarations
30   class Edge;
31   class GraphCanvas;
32
33   /**
34    */
35   class Node
36     : public QGraphicsItem
37   {
38   public:
39     Node( GraphCanvas* canvas, cpPlugins::Interface::Object* object );
40     virtual ~Node( );
41
42     void addEdge( Edge* edge );
43     QList< Edge* > edges( ) const;
44
45     void updateRepresentation( );
46
47     QRectF boundingRect( ) const;
48     QPainterPath shape( ) const;
49     void paint(
50       QPainter* painter,
51       const QStyleOptionGraphicsItem* option,
52       QWidget* widget
53       );
54     void moveBy(qreal dx, qreal dy)
55       {
56         std::cout << "move: " << dx << " " << dy << std::endl;
57         this->QGraphicsItem::moveBy( dx, dy );
58       }
59
60   protected:
61     QVariant itemChange( GraphicsItemChange change, const QVariant& value );
62
63     void mousePressEvent( QGraphicsSceneMouseEvent* event );
64     void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
65     void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event );
66     void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
67     void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
68     void dragMoveEvent( QGraphicsSceneDragDropEvent* event );
69     void dragLeaveEvent( QGraphicsSceneDragDropEvent* event );
70     void dropEvent( QGraphicsSceneDragDropEvent* event );
71
72     void _selectPort( const QPointF& pos );
73     void _deselectPort( );
74
75   private:
76     GraphCanvas*   m_Canvas;
77     QList< Edge* > m_Edges;
78     cpPlugins::Interface::Object* m_Object;
79
80     // Graphical objects
81     QString m_Label;
82     QRectF m_Bounds;
83     std::set< std::string > m_Inputs;
84     std::set< std::string > m_Outputs;
85     std::map< std::string, QRectF > m_InputPorts;
86     std::map< std::string, QRectF > m_OutputPorts;
87
88     // Interaction objects
89     const QRectF* m_SelectedPort;
90     bool m_SelectedPortIsInput;
91     bool m_DraggingPort;
92   };
93
94 } // ecapseman
95
96 #endif // __PIPELINEEDITOR__NODE__H__
97
98 // eof - $RCSfile$