Add Align left/centre/right/top/middle/bottom for the selected items

Edit > Aligner gains six commands, also in the selection's context menu
and the command search: Aligner à gauche, Centrer horizontalement,
Aligner à droite, Aligner en haut, Centrer verticalement, Aligner en bas.
One undo step; wires follow their symbols. Second stage of discussion
#1069, on top of "Aligner sur la grille".

Left/right/top/bottom line the edges up on the outermost one. The two
centre commands line the items up on the mean of their centres, and a
symbol's centre is its origin point, not the middle of its drawing: in
the collection, vertical two-terminal symbols almost always have their
terminals on the origin's axis, so this puts their wires on one line.
A picture is aligned by the picture itself, without its caption
(imageRect() becomes public for this).

A group (#1070) lines up as one piece: its edges are its members'
together, and every member moves by the same amount, so the group keeps
its shape; shapes inside a group come along.

Each item moves only across the line it is aligned on, and lands on the
grid its drag uses, so aligning never takes a symbol off the grid. Two
symbols whose edges sit at different distances from their origins
cannot both be exactly on the line and on the grid; they end up within
half a grid step of it.

The commands need two items (Aligner sur la grille still needs one).
Locked items stay put and the status bar says so. If nothing moves, no
undo step is pushed and the status bar says the selection is already
aligned as far as the grid allows. The geometry is in alignment.h,
tested by tst_alignment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-28 06:55:57 +13:00
parent 1331ed6677
commit 3c4d23bb4e
6 changed files with 411 additions and 24 deletions
+9 -1
View File
@@ -33,7 +33,13 @@ class AlignSelectionCommand : public QUndoCommand
{
public:
enum Mode {
SnapToGrid ///< put each item where a drag would have left it
SnapToGrid, ///< put each item where a drag would have left it
AlignLeft,
AlignHCenter,
AlignRight,
AlignTop,
AlignVCenter,
AlignBottom
};
AlignSelectionCommand(Diagram *diagram, Mode mode, QUndoCommand *parent = nullptr);
@@ -44,10 +50,12 @@ class AlignSelectionCommand : public QUndoCommand
bool isValid() const;
int movedCount() const;
int lockedCount() const;
int itemCount() const;
private:
QPointer<Diagram> m_diagram;
int m_locked_count = 0;
int m_item_count = 0;
};
#endif // ALIGNSELECTIONCOMMAND_H