#ifndef __CPBASEQTAPPLICATION__PORT__H__ #define __CPBASEQTAPPLICATION__PORT__H__ #include #include namespace cpBaseQtApplication { class Block; class Connection; /** */ class cpBaseQtApplication_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 // __CPBASEQTQPPLICATION__PORT__H__ // eof - $RCSfile$