#include #include #include #include #include #include // ------------------------------------------------------------------------- cpBaseQtApplication::Connection:: Connection( QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ) { this->setPen( QPen( Qt::black, 2 ) ); this->setBrush( Qt::NoBrush ); this->setZValue( -1 ); this->m_Port1 = NULL; this->m_Port2 = NULL; this->setFlag( QGraphicsItem::ItemIsSelectable ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Connection:: ~Connection( ) { if( this->m_Port1 != NULL ) this->m_Port1->connections( ). remove( this->m_Port1->connections( ).indexOf( this ) ); if( this->m_Port2 != NULL ) this->m_Port2->setConnection( NULL ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: setPos1( const QPointF& p ) { this->m_Pos1 = p; } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: setPos2( const QPointF& p ) { this->m_Pos2 = p; } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: setPort1( OutputPort* p ) { if( p != NULL ) { p->connections( ).append( this ); this->m_Port1 = p; } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: setPort2( InputPort* p ) { if( p != NULL ) { if( p->connection( ) == NULL ) { p->setConnection( this ); this->m_Port2 = p; } // fi } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: updatePosFromPorts( ) { if( this->m_Port1 != NULL ) this->m_Pos1 = this->m_Port1->scenePos( ) + QPointF( this->m_Port1->radius( ), this->m_Port1->radius( ) ); if( this->m_Port2 != NULL ) this->m_Pos2 = this->m_Port2->scenePos( ) + QPointF( this->m_Port2->radius( ), this->m_Port2->radius( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: updatePath( ) { QPainterPath p; p.moveTo( this->m_Pos1 ); qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( ); qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( ); QPointF c1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 ); QPointF c2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 ); p.cubicTo( c1, c2, this->m_Pos2 ); this->setPath( p ); } // ------------------------------------------------------------------------- cpBaseQtApplication::OutputPort* cpBaseQtApplication::Connection:: port1( ) const { return( this->m_Port1 ); } // ------------------------------------------------------------------------- cpBaseQtApplication::InputPort* cpBaseQtApplication::Connection:: port2( ) const { return( this->m_Port2 ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Connection:: paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) { Q_UNUSED( option ); Q_UNUSED( widget ); if( this->isSelected( ) ) painter->setPen( QPen( Qt::red, 5 ) ); else painter->setPen( QPen( Qt::black, 2 ) ); this->setBrush( Qt::NoBrush ); painter->drawPath( this->path( ) ); } // eof - $RCSfile$