PDA

View Full Version : How to implement a graphical curve drawing/editing tool



hakiim35
20th December 2010, 12:52
Hi all, I need to implement a graphical curve editing tool.
The interface would be similar to the Curve tool of Gimp or PaintDotNet, aiming at image adjustment.
The user can edit any point on the initial curve(y=x line) by clicking and then dragging the point via mouse move.
The curve then should instantly be updated based on the new position of its edited point, taking the proper shape via mathematical equations.
I have basic knowledge about QGraphicsView and QGraphicsScene, but this task seems a bit harder for my level of experience.
Any ideas or any directions to similar available applications/source codes are highly appreciated.

Lykurg
20th December 2010, 13:19
There comes only one off line resource in my mind: have a look at Johan's book "Foundations of Qt Development". There he has an example on how to manipulate circles and rects by using "handler" items.

hakiim35
21st December 2010, 15:43
Thanks for the suggestion,
Any more ideas?
It would be great to place an anchor point on the curve after the current dragging is finished, so that the updated curve is forced to include that point in further manipulations..

marcvanriet
21st December 2010, 21:40
Hi,

See the Elastic nodes (http://doc.qt.nokia.com/4.6/graphicsview-elasticnodes.html) sample.

When you detect a mouse press on your original curve, you can immediately insert an anchor point (like the yellow circles in the sample) and drag this around. While dragging the anchor point, you can continuously recalculate the curve. This way, modifying the curve is just dragging around GraphicsView items, which is easy. And inserting a new point or rearranging an old point is the same piece of code.

Regards,
Marc