3 #include <QGraphicsSceneContextMenuEvent>
10 static const QColor SEMANTIC_HIGHLIGHT(0x00, 0x97, 0x81);
11 static const QColor SEMANTIC_DEFAULT = Qt::GlobalColor::black;
15 const QStyleOptionGraphicsItem*
option,
19 QGraphicsPathItem::paint(painter,
option, widget);
21 QPainterPath path = this->path();
22 if (path.elementCount() < 2)
27 int elementCount = path.elementCount();
28 QPointF p1 = path.elementAt(elementCount - 1);
29 QPointF p2 = path.elementAt(elementCount - 2);
34 double angle = std::acos(line.dx() / line.length());
42 QPointF arrowP1 = line.p1() + QPointF(sin(
angle + adjustedAngle) *
size,
44 QPointF arrowP2 = line.p1() + QPointF(sin(
angle +
M_PI - adjustedAngle) *
size,
47 arrowHead << line.p1() << arrowP1 << arrowP2;
51 painter->setBrush(brush);
52 painter->drawPolygon(arrowHead);
62 QPointF point =
event->pos();
64 QPainterPath path = this->path();
66 float minDistance2 = 1000.0f;
67 for (
int i = 0; i < 101; ++i)
70 QPointF pointOnPath = path.pointAtPercent(t);
71 QPointF diff(pointOnPath - point);
72 float length2 = diff.x() * diff.x() + diff.y() * diff.y();
73 if (length2 < minDistance2)
75 minDistance2 = length2;
80 const float CLICK_DISTANCE = 7.0f;
81 if (minDistance2 < CLICK_DISTANCE * CLICK_DISTANCE)
83 event->setAccepted(
true);
88 event->setAccepted(
false);
98 QRectF bb = path().boundingRect();
101 bb.adjust(-deltaX, -deltaY, deltaX, deltaY);