PDA

View Full Version : Decide the arrow graphics item's docking point



sajis997
15th January 2012, 19:41
Hello forum,

I have some elliptical graphics items which will be connected by arrow graphics item.

The user is supposed to draw the arrow item by clicking and moving from the elliptical item with the control modifier. Even if the user clicks over the

elliptical item i would want to the arrow source start from the border of the elliptical item. The same scenario should happen when the user release the

mouse button over the another destination elliptical item - the arrow destination lands on the border of the elliptical item.


I am trying to write a function to return the docking point for the elliptical item - either for the source or the destination item.

The outline of the function is:



QPointF RootGraphicsItem::hierarchyArrowDockingPoint() const
{
return QPointF(0,0);
}




I need some hint to start ahead.

Thnak you.



Regards
Sajjad

sajis997
16th January 2012, 10:39
Hello forum,

Havent got any response yet. It is quite probable that i have not presented the problem properly enough.


Let me try again.


I want to draw an arrow line item from the border of the elliptical item even if the use clicks over the elliptical item.


Any existing reference or examples to solve this ?


Regards
Sajjad

sajis997
16th January 2012, 19:17
Hi forum,

This may be a more a mathematical question that the qt related one, but i need to post it here just in case some one might know.

Which point on the ellipse gives the shortest distance from the mouse click position inside the ellipse ?



Regards
Sajjad

ChrisW67
16th January 2012, 22:46
The Diagram Scene Example does this sort of thing for polygonal objects by looking for the intersection of the arrow line and each line in the polygon. You cannot do this for the ellipse though, and I cannot see an obvious Qt way to do this (there may be one though).

For ellipses you will need to do more maths. For ellipse where an axis is horizontal then this is trivial: http://mathworld.wolfram.com/Ellipse-LineIntersection.html. For ellipses in other orientations you may need to rotate first. For partial ellipses the problem is much more difficult.