| 33 | } |
| 34 | |
| 35 | void IPProcessEdgeTmp::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) |
| 36 | { |
| 37 | // main line |
| 38 | QPen pen(Qt::DotLine); |
| 39 | pen.setCapStyle(Qt::RoundCap); |
| 40 | pen.setWidth(2); |
| 41 | pen.setColor(Qt::red); |
| 42 | |
| 43 | painter->setPen(pen); |
| 44 | QLineF line(_from.toPoint()+QPoint(32,32), _to.toPoint()); |
| 45 | |
| 46 | painter->drawLine(line); |
| 47 | |
| 48 | // arrow |
| 49 | QPolygonF arrowPolygon; |
| 50 | double arrowSize = 10; |
| 51 | double angle = acos(line.dx() / line.length()); |
| 52 | if (line.dy() >= 0) |
| 53 | angle = (Pi * 2) - angle; |
| 54 | |
| 55 | QPointF arrowP1 = _to - QPointF(sin(angle + Pi / 3) * arrowSize, |
| 56 | cos(angle + Pi / 3) * arrowSize); |
| 57 | QPointF arrowP2 = _to - QPointF(sin(angle + Pi - Pi / 3) * arrowSize, |
| 58 | cos(angle + Pi - Pi / 3) * arrowSize); |
| 59 | arrowPolygon.clear(); |
| 60 | arrowPolygon << _to << arrowP1 << arrowP2; |
| 61 | |
| 62 | pen.setStyle(Qt::SolidLine); |
| 63 | painter->setPen(pen); |
| 64 | painter->drawPolygon(arrowPolygon); |
| 65 | } |