107{
108 Q_UNUSED(option)
109 Q_UNUSED(widget)
110
112 return;
113 }
114
115 QPen myPen = pen();
116 myPen.setColor(Qt::black);
117
118 QFont Font("Helvetica [Cronyx]", 10);
119 qreal arrowSize = 10;
120 painter->setFont(Font);
121 painter->setPen(myPen);
122 painter->setBrush(Qt::black);
123
127 QPointF p1 = endPolygon.first() +
End->pos();
128 QPointF p2;
129 QPointF intersectPointStart;
130 QPointF intersectPointEnd;
131 QLineF polyLine;
132
133 for (int i = 1; i < endPolygon.count(); ++i) {
134 p2 = endPolygon.at(i) +
End->pos();
135 polyLine = QLineF(p1, p2);
136 QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointEnd);
137
138 if (intersectType == QLineF::BoundedIntersection) {
139 break;
140 }
141
142 p1 = p2;
143 }
144
145 p1 = startPolygon.first() +
Start->pos();
146
147 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, &intersectPointStart);
151
152 if (intersectType == QLineF::BoundedIntersection) {
153 break;
154 }
155
156 p1 = p2;
157 }
158
159 setLine(QLineF(intersectPointEnd, intersectPointStart));
160
161 double angle = ::acos(line().dx() / line().length());
162
163 if (line().dy() >= 0) {
164 angle = (M_PI * 2) - angle;
165 }
166
167 QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, cos(angle + M_PI / 3) * arrowSize);
168 QPointF arrowP2 =
169 line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, cos(angle + M_PI - M_PI / 3) * arrowSize);
170 QPointF middlePoint = QPointF((arrowP1.x() + arrowP2.x()) / 2, (arrowP1.y() + arrowP2.y()) / 2);
171 QPointF arrowP3 = QPointF(line().p1().x() - 2 * (line().p1().x() - middlePoint.x()),
172 line().p1().y() - 2 * (line().p1().y() - middlePoint.y()));
174 ArrowHead << line().p1() << arrowP1 << arrowP2;
175
176 QFontMetrics Metrics(Font);
178
179 painter->drawLine(line());
180 qreal degree = (angle * 180) / M_PI;
181
183
185
186 if (degree >= 90 && degree < 270) {
187 Label->setTransformOriginPoint(
Label->boundingRect().center());
188 Label->setRotation(-180);
189 Label->setTransformOriginPoint(0, 0);
191 Label->setPos(line().p2() + QPointF(-5 * cos(angle), 5 * sin(angle)));
192 } else {
193 Label->setTransformOriginPoint(
Label->boundingRect().center());
194 Label->setRotation(360);
195 Label->setTransformOriginPoint(0, 0);
197
199 Label->setPos(line().p1() + QPointF(20 * cos(angle), -20 * sin(angle)));
200 } else {
201 Label->setPos(line().p1() + QPointF(5 * cos(angle), -5 * sin(angle)));
202 }
203 }
204
206 }
207
213 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;
215 }
216}
QRectF boundingRect() const override