105 const QStyleOptionGraphicsItem * option,
111 if (
Start->collidesWithItem (
End ) )
117 myPen.setColor ( Qt::black );
119 QFont Font (
"Helvetica [Cronyx]", 10 );
120 qreal arrowSize = 10;
121 painter->setFont ( Font );
122 painter->setPen ( myPen );
123 painter->setBrush ( Qt::black );
125 QLineF centerLine (
Start->mapToScene (
Start->boundingRect().center() ),
126 End->mapToScene (
End->boundingRect().center() ) );
127 QPolygonF startPolygon = QPolygonF (
Start->boundingRect() );
128 QPolygonF endPolygon = QPolygonF (
End->boundingRect() );
129 QPointF p1 = endPolygon.first() +
End->pos();
131 QPointF intersectPointStart;
132 QPointF intersectPointEnd;
135 for (
int i = 1; i < endPolygon.count(); ++i )
137 p2 = endPolygon.at ( i ) +
End->pos();
138 polyLine = QLineF ( p1, p2 );
139 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine, &intersectPointEnd );
141 if ( intersectType == QLineF::BoundedIntersection )
149 p1 = startPolygon.first() +
Start->pos();
151 for (
int i = 1; i < startPolygon.count(); ++i )
153 p2 = startPolygon.at ( i ) +
Start->pos();
154 polyLine = QLineF ( p1, p2 );
155 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine,
156 &intersectPointStart );
158 if ( intersectType == QLineF::BoundedIntersection )
166 setLine ( QLineF ( intersectPointEnd, intersectPointStart ) );
168 double angle = ::acos ( line().dx() / line().length() );
170 if ( line().dy() >= 0 )
172 angle = ( M_PI * 2 ) - angle;
175 QPointF arrowP1 = line().p1()
176 + QPointF ( sin ( angle + M_PI / 3 ) * arrowSize, cos ( angle + M_PI / 3 ) * arrowSize );
177 QPointF arrowP2 = line().p1()
178 + QPointF ( sin ( angle + M_PI - M_PI / 3 ) * arrowSize,
179 cos ( angle + M_PI - M_PI / 3 ) * arrowSize );
180 QPointF middlePoint = QPointF ( ( arrowP1.x() + arrowP2.x() ) / 2,
181 ( arrowP1.y() + arrowP2.y() ) / 2 );
182 QPointF arrowP3 = QPointF ( line().p1().x() - 2 * ( line().p1().x() - middlePoint.x() ),
183 line().p1().y() - 2 * ( line().p1().y() - middlePoint.y() ) );
185 ArrowHead << line().p1() << arrowP1 << arrowP2;
187 QFontMetrics Metrics ( Font );
190 painter->drawLine ( line() );
191 qreal degree = ( angle * 180 ) / M_PI;
198 if ( degree >= 90 && degree < 270 )
200 Label->setTransformOriginPoint (
Label->boundingRect().center() );
201 Label->setRotation ( -180 );
202 Label->setTransformOriginPoint ( 0, 0 );
204 Label->setPos ( line().p2() + QPointF ( -5 * cos ( angle ), 5 * sin ( angle ) ) );
208 Label->setTransformOriginPoint (
Label->boundingRect().center() );
209 Label->setRotation ( 360 );
210 Label->setTransformOriginPoint ( 0, 0 );
215 Label->setPos ( line().p1() + QPointF ( 20 * cos ( angle ), -20 * sin ( angle ) ) );
219 Label->setPos ( line().p1() + QPointF ( 5 * cos ( angle ), -5 * sin ( angle ) ) );
234 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;