]> Creatis software - cpPlugins.git/blob - appli/cpPipelineEditor/QNEPort.h
More on graph editor
[cpPlugins.git] / appli / cpPipelineEditor / QNEPort.h
1 /* Copyright (c) 2012, STANISLAW ADASZEWSKI\r
2    All rights reserved.\r
3 \r
4    Redistribution and use in source and binary forms, with or without\r
5    modification, are permitted provided that the following conditions are met:\r
6    * Redistributions of source code must retain the above copyright\r
7    notice, this list of conditions and the following disclaimer.\r
8    * Redistributions in binary form must reproduce the above copyright\r
9    notice, this list of conditions and the following disclaimer in the\r
10    documentation and/or other materials provided with the distribution.\r
11    * Neither the name of STANISLAW ADASZEWSKI nor the\r
12    names of its contributors may be used to endorse or promote products\r
13    derived from this software without specific prior written permission.\r
14 \r
15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
16    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
17    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
18    DISCLAIMED. IN NO EVENT SHALL STANISLAW ADASZEWSKI BE LIABLE FOR ANY\r
19    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
20    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
21    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
22    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
23    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
24    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
25 */\r
26 \r
27 #ifndef __PIPELINEEDITOR__QNEPORT__H__\r
28 #define __PIPELINEEDITOR__QNEPORT__H__\r
29 \r
30 #include <QGraphicsPathItem>\r
31 \r
32 namespace PipelineEditor\r
33 {\r
34   class QNEBlock;\r
35   class QNEConnection;\r
36 \r
37   /**\r
38    */\r
39   class QNEPort\r
40     : public QGraphicsPathItem\r
41   {\r
42   public:\r
43     typedef QNEPort Self;\r
44     typedef QGraphicsPathItem Superclass;\r
45 \r
46     enum { Type = QGraphicsItem::UserType + 1 };\r
47 \r
48   public:\r
49     QNEPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
50     virtual ~QNEPort( );\r
51 \r
52     void setBlock( QNEBlock* b );\r
53     inline QNEBlock* block( ) const\r
54       { return( this->m_Block ); }\r
55 \r
56     virtual void setName( const QString& n );\r
57     virtual void setExtendedName( const QString& n );\r
58     inline QString name( ) const\r
59       { return( this->m_Label->toPlainText( ) ); }\r
60     inline QString extendedName( ) const\r
61       { return( this->m_ExtendedLabel->toPlainText( ) ); }\r
62 \r
63     inline int radius( ) const\r
64       { return( this->m_Radius ); }\r
65 \r
66     inline bool isExtended( ) const\r
67       { return( this->m_IsExtended ); }\r
68     virtual void setExtend( bool extend );\r
69 \r
70     virtual bool isConnected( QNEPort* other ) = 0;\r
71     inline int type( ) const\r
72       { return( this->Type ); }\r
73 \r
74     virtual void paint(\r
75       QPainter* painter,\r
76       const QStyleOptionGraphicsItem* option,\r
77       QWidget* widget\r
78       );\r
79 \r
80   protected:\r
81     virtual void _updateLabels( ) { }\r
82 \r
83   protected:\r
84     QNEBlock* m_Block;\r
85 \r
86     int  m_Radius;\r
87     int  m_Margin;\r
88     bool m_IsExtended;\r
89 \r
90     QGraphicsTextItem* m_Label;\r
91     QGraphicsTextItem* m_ExtendedLabel;\r
92   };\r
93 \r
94   /**\r
95    */\r
96   class QNENamePort\r
97     : public QNEPort\r
98   {\r
99   public:\r
100     typedef QNENamePort Self;\r
101     typedef QNEPort     Superclass;\r
102 \r
103     enum { Type = Superclass::Type + 1 };\r
104 \r
105   public:\r
106     QNENamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
107     virtual ~QNENamePort( );\r
108 \r
109     virtual bool isConnected( QNEPort* other );\r
110     inline int type( ) const\r
111       { return( this->Type ); }\r
112 \r
113   protected:\r
114     virtual void _updateLabels( );\r
115   };\r
116 \r
117   /**\r
118    */\r
119   class QNETypePort\r
120     : public QNEPort\r
121   {\r
122   public:\r
123     typedef QNETypePort Self;\r
124     typedef QNEPort     Superclass;\r
125 \r
126     enum { Type = Superclass::Type + 2 };\r
127 \r
128   public:\r
129     QNETypePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
130     virtual ~QNETypePort( );\r
131 \r
132     virtual bool isConnected( QNEPort* other );\r
133     inline int type( ) const\r
134       { return( this->Type ); }\r
135 \r
136   protected:\r
137     virtual void _updateLabels( );\r
138   };\r
139 \r
140   /**\r
141    */\r
142   class QNEInputPort\r
143     : public QNEPort\r
144   {\r
145   public:\r
146     typedef QNEInputPort Self;\r
147     typedef QNEPort      Superclass;\r
148 \r
149     enum { Type = Superclass::Type + 3 };\r
150 \r
151   public:\r
152     QNEInputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
153     virtual ~QNEInputPort( );\r
154 \r
155     virtual void setExtend( bool extend );\r
156 \r
157     virtual bool isConnected( QNEPort* other );\r
158     inline int type( ) const\r
159       { return( this->Type ); }\r
160 \r
161     void setConnection( QNEConnection* c );\r
162     inline QNEConnection* connection( )\r
163       { return( this->m_Connection ); }\r
164     inline const QNEConnection* connection( ) const\r
165       { return( this->m_Connection ); }\r
166     inline bool hasConnection( ) const\r
167       { return( this->m_Connection != NULL ); }\r
168 \r
169   protected:\r
170     QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
171     virtual void _updateLabels( );\r
172 \r
173   protected:\r
174     QNEConnection* m_Connection;\r
175   };\r
176 \r
177   /**\r
178    */\r
179   class QNEOutputPort\r
180     : public QNEPort\r
181   {\r
182   public:\r
183     typedef QNEOutputPort Self;\r
184     typedef QNEPort       Superclass;\r
185 \r
186     enum { Type = Superclass::Type + 4 };\r
187 \r
188   public:\r
189     QNEOutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
190     virtual ~QNEOutputPort( );\r
191 \r
192     virtual void setExtend( bool extend );\r
193 \r
194     virtual bool isConnected( QNEPort* other );\r
195     inline int type( ) const\r
196       { return( this->Type ); }\r
197 \r
198     inline QVector< QNEConnection* >& connections( )\r
199       { return( this->m_Connections ); }\r
200     inline const QVector< QNEConnection* >& connections( ) const\r
201       { return( this->m_Connections ); }\r
202 \r
203   protected:\r
204     QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
205     virtual void _updateLabels( );\r
206 \r
207   protected:\r
208     QVector< QNEConnection* > m_Connections;\r
209   };\r
210 \r
211 } // ecapseman\r
212 \r
213 #endif // __PIPELINEEDITOR__QNEPORT__H__\r
214 \r
215 // eof - $RCSfile$\r