100 const QStyleOptionGraphicsItem * option,
106 if ( Start->collidesWithItem ( End ) )
112 myPen.setColor ( Qt::black );
114 QFont Font (
"Helvetica [Cronyx]", 10 );
115 qreal arrowSize = 10;
116 painter->setFont ( Font );
117 painter->setPen ( myPen );
118 painter->setBrush ( Qt::black );
120 QLineF centerLine ( Start->mapToScene ( Start->boundingRect().center() ),
121 End->mapToScene ( End->boundingRect().center() ) );
122 QPolygonF startPolygon = QPolygonF ( Start->boundingRect() );
123 QPolygonF endPolygon = QPolygonF ( End->boundingRect() );
124 QPointF p1 = endPolygon.first() + End->pos();
126 QPointF intersectPointStart;
127 QPointF intersectPointEnd;
130 for (
int i = 1; i < endPolygon.count(); ++i )
132 p2 = endPolygon.at ( i ) + End->pos();
133 polyLine = QLineF ( p1, p2 );
134 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine, &intersectPointEnd );
136 if ( intersectType == QLineF::BoundedIntersection )
144 p1 = startPolygon.first() + Start->pos();
146 for (
int i = 1; i < startPolygon.count(); ++i )
148 p2 = startPolygon.at ( i ) + Start->pos();
149 polyLine = QLineF ( p1, p2 );
150 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine,
151 &intersectPointStart );
153 if ( intersectType == QLineF::BoundedIntersection )
161 setLine ( QLineF ( intersectPointEnd, intersectPointStart ) );
163 double angle = ::acos ( line().dx() / line().length() );
165 if ( line().dy() >= 0 )
167 angle = ( M_PI * 2 ) - angle;
170 QPointF arrowP1 = line().p1()
171 + QPointF ( sin ( angle + M_PI / 3 ) * arrowSize, cos ( angle + M_PI / 3 ) * arrowSize );
172 QPointF arrowP2 = line().p1()
173 + QPointF ( sin ( angle + M_PI - M_PI / 3 ) * arrowSize,
174 cos ( angle + M_PI - M_PI / 3 ) * arrowSize );
175 QPointF middlePoint = QPointF ( ( arrowP1.x() + arrowP2.x() ) / 2,
176 ( arrowP1.y() + arrowP2.y() ) / 2 );
177 QPointF arrowP3 = QPointF ( line().p1().x() - 2 * ( line().p1().x() - middlePoint.x() ),
178 line().p1().y() - 2 * ( line().p1().y() - middlePoint.y() ) );
180 ArrowHead << line().p1() << arrowP1 << arrowP2;
182 QFontMetrics Metrics ( Font );
183 Metrics.boundingRect ( Name +
" - " + Cardinality );
185 painter->drawLine ( line() );
186 qreal degree = ( angle * 180 ) / M_PI;
191 Label->setRotation ( -degree + LastDegree );
193 if ( degree >= 90 && degree < 270 )
195 Label->setTransformOriginPoint ( Label->boundingRect().center() );
196 Label->setRotation ( -180 );
197 Label->setTransformOriginPoint ( 0, 0 );
199 Label->setPos ( line().p2() + QPointF ( -5 * cos ( angle ), 5 * sin ( angle ) ) );
203 Label->setTransformOriginPoint ( Label->boundingRect().center() );
204 Label->setRotation ( 360 );
205 Label->setTransformOriginPoint ( 0, 0 );
210 Label->setPos ( line().p1() + QPointF ( 20 * cos ( angle ), -20 * sin ( angle ) ) );
214 Label->setPos ( line().p1() + QPointF ( 5 * cos ( angle ), -5 * sin ( angle ) ) );
223 painter->drawPolygon ( ArrowHead );
225 else if ( Composite )
229 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
230 painter->drawPolygon ( ArrowHead );