mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
3c4d23bb4e
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>
62 lines
1.6 KiB
C++
62 lines
1.6 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;
|
|
|
|
/**
|
|
@brief The AlignSelectionCommand class
|
|
Moves each selected item by its own amount, as one undo step.
|
|
Symbols, pictures and free texts 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;
|
|
|
|
private:
|
|
QPointer<Diagram> m_diagram;
|
|
int m_locked_count = 0;
|
|
int m_item_count = 0;
|
|
};
|
|
|
|
#endif // ALIGNSELECTIONCOMMAND_H
|