I have a canvas in Qt (QGraphicsScene
in QGraphicsView
) on which user can add shapes: circle, square, rectangle, ellipse and triangle and change the size of either (as single QGraphicsObject
subclass). Between these shapes user can create lines and the direction of the line is indicated by drawing an arrow at the intersection point of the line and a shape in the similar manner to Qt's example ElasticNodes (the connection is also QGraphicsObject
suclass).
Now in order to support bi-directional connections and multiple connections of the same shapes I change any subsequent connection line into quadratic curve with progressively bigger arc to allow their selection and visualisation.
- The implementation of the shapes is so that their centre is NOT top left, but instead the centre of the shape.
- The connection between them is a line between these two centres pushed back in Z axis so it hides behind the shapes.
- The arrow is position at the edge on a shape is determined depending on a shape: radius for circle and trigonometrics for other shapes.
Now when using quadratic curve I need to reposition the arrow to the intersection point of the curve and a shape. With that point I can then use the same procedure to render the arrow because I can get the angle at certain point from QPainterPath
.
However he biggest challenge is to detect this collision point. The only option I can think of is to use QPainterPath::intersected
but for that to work it requires fill areas (i.e. making the curve with a width of at least 2) and I would still need to somehow extract the correct point from the result - not sure how yet.
I would appreciate any ideas on how I could go about this.