Files
qelectrotech-source-mirror/sources/undocommand/alignselectioncommand.h
T
ispyisail 795484ff4f 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>
2026-09-29 23:24:50 +13:00

65 lines
1.7 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ALIGNSELECTIONCOMMAND_H
#define ALIGNSELECTIONCOMMAND_H
#include <QPointer>
#include <QUndoCommand>
class Diagram;
class DiagramContent;
/**
@brief The AlignSelectionCommand class
Moves each selected item by its own amount, as one undo step.
Symbols, pictures, free texts and shapes take part; locked items are left
where they are and counted, so the caller can say so.
*/
class AlignSelectionCommand : public QUndoCommand
{
public:
enum Mode {
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);
void undo() override;
void redo() override;
bool isValid() const;
int movedCount() const;
int lockedCount() const;
int itemCount() const;
static int unitCount(const DiagramContent &dc);
private:
QPointer<Diagram> m_diagram;
int m_locked_count = 0;
int m_item_count = 0;
};
#endif // ALIGNSELECTIONCOMMAND_H