Let Align and Snap to grid move drawn shapes (#1145)

Rectangles, ellipses, lines and polygons were left out of the Align
submenu: with only shapes selected every command was greyed out, and a
shape outside a group was ignored when aligning it with a symbol.

Shapes now take part like pictures. Their edges are the shape as drawn
(the new QetShapeItem::sceneOutlineRect(), without the pen, the 6 px
selection margin or the wider hover outline; the old code used
sceneBoundingRect() for grouped shapes and so aligned them 6 px off).
The point that goes on the grid is the top-left corner of that box: a
rectangle's corner, an ellipse's box. pos() is not used, because a
shape drawn with Ctrl held or rotated has its corners off the grid
while pos() is on it.

The menu's enable rule now counts what the command counts, a group as
one. Before, two symbols in one group enabled the six align commands,
which then did nothing and only said so in the status bar.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 23:24:38 +13:00
parent cbbb9fd0ac
commit 795484ff4f
5 changed files with 127 additions and 86 deletions
+4 -5
View File
@@ -2207,7 +2207,7 @@ void QETDiagramEditor::alignGroupTriggered(QAction *action)
if (mode == AlignSelectionCommand::SnapToGrid)
message = tr("La sélection est déjà sur la grille");
else if (command->itemCount() < 2)
message = tr("Sélectionnez au moins deux éléments, images, textes ou groupes non verrouillés");
message = tr("Sélectionnez au moins deux éléments, images, textes, formes ou groupes non verrouillés");
else
message = tr("La sélection est déjà alignée, à la grille près");
delete command;
@@ -2487,11 +2487,10 @@ void QETDiagramEditor::slot_updateComplexActions()
| DiagramContent::Images);
m_depth_action_group->setEnabled(list.isEmpty()? false : true);
//Align actions: symbols, pictures and free texts take part.
//Align actions: symbols, pictures, free texts and shapes take part,
//counted the way the command counts them, a group as one.
//Snapping needs one of them, lining them up needs two.
const int alignable = selected_elements_count
+ selected_image
+ dc.count(DiagramContent::TextFields);
const int alignable = AlignSelectionCommand::unitCount(dc);
m_align_actions_group.setEnabled(!ro && alignable);
const QList<QAction *> align_actions = m_align_actions_group.actions();
for (QAction *action : align_actions.mid(1))