]> Creatis software - cpPlugins.git/blob - lib/cpBaseQtApplication/Port.h
45d1fe95ef67dd744c08043636f84c930f0a0c57
[cpPlugins.git] / lib / cpBaseQtApplication / Port.h
1 #ifndef __CPBASEQTAPPLICATION__PORT__H__\r
2 #define __CPBASEQTAPPLICATION__PORT__H__\r
3 \r
4 #include <cpBaseQtApplication_Export.h>\r
5 #include <QGraphicsPathItem>\r
6 \r
7 namespace cpBaseQtApplication\r
8 {\r
9   class Block;\r
10   class Connection;\r
11 \r
12   /**\r
13    */\r
14   class cpBaseQtApplication_EXPORT Port\r
15     : public QGraphicsPathItem\r
16   {\r
17   public:\r
18     typedef Port Self;\r
19     typedef QGraphicsPathItem Superclass;\r
20 \r
21     enum { Type = QGraphicsItem::UserType + 1 };\r
22 \r
23   public:\r
24     Port( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
25     virtual ~Port( );\r
26 \r
27     void setBlock( Block* b );\r
28     inline Block* block( ) const\r
29       { return( this->m_Block ); }\r
30 \r
31     virtual void setName( const QString& n );\r
32     virtual void setExtendedName( const QString& n );\r
33     inline QString name( ) const\r
34       { return( this->m_Label->toPlainText( ) ); }\r
35     inline QString extendedName( ) const\r
36       { return( this->m_ExtendedLabel->toPlainText( ) ); }\r
37 \r
38     inline int radius( ) const\r
39       { return( this->m_Radius ); }\r
40 \r
41     inline bool isExtended( ) const\r
42       { return( this->m_IsExtended ); }\r
43     virtual void setExtend( bool extend );\r
44 \r
45     virtual bool isConnected( Port* other ) = 0;\r
46     inline int type( ) const\r
47       { return( this->Type ); }\r
48 \r
49     virtual void paint(\r
50       QPainter* painter,\r
51       const QStyleOptionGraphicsItem* option,\r
52       QWidget* widget\r
53       );\r
54 \r
55   protected:\r
56     virtual void _updateLabels( ) { }\r
57 \r
58   protected:\r
59     Block* m_Block;\r
60 \r
61     int  m_Radius;\r
62     int  m_Margin;\r
63     bool m_IsExtended;\r
64 \r
65     QGraphicsTextItem* m_Label;\r
66     QGraphicsTextItem* m_ExtendedLabel;\r
67   };\r
68 \r
69   /**\r
70    */\r
71   class NamePort\r
72     : public Port\r
73   {\r
74   public:\r
75     typedef NamePort Self;\r
76     typedef Port     Superclass;\r
77 \r
78     enum { Type = Superclass::Type + 1 };\r
79 \r
80   public:\r
81     NamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
82     virtual ~NamePort( );\r
83 \r
84     virtual bool isConnected( Port* other );\r
85     inline int type( ) const\r
86       { return( this->Type ); }\r
87 \r
88   protected:\r
89     virtual void _updateLabels( );\r
90   };\r
91 \r
92   /**\r
93    */\r
94   class InputPort\r
95     : public Port\r
96   {\r
97   public:\r
98     typedef InputPort Self;\r
99     typedef Port      Superclass;\r
100 \r
101     enum { Type = Superclass::Type + 3 };\r
102 \r
103   public:\r
104     InputPort(\r
105       QGraphicsItem* parent,\r
106       bool multiple,\r
107       QGraphicsScene* scene = NULL\r
108       );\r
109     virtual ~InputPort( );\r
110 \r
111     virtual void setExtend( bool extend );\r
112 \r
113     virtual bool isConnected( Port* other );\r
114     inline int type( ) const\r
115       { return( this->Type ); }\r
116 \r
117     void setConnection( Connection* c );\r
118     inline Connection* connection( unsigned int i )\r
119       { return( this->m_Connection[ i ] ); }\r
120     inline const Connection* connection( unsigned int i ) const\r
121       { return( this->m_Connection[ i ] ); }\r
122     inline bool hasConnection( ) const\r
123       { return( this->m_Connection.size( ) > 0 ); }\r
124     inline bool isMultiple( ) const\r
125       { return( this->m_IsMultiple ); }\r
126 \r
127   protected:\r
128     QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
129     virtual void _updateLabels( );\r
130 \r
131   protected:\r
132     std::vector< Connection* > m_Connection;\r
133     bool m_IsMultiple;\r
134   };\r
135 \r
136   /**\r
137    */\r
138   class OutputPort\r
139     : public Port\r
140   {\r
141   public:\r
142     typedef OutputPort Self;\r
143     typedef Port       Superclass;\r
144 \r
145     enum { Type = Superclass::Type + 4 };\r
146 \r
147   public:\r
148     OutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
149     virtual ~OutputPort( );\r
150 \r
151     virtual void setExtend( bool extend );\r
152 \r
153     virtual bool isConnected( Port* other );\r
154     inline int type( ) const\r
155       { return( this->Type ); }\r
156 \r
157     inline QVector< Connection* >& connections( )\r
158       { return( this->m_Connections ); }\r
159     inline const QVector< Connection* >& connections( ) const\r
160       { return( this->m_Connections ); }\r
161 \r
162   protected:\r
163     QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
164     virtual void _updateLabels( );\r
165 \r
166     virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* evt );\r
167 \r
168   protected:\r
169     QVector< Connection* > m_Connections;\r
170   };\r
171 \r
172 } // ecapseman\r
173 \r
174 #endif // __CPBASEQTQPPLICATION__PORT__H__\r
175 \r
176 // eof - $RCSfile$\r