5 #include <QGraphicsSceneContextMenuEvent>
10 static const QColor SEMANTIC_HIGHLIGHT(0x00, 0x97, 0x81);
11 static const QColor SEMANTIC_DEFAULT = Qt::GlobalColor::black;
16 QGraphicsPathItem::paint(painter,
option, widget);
18 QPainterPath path = this->path();
19 if (path.elementCount() < 2)
24 int elementCount = path.elementCount();
25 QPointF p1 = path.elementAt(elementCount - 1);
26 QPointF p2 = path.elementAt(elementCount - 2);
31 double angle = std::acos(line.dx() / line.length());
39 QPointF arrowP1 = line.p1() + QPointF(sin(
angle + adjustedAngle) *
size,
41 QPointF arrowP2 = line.p1() + QPointF(sin(
angle +
M_PI - adjustedAngle) *
size,
44 arrowHead << line.p1() << arrowP1 << arrowP2 ;
48 painter->setBrush(brush);
49 painter->drawPolygon(arrowHead);
58 QPointF point =
event->pos();
60 QPainterPath path = this->path();
62 float minDistance2 = 1000.0f;
63 for (
int i = 0; i < 101; ++i)
66 QPointF pointOnPath = path.pointAtPercent(t);
67 QPointF diff(pointOnPath - point);
68 float length2 = diff.x() * diff.x() + diff.y() * diff.y();
69 if (length2 < minDistance2)
71 minDistance2 = length2;
75 const float CLICK_DISTANCE = 7.0f;
76 if (minDistance2 < CLICK_DISTANCE * CLICK_DISTANCE)
78 event->setAccepted(
true);
83 event->setAccepted(
false);
92 QRectF bb = path().boundingRect();
95 bb.adjust(-deltaX, -deltaY, deltaX, deltaY);