102{
103 Q_UNUSED ( option )
104 Q_UNUSED ( widget )
105
106 if (
Start->collidesWithItem (
End ) )
107 {
108 return;
109 }
110
111 QPen myPen = pen();
112 myPen.setColor ( Qt::black );
113
114 QFont Font ( "Helvetica [Cronyx]", 10 );
115 qreal arrowSize = 10;
116 painter->setFont ( Font );
117 painter->setPen ( myPen );
118 painter->setBrush ( Qt::black );
119
124 QPointF p1 = endPolygon.first() +
End->pos();
125 QPointF p2;
126 QPointF intersectPointStart;
127 QPointF intersectPointEnd;
128 QLineF polyLine;
129
130 for ( int i = 1; i < endPolygon.count(); ++i )
131 {
132 p2 = endPolygon.at ( i ) +
End->pos();
133 polyLine = QLineF ( p1, p2 );
134 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine, &intersectPointEnd );
135
136 if ( intersectType == QLineF::BoundedIntersection )
137 {
138 break;
139 }
140
141 p1 = p2;
142 }
143
144 p1 = startPolygon.first() +
Start->pos();
145
146 for ( int i = 1; i < startPolygon.count(); ++i )
147 {
148 p2 = startPolygon.at ( i ) +
Start->pos();
149 polyLine = QLineF ( p1, p2 );
150 QLineF::IntersectType intersectType = polyLine.intersect ( centerLine,
151 &intersectPointStart );
152
153 if ( intersectType == QLineF::BoundedIntersection )
154 {
155 break;
156 }
157
158 p1 = p2;
159 }
160
161 setLine ( QLineF ( intersectPointEnd, intersectPointStart ) );
162
163 double angle = ::acos ( line().dx() / line().length() );
164
165 if ( line().dy() >= 0 )
166 {
167 angle = ( M_PI * 2 ) - angle;
168 }
169
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;
181
182 QFontMetrics Metrics ( Font );
184
185 painter->drawLine ( line() );
186 qreal degree = ( angle * 180 ) / M_PI;
187
188 if ( Label )
189 {
190
192
193 if ( degree >= 90 && degree < 270 )
194 {
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 ) ) );
200 }
201 else
202 {
203 Label->setTransformOriginPoint ( Label->boundingRect().center() );
204 Label->setRotation ( 360 );
205 Label->setTransformOriginPoint ( 0, 0 );
207
209 {
210 Label->setPos ( line().p1() + QPointF ( 20 * cos ( angle ), -20 * sin ( angle ) ) );
211 }
212 else
213 {
214 Label->setPos ( line().p1() + QPointF ( 5 * cos ( angle ), -5 * sin ( angle ) ) );
215 }
216 }
217
219 }
220
222 {
224 }
226 {
229 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
231 }
232}
QRectF boundingRect() const override