diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index 87d7cc706..1a013eefa 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -686,7 +686,7 @@ void MirrorElementsCommand::redo() foreach (auto *item, m_items) { if (item->type() == PartText::Type) { PartText* staticText = qgraphicsitem_cast(item); - //staticText->mirror(); + staticText->mirror(); } else if (item->type() == PartDynamicTextField::Type) { PartDynamicTextField* dyntext = qgraphicsitem_cast(item); dyntext->mirror(); @@ -734,7 +734,7 @@ void FlipElementsCommand::redo() foreach (auto *item, m_items) { if (item->type() == PartText::Type) { PartText* staticText = qgraphicsitem_cast(item); - //staticText->flip(); + staticText->flip(); } else if (item->type() == PartDynamicTextField::Type) { PartDynamicTextField* dyntext = qgraphicsitem_cast(item); dyntext->flip(); diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index caad2fa18..ec5a0eb5f 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -72,6 +72,39 @@ void PartText::setRotation(qreal angle) { setPos(QTransform().rotate(angle).map(pos())); } +void PartText::mirror() { + // at first: rotate the text: + QGraphicsObject::setRotation(QET::correctAngle((360-rotation()), true)); + // then see, where we need to re-position depending on text, font ... + QFontMetrics qfm(font()); + qreal textwidth = qfm.horizontalAdvance(toPlainText()); + // ... and angle!!! + qreal rot = qRound(QET::correctAngle(rotation(), true)); + qreal c = qCos(qDegreesToRadians(rot)); + qreal s = qSin(qDegreesToRadians(rot)); + // Now: Move! + qreal x = (-1) * pos().x() - c * (textwidth); + qreal y = pos().y() - s * (textwidth); + setPos(x, y); +} + +void PartText::flip() { + // at first: rotate the text: + QGraphicsObject::setRotation(QET::correctAngle((360-rotation()), true)); + // then see, where we need to re-position depending on text, font ... + QFontMetrics qfm(font()); + qreal textheight = realSize() - qfm.descent(); + // ... and angle!!! + qreal rot = qRound(QET::correctAngle(rotation(), true)); + qreal c = qCos(qDegreesToRadians(rot)); + qreal s = qSin(qDegreesToRadians(rot)); + // Now: Move! + qreal x = pos().x() - s * (textheight); + qreal y = (-1) * pos().y() + c * (textheight); + setPos(x, y); +} + + /** Importe les proprietes d'un texte statique depuis un element XML @param xml_element Element XML a lire diff --git a/sources/editor/graphicspart/parttext.h b/sources/editor/graphicspart/parttext.h index d5650c406..ebfa276df 100644 --- a/sources/editor/graphicspart/parttext.h +++ b/sources/editor/graphicspart/parttext.h @@ -62,6 +62,8 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { void fromXml(const QDomElement &) override; const QDomElement toXml(QDomDocument &) const override; void setRotation(qreal angle); + void mirror(); + void flip(); bool isUseless() const override; QRectF sceneGeometricRect() const override; void startUserTransformation(const QRectF &) override;