mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
4c3e86c07e
Edit > Aligner > Aligner sur la grille, also in the selection's context menu and the command search, puts each selected item back where dragging it would have left it: symbols and pictures on the folio grid, free texts on the text grid. One undo step; wires follow their symbols. Symbols leave the grid through the fine nudge (Alt+arrow, 1 px), and nothing put them back: 508 of the 3,678 symbols in the example projects are off the 10 px grid. First stage of discussion #1069. The status bar says how many items moved, or that the selection was already on the grid, and how many locked items were left in place. Shapes are left out: they are made of several points and no single one is the obvious one to snap. The snap never reads the keyboard, unlike Diagram::snapToGrid(), so a user who binds the action to a shortcut with Ctrl gets the grid, not pixel rounding. The geometry is in alignment.h, tested by tst_alignment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
54 lines
1.5 KiB
C++
54 lines
1.5 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
|
|
};
|
|
|
|
AlignSelectionCommand(Diagram *diagram, Mode mode, QUndoCommand *parent = nullptr);
|
|
|
|
void undo() override;
|
|
void redo() override;
|
|
|
|
bool isValid() const;
|
|
int movedCount() const;
|
|
int lockedCount() const;
|
|
|
|
private:
|
|
QPointer<Diagram> m_diagram;
|
|
int m_locked_count = 0;
|
|
};
|
|
|
|
#endif // ALIGNSELECTIONCOMMAND_H
|