1 #include <cpBaseQtApplication/Pipeline/Connection.h>
\r
2 #include <cpBaseQtApplication/Pipeline/Port.h>
\r
5 #include <QGraphicsScene>
\r
9 // -------------------------------------------------------------------------
\r
10 cpBaseQtApplication::Pipeline::Connection::
\r
11 Connection( QGraphicsItem* parent, QGraphicsScene* scene )
\r
12 : Superclass( parent, scene )
\r
14 this->setPen( QPen( Qt::black, 2 ) );
\r
15 this->setBrush( Qt::NoBrush );
\r
16 this->setZValue( -1 );
\r
17 this->m_Port1 = NULL;
\r
18 this->m_Port2 = NULL;
\r
19 this->setFlag( QGraphicsItem::ItemIsSelectable );
\r
22 // -------------------------------------------------------------------------
\r
23 cpBaseQtApplication::Pipeline::Connection::
\r
26 if( this->m_Port1 != NULL )
\r
27 this->m_Port1->removeConnection( this );
\r
28 if( this->m_Port2 != NULL )
\r
29 this->m_Port2->removeConnection( this );
\r
32 // -------------------------------------------------------------------------
\r
33 void cpBaseQtApplication::Pipeline::Connection::
\r
34 setPos1( const QPointF& p )
\r
39 // -------------------------------------------------------------------------
\r
40 void cpBaseQtApplication::Pipeline::Connection::
\r
41 setPos2( const QPointF& p )
\r
46 // -------------------------------------------------------------------------
\r
47 void cpBaseQtApplication::Pipeline::Connection::
\r
48 setPort1( OutputPort* p )
\r
52 p->connections( ).push_back( this );
\r
58 // -------------------------------------------------------------------------
\r
59 void cpBaseQtApplication::Pipeline::Connection::
\r
60 setPort2( InputPort* p )
\r
64 p->setConnection( this );
\r
70 // -------------------------------------------------------------------------
\r
71 void cpBaseQtApplication::Pipeline::Connection::
\r
72 updatePosFromPorts( )
\r
74 if( this->m_Port1 != NULL )
\r
76 this->m_Port1->scenePos( ) +
\r
77 QPointF( this->m_Port1->radius( ), this->m_Port1->radius( ) );
\r
78 if( this->m_Port2 != NULL )
\r
80 this->m_Port2->scenePos( ) +
\r
81 QPointF( this->m_Port2->radius( ), this->m_Port2->radius( ) );
\r
84 // -------------------------------------------------------------------------
\r
85 void cpBaseQtApplication::Pipeline::Connection::
\r
89 p.moveTo( this->m_Pos1 );
\r
91 qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( );
\r
92 qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( );
\r
93 QPointF c1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 );
\r
94 QPointF c2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 );
\r
95 p.cubicTo( c1, c2, this->m_Pos2 );
\r
100 // -------------------------------------------------------------------------
\r
101 cpBaseQtApplication::Pipeline::OutputPort*
\r
102 cpBaseQtApplication::Pipeline::Connection::
\r
105 return( this->m_Port1 );
\r
108 // -------------------------------------------------------------------------
\r
109 cpBaseQtApplication::Pipeline::InputPort*
\r
110 cpBaseQtApplication::Pipeline::Connection::
\r
113 return( this->m_Port2 );
\r
116 // -------------------------------------------------------------------------
\r
117 void cpBaseQtApplication::Pipeline::Connection::
\r
120 const QStyleOptionGraphicsItem* option,
\r
124 Q_UNUSED( option );
\r
125 Q_UNUSED( widget );
\r
127 if( this->isSelected( ) )
\r
128 painter->setPen( QPen( Qt::red, 5 ) );
\r
130 painter->setPen( QPen( Qt::black, 2 ) );
\r
131 this->setBrush( Qt::NoBrush );
\r
132 painter->drawPath( this->path( ) );
\r