107{
108 Q_UNUSED ( option )
109 Q_UNUSED ( widget )
110
111 if (
Start->collidesWithItem (
End ) )
112 {
113 return;
114 }
115
116 QPen myPen = pen();
117 myPen.setColor ( Qt::black );
118
119 QFont Font ( "Helvetica [Cronyx]", 10 );
120 qreal arrowSize = 10;
121 painter->setFont ( Font );
122 painter->setPen ( myPen );
123 painter->setBrush ( Qt::black );
124
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();
130 QPointF p2;
131 QPointF intersectPointStart;
132 QPointF intersectPointEnd;
133 QLineF polyLine;
134
135 for ( int i = 1; i < endPolygon.count(); ++i )
136 {
137 p2 = endPolygon.at ( i ) +
End->pos();
138 polyLine = QLineF ( p1, p2 );
139 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine, &intersectPointEnd );
140
141 if ( intersectType == QLineF::BoundedIntersection )
142 {
143 break;
144 }
145
146 p1 = p2;
147 }
148
149 p1 = startPolygon.first() +
Start->pos();
150
151 for ( int i = 1; i < startPolygon.count(); ++i )
152 {
153 p2 = startPolygon.at ( i ) +
Start->pos();
154 polyLine = QLineF ( p1, p2 );
155 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine,
156 &intersectPointStart );
157
158 if ( intersectType == QLineF::BoundedIntersection )
159 {
160 break;
161 }
162
163 p1 = p2;
164 }
165
166 setLine ( QLineF ( intersectPointEnd, intersectPointStart ) );
167
168 double angle = ::acos ( line().dx() / line().length() );
169
170 if ( line().dy() >= 0 )
171 {
172 angle = ( M_PI * 2 ) - angle;
173 }
174
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;
186
187 QFontMetrics Metrics ( Font );
189
190 painter->drawLine ( line() );
191 qreal degree = ( angle * 180 ) / M_PI;
192
194 {
195
197
198 if ( degree >= 90 && degree < 270 )
199 {
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 ) ) );
205 }
206 else
207 {
208 Label->setTransformOriginPoint (
Label->boundingRect().center() );
209 Label->setRotation ( 360 );
210 Label->setTransformOriginPoint ( 0, 0 );
212
214 {
215 Label->setPos ( line().p1() + QPointF ( 20 * cos ( angle ), -20 * sin ( angle ) ) );
216 }
217 else
218 {
219 Label->setPos ( line().p1() + QPointF ( 5 * cos ( angle ), -5 * sin ( angle ) ) );
220 }
221 }
222
224 }
225
227 {
229 }
231 {
234 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
236 }
237}