From 3fc5469aee22baebb5e2f4257d513c1bf272d8c6 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Sun, 16 Feb 2025 16:15:46 +0100 Subject: [PATCH] element-editor: add mirror and flip for "dynamic_text" --- sources/editor/editorcommands.cpp | 18 ++++++++++----- .../graphicspart/partdynamictextfield.cpp | 23 +++++++++++++++++++ .../graphicspart/partdynamictextfield.h | 2 ++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index 46109d56a..26eaf2f81 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -619,9 +619,12 @@ ElementEditionCommand(QObject::tr("Miroir de sélection", "undo caption"), scene void MirrorElementsCommand::redo() { foreach (auto *item, m_items) { - if ((item->type() == PartText::Type) || - (item->type() == PartDynamicTextField::Type)) { - continue; + if (item->type() == PartText::Type) { + PartText* staticText = qgraphicsitem_cast(item); + //staticText->mirror(); + } else if (item->type() == PartDynamicTextField::Type) { + PartDynamicTextField* dyntext = qgraphicsitem_cast(item); + dyntext->mirror(); } else if (item->type() == PartArc::Type) { PartArc* arc = qgraphicsitem_cast(item); arc->mirror(); @@ -664,9 +667,12 @@ ElementEditionCommand(QObject::tr("Retourner la sélection", "undo caption"), sc void FlipElementsCommand::redo() { foreach (auto *item, m_items) { - if ((item->type() == PartText::Type) || - (item->type() == PartDynamicTextField::Type)) { - continue; + if (item->type() == PartText::Type) { + PartText* staticText = qgraphicsitem_cast(item); + //staticText->flip(); + } else if (item->type() == PartDynamicTextField::Type) { + PartDynamicTextField* dyntext = qgraphicsitem_cast(item); + dyntext->flip(); } else if (item->type() == PartArc::Type) { PartArc* arc = qgraphicsitem_cast(item); arc->flip(); diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index 2f3bd2ff0..bcc25435b 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -69,7 +69,30 @@ QString PartDynamicTextField::xmlName() const void PartDynamicTextField::setRotation(qreal angle) { QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true)); setPos(QTransform().rotate(angle).map(pos())); +} +void PartDynamicTextField::mirror() { + // at first: rotate the text: + QGraphicsObject::setRotation(QET::correctAngle(360-rotation(), true)); + // then see, where we need to re-position depending on the angle! + qreal rot = qRound(QET::correctAngle(rotation(), true)); + qreal c = qCos(qDegreesToRadians(rot)); + qreal s = qSin(qDegreesToRadians(rot)); + qreal x = (-1) * pos().x() - c * boundingRect().width(); + qreal y = pos().y() - s * boundingRect().width(); + setPos(x, y); +} + +void PartDynamicTextField::flip() { + // at first: rotate the text: + QGraphicsObject::setRotation(QET::correctAngle(360-rotation(), true)); + // then see, where we need to re-position depending on the angle! + qreal rot = qRound(QET::correctAngle(rotation(), true)); + qreal c = qCos(qDegreesToRadians(rot)); + qreal s = qSin(qDegreesToRadians(rot)); + qreal x = pos().x() + s * boundingRect().height(); + qreal y = (-1) * pos().y() - c * boundingRect().height(); + setPos(x, y); } /** diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h index 642d11e00..07a1996e9 100644 --- a/sources/editor/graphicspart/partdynamictextfield.h +++ b/sources/editor/graphicspart/partdynamictextfield.h @@ -102,6 +102,8 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart bool keepVisualRotation() const; void setRotation(qreal angle); + void mirror(); + void flip(); protected: