#include "Edge.h" #include "Node.h" // ------------------------------------------------------------------------- PipelineEditor::Edge:: Edge( PipelineEditor::Node* src, PipelineEditor::Node* des ) : QGraphicsItem( NULL ), m_ArrowSize( 10 ) { this->setAcceptedMouseButtons( 0 ); this->m_Source = src; this->m_Destination = des; this->m_Source->addEdge( this ); this->m_Destination->addEdge( this ); // TODO: this->setToolTip( "Edge!!!" ); this->adjust( ); } // ------------------------------------------------------------------------- PipelineEditor::Edge:: ~Edge( ) { } // ------------------------------------------------------------------------- PipelineEditor::Node* PipelineEditor::Edge:: sourceNode( ) const { return( this->m_Source ); } // ------------------------------------------------------------------------- PipelineEditor::Node* PipelineEditor::Edge:: destinationNode( ) const { return( this->m_Destination ); } // ------------------------------------------------------------------------- void PipelineEditor::Edge:: adjust( ) { if( this->m_Source == NULL || this->m_Destination == NULL ) return; QLineF line( mapFromItem( this->m_Source, 0, 0 ), mapFromItem( this->m_Destination, 0, 0 ) ); qreal length = line.length( ); this->prepareGeometryChange( ); if( length > qreal( 20 ) ) { QPointF edgeOffset( ( line.dx( ) * qreal( 10 ) ) / length, ( line.dy( ) * qreal( 10 ) ) / length ); this->m_SourcePoint = line.p1( ) + edgeOffset; this->m_DestinationPoint = line.p2( ) - edgeOffset; } else this->m_SourcePoint = this->m_DestinationPoint = line.p1( ); } // ------------------------------------------------------------------------- QRectF PipelineEditor::Edge:: boundingRect( ) const { if( this->m_Source == NULL || this->m_Destination == NULL ) return( QRectF( ) ); qreal penWidth = 1; qreal extra = ( penWidth + this->m_ArrowSize ) / qreal( 2 ); return( QRectF( this->m_SourcePoint, QSizeF( this->m_DestinationPoint.x( ) - this->m_SourcePoint.x( ), this->m_DestinationPoint.y( ) - this->m_SourcePoint.y( ) ) ).normalized( ).adjusted( -extra, -extra, extra, extra ) ); } // ------------------------------------------------------------------------- void PipelineEditor::Edge:: paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) { /* TODO if (!source || !dest) return; QLineF line(sourcePoint, destPoint); if (qFuzzyCompare(line.length(), qreal(0.))) return; // Draw the line itself painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter->drawLine(line); // Draw the arrows double angle = ::acos(line.dx() / line.length()); if (line.dy() >= 0) angle = TwoPi - angle; QPointF destArrowP1 = destPoint + QPointF( sin(angle - Pi / 3) * arrowSize, cos(angle - Pi / 3) * arrowSize ); QPointF destArrowP2 = destPoint + QPointF( sin(angle - Pi + Pi / 3) * arrowSize, cos(angle - Pi + Pi / 3) * arrowSize ); QPointF center = sourcePoint + destPoint; center /= 2; painter->setBrush(Qt::black); painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); painter->drawText( center, "Edge!!!" ); */ } // eof - $RCSfile$