4 // -------------------------------------------------------------------------
6 Edge( PipelineEditor::Node* src, PipelineEditor::Node* des )
7 : QGraphicsItem( NULL ),
10 this->setAcceptedMouseButtons( 0 );
12 this->m_Destination = des;
13 this->m_Source->addEdge( this );
14 this->m_Destination->addEdge( this );
15 // TODO: this->setToolTip( "Edge!!!" );
19 // -------------------------------------------------------------------------
20 PipelineEditor::Edge::
25 // -------------------------------------------------------------------------
26 PipelineEditor::Node* PipelineEditor::Edge::
29 return( this->m_Source );
32 // -------------------------------------------------------------------------
33 PipelineEditor::Node* PipelineEditor::Edge::
34 destinationNode( ) const
36 return( this->m_Destination );
39 // -------------------------------------------------------------------------
40 void PipelineEditor::Edge::
43 if( this->m_Source == NULL || this->m_Destination == NULL )
47 mapFromItem( this->m_Source, 0, 0 ),
48 mapFromItem( this->m_Destination, 0, 0 )
50 qreal length = line.length( );
52 this->prepareGeometryChange( );
54 if( length > qreal( 20 ) )
57 ( line.dx( ) * qreal( 10 ) ) / length,
58 ( line.dy( ) * qreal( 10 ) ) / length
60 this->m_SourcePoint = line.p1( ) + edgeOffset;
61 this->m_DestinationPoint = line.p2( ) - edgeOffset;
64 this->m_SourcePoint = this->m_DestinationPoint = line.p1( );
67 // -------------------------------------------------------------------------
68 QRectF PipelineEditor::Edge::
71 if( this->m_Source == NULL || this->m_Destination == NULL )
75 qreal extra = ( penWidth + this->m_ArrowSize ) / qreal( 2 );
81 this->m_DestinationPoint.x( ) - this->m_SourcePoint.x( ),
82 this->m_DestinationPoint.y( ) - this->m_SourcePoint.y( )
84 ).normalized( ).adjusted( -extra, -extra, extra, extra )
88 // -------------------------------------------------------------------------
89 void PipelineEditor::Edge::
91 QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget
98 QLineF line(sourcePoint, destPoint);
99 if (qFuzzyCompare(line.length(), qreal(0.)))
102 // Draw the line itself
103 painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
104 painter->drawLine(line);
107 double angle = ::acos(line.dx() / line.length());
109 angle = TwoPi - angle;
111 QPointF destArrowP1 = destPoint + QPointF(
112 sin(angle - Pi / 3) * arrowSize,
113 cos(angle - Pi / 3) * arrowSize
115 QPointF destArrowP2 = destPoint + QPointF(
116 sin(angle - Pi + Pi / 3) * arrowSize,
117 cos(angle - Pi + Pi / 3) * arrowSize
119 QPointF center = sourcePoint + destPoint;
122 painter->setBrush(Qt::black);
123 painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
124 painter->drawText( center, "Edge!!!" );