From 1607c7f5dc0018be1875e38fea1dfb3bbba5b865 Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 15 Jul 2025 22:47:33 +0200 Subject: [PATCH] Minor : improve behavior when rotate terminal part. iIn the element editor, every rotation is made around the center of the scene, this is usefull when rotate several part but less when only one need to be rotated, especially when it is the terminal part and we only want to change the orientation. This commit solve it. Now when only a terminal part is selected, the terminal don't rotate around the center of the scene but change the orientation. The rotation, flip and mirror of parts are good features but always rotate around the center of the scene and if the parts are far from the center of the scene the behavior look inappropriate from the POV of user (because parts move far from original position and can out of the view). A good new features should be to solve it (rotate around the center of the bounding rect of the selection) and probably extract the function rotate/flip/mirror from the parts class and create a new class with for only goal to calculate and apply these modifiaction trough an undo command. --- sources/editor/editorcommands.cpp | 8 ++++++ sources/editor/graphicspart/partterminal.cpp | 28 ++++++++++++++++++++ sources/editor/graphicspart/partterminal.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index 221143c44..6edd57235 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -525,7 +525,11 @@ void RotateElementsCommand::undo() { if (item->type() == PartTerminal::Type) { PartTerminal* term = qgraphicsitem_cast(item); + if(m_items.size() == 1) { + term->previousOrientation(); + } else { term->setRotation(term->rotation()-90); + } } else if (item->type() == PartRectangle::Type) { PartRectangle* rect = qgraphicsitem_cast(item); @@ -570,7 +574,11 @@ void RotateElementsCommand::redo() { if (item->type() == PartTerminal::Type) { PartTerminal* term = qgraphicsitem_cast(item); + if (m_items.size() == 1) { + term->nextOrientation(); + } else { term->setRotation(term->rotation()+90); + } } else if (item->type() == PartRectangle::Type) { PartRectangle* rect = qgraphicsitem_cast(item); diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index af321e771..6ed10d0fd 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -224,6 +224,34 @@ void PartTerminal::mirror() { emit xChanged(); // all terminal-signals call "updateForm" } +void PartTerminal::nextOrientation() +{ + switch (d->m_orientation) { + case Qet::North : + setOrientation(Qet::East); break; + case Qet::East : + setOrientation(Qet::South); break; + case Qet::South : + setOrientation(Qet::West); break; + case Qet::West : + setOrientation(Qet::North); break; + } +} + +void PartTerminal::previousOrientation() +{ + switch (d->m_orientation) { + case Qet::North : + setOrientation(Qet::West); break; + case Qet::East : + setOrientation(Qet::North); break; + case Qet::South : + setOrientation(Qet::East); break; + case Qet::West : + setOrientation(Qet::South); break; + } +} + /** @brief PartTerminal::setTerminalName diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index 76d3cad21..aae26dbee 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -78,6 +78,8 @@ class PartTerminal : public CustomElementGraphicPart qreal rotation() const; void flip(); void mirror(); + void nextOrientation(); + void previousOrientation(); QString terminalName() const { return d -> m_name; }