6 // -------------------------------------------------------------------------
9 const Node* nsrc, const Node* ndes,
10 const QRectF* rsrc, const QRectF* rdes
12 : QGraphicsItem( NULL )
14 this->setAcceptedMouseButtons( 0 );
15 this->m_SrcNode = nsrc;
16 this->m_DesNode = ndes;
17 this->m_SrcRect = rsrc;
18 this->m_DesRect = rdes;
22 // -------------------------------------------------------------------------
23 PipelineEditor::Edge::
28 // -------------------------------------------------------------------------
29 const QRectF* PipelineEditor::Edge::
32 return( this->m_SrcRect );
35 // -------------------------------------------------------------------------
36 const QRectF* PipelineEditor::Edge::
39 return( this->m_DesRect );
42 // -------------------------------------------------------------------------
43 void PipelineEditor::Edge::
48 if( this->m_Src == NULL || this->m_Des == NULL )
52 this->mapFromParent( this->m_Src->center( ) ),
53 this->mapFromParent( this->m_Des->center( ) )
55 // TODO: qreal length = line.length( );
56 this->prepareGeometryChange( );
57 if( length > qreal( 20 ) )
60 ( line.dx( ) * qreal( 10 ) ) / length,
61 ( line.dy( ) * qreal( 10 ) ) / length
63 this->m_SrcPoint = line.p1( ) + edgeOffset;
64 this->m_DesPoint = line.p2( ) - edgeOffset;
67 this->m_SrcPoint = this->m_DesPoint = line.p1( );
71 // -------------------------------------------------------------------------
72 QRectF PipelineEditor::Edge::
75 if( this->m_SrcRect == NULL || this->m_DesRect == NULL )
80 qreal extra = ( penWidth + this->m_ArrowSize ) / qreal( 2 );
82 qreal extra = qreal( 1 );
85 this->m_SrcRect->center( ),
87 this->m_DesRect->center( ).x( ) - this->m_SrcRect->center( ).x( ),
88 this->m_DesRect->center( ).y( ) - this->m_SrcRect->center( ).y( )
90 ).normalized( ).adjusted( -extra, -extra, extra, extra )
94 // -------------------------------------------------------------------------
95 void PipelineEditor::Edge::
97 QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget
101 if( this->m_Src == NULL || this->m_Des == NULL )
105 // TODO: QLineF line( this->m_Src->center( ), this->m_Des->center( ) );
107 this->m_SrcNode->mapToScene( this->m_SrcRect->center( ) ),
108 this->m_DesNode->mapToScene( this->m_DesRect->center( ) )
111 if( qFuzzyCompare( line.length(), qreal( 0 ) ) )
114 // Draw the line itself
116 QPen( Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin )
118 painter->drawLine( line );
122 double angle = ::acos(line.dx() / line.length());
124 angle = TwoPi - angle;
126 QPointF destArrowP1 = destPoint + QPointF(
127 sin(angle - Pi / 3) * arrowSize,
128 cos(angle - Pi / 3) * arrowSize
130 QPointF destArrowP2 = destPoint + QPointF(
131 sin(angle - Pi + Pi / 3) * arrowSize,
132 cos(angle - Pi + Pi / 3) * arrowSize
134 QPointF center = sourcePoint + destPoint;
137 painter->setBrush(Qt::black);
138 painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
139 painter->drawText( center, "Edge!!!" );