This pull request adds a snap-to-grid function when drawing lines and moving tools or objects and resizing objects. In detail it provides the following functions:
The Shift key is no longer used for multi-selection. Instead now only the Ctrl key works for that. Before, both keys were used for multi-selection.
The Shift key is now used to activate snap-to-grid. The snap function is only active while this key is pressed. If Shift is not pressed, all draw, move and resize operations do not snap.
This also means that the current 0°/45°/90° snap when drawing lines is no longer active when Shift is not pressed. This was requested by several people who wanted to draw "near horizontal" lines.
With the Shift key pressed, some points snap to the grid as follows:
If the background is blank, then no snapping occurs.
If the background is lined, then points snap to the closest line.
If the background is crossed, points snap to the closest crossing.
If intermediate lines are on, they also act as snap points.
Additionally when drawing a line, the 0°/45°/90° snap is activated.
The individual tools and objects behave as follows when the Shift key is pressed and the tool or object is moved:
The center of the Axes tool snaps.
The Zero point of the upper scale on the Ruler snaps.
The Zero point of the Protractor snaps.
The Zero point of the Triangle snaps.
The needle of the compass snaps.
For Objects, all four corner points are snappy.
The individual tools and objects behave as follows when the Shift key is pressed and the tool or object is resized:
When the compass is resized (radius is adjusted) and Shift is pressed, then the radius snaps so that the circle goes through the closest grid point.
No snap when Axes, Ruler, Protractor or Triangle are resized.
When Objects are resized, the resized side snaps to the grid.
No snap for Objects if the lower right corner is resized. Here keeping the aspect ratio is more important.
When an object is in a rotated state, then the corners of the bounding rectangle of the rotated object define the points to snap.
For a Line, the snap points are not determined by the outline of the line, but by the actual line start and end points inside the outline. This works however only if the line is moved or resized in the same session where it was created. After a document was serialized and loaded again, the line property is lost and the line is handled like any other arbitrary drawing.
The implementation of the snap function is as follows:
In UBGraphicsScene, functions are added to compute the snap vector, i.e. the amount by which we should move an object so that it snaps.
Separate commits use these functions for the tools (Axes, Ruler, Protractor, Triangle and Compass).
For drawing a line, the keyboard modifier is forwarded from the UBBoardView to the UBGraphicsScene and the snap functions are used.
Moving objects using the Hand tool is handled in the UBBoardView.
Moving and resizing objects with the pointer tool and using the Delegate frame is handled in the UBGraphicsDelegateFrame.
When at some later time the flexible background definitions are implemented (PR #888), then only the single UBGraphicsScene::snap() function must be adapted. All the other logic is not affected.
This pull request adds a snap-to-grid function when drawing lines and moving tools or objects and resizing objects. In detail it provides the following functions:
Shift
key is no longer used for multi-selection. Instead now only theCtrl
key works for that. Before, both keys were used for multi-selection.Shift
key is now used to activate snap-to-grid. The snap function is only active while this key is pressed. IfShift
is not pressed, all draw, move and resize operations do not snap.Shift
is not pressed. This was requested by several people who wanted to draw "near horizontal" lines.With the
Shift
key pressed, some points snap to the grid as follows:The individual tools and objects behave as follows when the
Shift
key is pressed and the tool or object is moved:The individual tools and objects behave as follows when the
Shift
key is pressed and the tool or object is resized:Shift
is pressed, then the radius snaps so that the circle goes through the closest grid point.When an object is in a rotated state, then the corners of the bounding rectangle of the rotated object define the points to snap.
For a Line, the snap points are not determined by the outline of the line, but by the actual line start and end points inside the outline. This works however only if the line is moved or resized in the same session where it was created. After a document was serialized and loaded again, the line property is lost and the line is handled like any other arbitrary drawing.
The implementation of the snap function is as follows:
UBGraphicsScene
, functions are added to compute the snap vector, i.e. the amount by which we should move an object so that it snaps.UBBoardView
to theUBGraphicsScene
and the snap functions are used.UBBoardView
.UBGraphicsDelegateFrame
.When at some later time the flexible background definitions are implemented (PR #888), then only the single
UBGraphicsScene::snap()
function must be adapted. All the other logic is not affected.This PR is related to the following issues:
871
1007