116 myPen.setColor(Qt::black);
118 QFont Font(
"Helvetica [Cronyx]", 10);
119 qreal arrowSize = 10;
120 painter->setFont(Font);
121 painter->setPen(myPen);
122 painter->setBrush(Qt::black);
124 QLineF centerLine(
Start->mapToScene(
Start->boundingRect().center()),
End->mapToScene(
End->boundingRect().center()));
125 QPolygonF startPolygon = QPolygonF(
Start->boundingRect());
126 QPolygonF endPolygon = QPolygonF(
End->boundingRect());
127 QPointF p1 = endPolygon.first() +
End->pos();
129 QPointF intersectPointStart;
130 QPointF intersectPointEnd;
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);
138 if (intersectType == QLineF::BoundedIntersection) {
145 p1 = startPolygon.first() +
Start->pos();
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);
152 if (intersectType == QLineF::BoundedIntersection) {
159 setLine(QLineF(intersectPointEnd, intersectPointStart));
161 double angle = ::acos(line().dx() / line().length());
163 if (line().dy() >= 0) {
164 angle = (M_PI * 2) - angle;
167 QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, cos(angle + M_PI / 3) * arrowSize);
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;
176 QFontMetrics Metrics(Font);
179 painter->drawLine(line());
180 qreal degree = (angle * 180) / M_PI;
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)));
193 Label->setTransformOriginPoint(
Label->boundingRect().center());
194 Label->setRotation(360);
195 Label->setTransformOriginPoint(0, 0);
199 Label->setPos(line().p1() + QPointF(20 * cos(angle), -20 * sin(angle)));
201 Label->setPos(line().p1() + QPointF(5 * cos(angle), -5 * sin(angle)));
213 ArrowHead << line().p1() << arrowP1 << arrowP3 << arrowP2;