#include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::Port:: Port( QGraphicsItem* parent, QGraphicsScene* scene ) : QObject( ), Superclass( parent, scene ), m_Radius( 5 ), m_Margin( 2 ) { this->m_Label = new QGraphicsTextItem( this ); this->m_ExtendedLabel = new QGraphicsTextItem( this ); this->setExtend( false ); QPainterPath p; p.addEllipse( 0, 0, 2 * this->m_Radius, 2 * this->m_Radius ); this->setPath( p ); this->setPen( QPen( Qt::darkRed ) ); this->setBrush( Qt::red ); this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::Port:: ~Port( ) { } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::Port:: setBlock( Block* b ) { this->m_Block = b; } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::Port:: setName( const QString& n ) { this->m_Label->setPlainText( n ); this->_updateLabels( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::Port:: setExtendedName( const QString& n ) { this->m_ExtendedLabel->setPlainText( n ); this->_updateLabels( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::Port:: setExtend( bool extend ) { // Do nothing! this->m_IsExtended = false; this->m_ExtendedLabel->setVisible( false ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::Port:: paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) { Q_UNUSED( option ); Q_UNUSED( widget ); if( this->isExtended( ) ) { painter->setPen( QPen( Qt::darkBlue ) ); painter->setBrush( Qt::blue ); } else { painter->setPen( QPen( Qt::darkRed ) ); painter->setBrush( Qt::red ); } // fi painter->drawPath( this->path( ) ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::NamePort:: NamePort( QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ) { } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::NamePort:: ~NamePort( ) { } // ------------------------------------------------------------------------- bool cpBaseQtApplication::Pipeline::NamePort:: isConnected( Port* other ) { return( false ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::NamePort:: _updateLabels( ) { QFont font( this->scene( )->font( ) ); font.setBold( true ); this->m_Label->setFont( font ); this->m_ExtendedLabel->setFont( font ); this->setPath( QPainterPath( ) ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::InfoPort:: InfoPort( QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ) { } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::InfoPort:: ~InfoPort( ) { } // ------------------------------------------------------------------------- bool cpBaseQtApplication::Pipeline::InfoPort:: isConnected( Port* other ) { return( false ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::InfoPort:: _updateLabels( ) { QFont font( this->scene( )->font( ) ); font.setBold( false ); this->m_Label->setFont( font ); this->m_ExtendedLabel->setFont( font ); this->setPath( QPainterPath( ) ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::InputPort:: InputPort( QGraphicsItem* parent, bool multiple, QGraphicsScene* scene ) : Superclass( parent, scene ), m_IsMultiple( multiple ) { } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::InputPort:: ~InputPort( ) { this->m_Connection.clear( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::InputPort:: _updateLabels( ) { QFontMetrics fm( this->scene( )->font( ) ); this->m_Label->setPos( this->m_Radius * 2, -fm.height( ) / 2 ); this->m_ExtendedLabel->setPos( -fm.width( this->extendedName( ) ) - this->m_Radius * 2, -fm.height( ) / 2 ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::InputPort:: setExtend( bool extend ) { if( this->m_Connection.size( ) == 0 ) { this->m_IsExtended = extend; this->m_ExtendedLabel->setVisible( extend ); } else this->Superclass::setExtend( false ); } // ------------------------------------------------------------------------- bool cpBaseQtApplication::Pipeline::InputPort:: isConnected( Port* other ) { bool conn = false; auto i = this->m_Connection.begin( ); for( ; i != this->m_Connection.end( ); ++i ) conn |= ( ( *i )->port1( ) == other && ( *i )->port2( ) == this ); return( conn ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::InputPort:: setConnection( Connection* c ) { if( this->m_IsMultiple || this->m_Connection.size( ) == 0 ) this->m_Connection.push_back( c ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::InputPort:: removeConnection( Connection* c ) { auto i = std::find( this->m_Connection.begin( ), this->m_Connection.end( ), c ); if( i != this->m_Connection.end( ) ) { *i = NULL; this->m_Connection.erase( i ); } // fi } // ------------------------------------------------------------------------- QVariant cpBaseQtApplication::Pipeline::InputPort:: itemChange( GraphicsItemChange change, const QVariant& value ) { if( change == ItemScenePositionHasChanged ) { for( auto i = this->m_Connection.begin( ); i != this->m_Connection.end( ); ++i ) { ( *i )->updatePosFromPorts( ); ( *i )->updatePath( ); } // fi } // fi return( value ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::OutputPort:: OutputPort( QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ) { } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::OutputPort:: ~OutputPort( ) { foreach( Connection* conn, this->m_Connections ) delete conn; } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::OutputPort:: _updateLabels( ) { QFontMetrics fm( this->scene( )->font( ) ); this->m_Label->setPos( -fm.width( this->name( ) ) - this->m_Radius * 2, -fm.height( ) / 2 ); this->m_ExtendedLabel->setPos( this->m_Radius * 2, -fm.height( ) / 2 ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::OutputPort:: removeConnection( Connection* c ) { auto i = std::find( this->m_Connections.begin( ), this->m_Connections.end( ), c ); if( i != this->m_Connections.end( ) ) { *i = NULL; this->m_Connections.erase( i ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::OutputPort:: setExtend( bool extend ) { this->m_IsExtended = extend; this->m_ExtendedLabel->setVisible( extend ); } // ------------------------------------------------------------------------- bool cpBaseQtApplication::Pipeline::OutputPort:: isConnected( Port* other ) { auto i = this->m_Connections.begin( ); bool conn = false; for( ; i != this->m_Connections.end( ) && !conn; ++i ) conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other ); return( conn ); } // ------------------------------------------------------------------------- QVariant cpBaseQtApplication::Pipeline::OutputPort:: itemChange( GraphicsItemChange change, const QVariant& value ) { if( change == ItemScenePositionHasChanged ) { foreach( Connection* conn, this->m_Connections ) { conn->updatePosFromPorts( ); conn->updatePath( ); } // rof } // fi return( value ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Pipeline::OutputPort:: contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) { if( this->m_Block == NULL ) return; QMenu menu; QAction* showAction = menu.addAction( "Show" ); QAction* hideAction = menu.addAction( "Hide" ); QAction* selectedAction = menu.exec( evt->screenPos( ) ); if( selectedAction == showAction || selectedAction == hideAction ) { std::stringstream str; str << this->name( ).toStdString( ) << "@" << this->m_Block->filter( )->GetName( ); emit viewData( str.str( ), ( selectedAction == showAction ) ); } // fi } // eof - $RCSfile$