X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=lib%2FcpPipelineEditor%2FPort.h;fp=lib%2FcpPipelineEditor%2FPort.h;h=4daafd0b7a32e57f54b6fdacc485233dc0e2d595;hb=1b0022070ff3b5f80f6f8c8b87f73032f5685eaf;hp=0000000000000000000000000000000000000000;hpb=98390bcac544f7f3a6762ce812dda491213d6f13;p=cpPlugins.git diff --git a/lib/cpPipelineEditor/Port.h b/lib/cpPipelineEditor/Port.h new file mode 100644 index 0000000..4daafd0 --- /dev/null +++ b/lib/cpPipelineEditor/Port.h @@ -0,0 +1,169 @@ +#ifndef __CPPIPELINEEDITOR__PORT__H__ +#define __CPPIPELINEEDITOR__PORT__H__ + +#include +#include + +namespace cpPipelineEditor +{ + class Block; + class Connection; + + /** + */ + class cpPipelineEditor_EXPORT Port + : public QGraphicsPathItem + { + public: + typedef Port Self; + typedef QGraphicsPathItem Superclass; + + enum { Type = QGraphicsItem::UserType + 1 }; + + public: + Port( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~Port( ); + + void setBlock( Block* b ); + inline Block* block( ) const + { return( this->m_Block ); } + + virtual void setName( const QString& n ); + virtual void setExtendedName( const QString& n ); + inline QString name( ) const + { return( this->m_Label->toPlainText( ) ); } + inline QString extendedName( ) const + { return( this->m_ExtendedLabel->toPlainText( ) ); } + + inline int radius( ) const + { return( this->m_Radius ); } + + inline bool isExtended( ) const + { return( this->m_IsExtended ); } + virtual void setExtend( bool extend ); + + virtual bool isConnected( Port* other ) = 0; + inline int type( ) const + { return( this->Type ); } + + virtual void paint( + QPainter* painter, + const QStyleOptionGraphicsItem* option, + QWidget* widget + ); + + protected: + virtual void _updateLabels( ) { } + + protected: + Block* m_Block; + + int m_Radius; + int m_Margin; + bool m_IsExtended; + + QGraphicsTextItem* m_Label; + QGraphicsTextItem* m_ExtendedLabel; + }; + + /** + */ + class NamePort + : public Port + { + public: + typedef NamePort Self; + typedef Port Superclass; + + enum { Type = Superclass::Type + 1 }; + + public: + NamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~NamePort( ); + + virtual bool isConnected( Port* other ); + inline int type( ) const + { return( this->Type ); } + + protected: + virtual void _updateLabels( ); + }; + + /** + */ + class InputPort + : public Port + { + public: + typedef InputPort Self; + typedef Port Superclass; + + enum { Type = Superclass::Type + 3 }; + + public: + InputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~InputPort( ); + + virtual void setExtend( bool extend ); + + virtual bool isConnected( Port* other ); + inline int type( ) const + { return( this->Type ); } + + void setConnection( Connection* c ); + inline Connection* connection( ) + { return( this->m_Connection ); } + inline const Connection* connection( ) const + { return( this->m_Connection ); } + inline bool hasConnection( ) const + { return( this->m_Connection != NULL ); } + + protected: + QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + virtual void _updateLabels( ); + + protected: + Connection* m_Connection; + }; + + /** + */ + class OutputPort + : public Port + { + public: + typedef OutputPort Self; + typedef Port Superclass; + + enum { Type = Superclass::Type + 4 }; + + public: + OutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~OutputPort( ); + + virtual void setExtend( bool extend ); + + virtual bool isConnected( Port* other ); + inline int type( ) const + { return( this->Type ); } + + inline QVector< Connection* >& connections( ) + { return( this->m_Connections ); } + inline const QVector< Connection* >& connections( ) const + { return( this->m_Connections ); } + + protected: + QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + virtual void _updateLabels( ); + + virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ); + + protected: + QVector< Connection* > m_Connections; + }; + +} // ecapseman + +#endif // __CPPIPELINEEDITOR__PORT__H__ + +// eof - $RCSfile$