diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index 4fc2e81d7..46109d56a 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -547,6 +547,14 @@ void RotateElementsCommand::undo() PartPolygon* poly = qgraphicsitem_cast(item); poly->setRotation(-90); } + else if (item->type() == PartText::Type) { + PartText* text = qgraphicsitem_cast(item); + text->setRotation(-90); + } + else if (item->type() == PartDynamicTextField::Type) { + PartDynamicTextField* dyntext = qgraphicsitem_cast(item); + dyntext->setRotation(-90); + } else { item->setRotation(item->rotation()-90); } @@ -584,6 +592,14 @@ void RotateElementsCommand::redo() PartPolygon* poly = qgraphicsitem_cast(item); poly->setRotation(+90); } + else if (item->type() == PartText::Type) { + PartText* text = qgraphicsitem_cast(item); + text->setRotation(+90); + } + else if (item->type() == PartDynamicTextField::Type) { + PartDynamicTextField* dyntext = qgraphicsitem_cast(item); + dyntext->setRotation(+90); + } else { item->setRotation(item->rotation()+90); } diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index 529372612..2f3bd2ff0 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -33,7 +33,7 @@ PartDynamicTextField::PartDynamicTextField(QETElementEditor *editor, QGraphicsIt setDefaultTextColor(Qt::black); setFont(QETApp::dynamicTextsItemFont()); QSettings settings; - setRotation(settings.value("diagrameditor/dynamic_text_rotation", 0).toInt()); + QGraphicsObject::setRotation(QET::correctAngle(settings.value("diagrameditor/dynamic_text_rotation", 0).toInt())); setTextWidth(settings.value("diagrameditor/dynamic_text_width", -1).toInt()); setText("_"); setTextFrom(DynamicElementTextItem::UserText); @@ -60,6 +60,18 @@ QString PartDynamicTextField::xmlName() const return QString("dynamic_text"); } + + +/** + Redefines setRotation + @param angle +*/ +void PartDynamicTextField::setRotation(qreal angle) { + QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true)); + setPos(QTransform().rotate(angle).map(pos())); + +} + /** @brief PartDynamicTextField::startUserTransformation @param initial_selection_rect @@ -172,7 +184,7 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) { dom_elmt.attribute("y", QString::number(0)).toDouble() ); setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble()); - QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble()); + QGraphicsObject::setRotation(QET::correctAngle(dom_elmt.attribute("rotation", QString::number(0)).toDouble())); setKeepVisualRotation(dom_elmt.attribute("keep_visual_rotation", "true") == "true"? true : false); if (dom_elmt.hasAttribute("font")) { @@ -255,7 +267,7 @@ void PartDynamicTextField::fromTextFieldXml(const QDomElement &dom_element) setInfoName(dom_element.attribute("tagg", "label")); } - QGraphicsTextItem::setRotation(dom_element.attribute("rotation", "0").toDouble()); + QGraphicsObject::setRotation(QET::correctAngle(dom_element.attribute("rotation", "0").toDouble())); //the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size //The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h index f5bdbfa59..642d11e00 100644 --- a/sources/editor/graphicspart/partdynamictextfield.h +++ b/sources/editor/graphicspart/partdynamictextfield.h @@ -101,6 +101,9 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart void setKeepVisualRotation(const bool &keep); bool keepVisualRotation() const; + void setRotation(qreal angle); + + protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mousePressEvent(QGraphicsSceneMouseEvent *event) override; diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index 313b443ee..caad2fa18 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -63,6 +63,15 @@ PartText::~PartText() { } +/** + Redefines setRotation + @param angle +*/ +void PartText::setRotation(qreal angle) { + QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true)); + setPos(QTransform().rotate(angle).map(pos())); +} + /** Importe les proprietes d'un texte statique depuis un element XML @param xml_element Element XML a lire @@ -89,7 +98,7 @@ void PartText::fromXml(const QDomElement &xml_element) { setPlainText(xml_element.attribute("text")); setPos(xml_element.attribute("x").toDouble(), xml_element.attribute("y").toDouble()); - setRotation(xml_element.attribute("rotation", QString::number(0)).toDouble()); + QGraphicsObject::setRotation(QET::correctAngle(xml_element.attribute("rotation", QString::number(0)).toDouble())); } /** @@ -116,6 +125,7 @@ const QDomElement PartText::toXml(QDomDocument &xml_document) const /** @return Les coordonnees du point situe en bas a gauche du texte. + The coordinates of the point at the bottom left of the text. */ QPointF PartText::margin() const { @@ -124,8 +134,10 @@ QPointF PartText::margin() const qreal document_margin = document() -> documentMargin(); QPointF margin( + // margin around the text // marge autour du texte document_margin, + // margin above the text + distance between the top of the text and the baseline // marge au-dessus du texte + distance entre le plafond du texte et la baseline document_margin + qfm.ascent() ); diff --git a/sources/editor/graphicspart/parttext.h b/sources/editor/graphicspart/parttext.h index e937b822f..d5650c406 100644 --- a/sources/editor/graphicspart/parttext.h +++ b/sources/editor/graphicspart/parttext.h @@ -61,7 +61,7 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { QString xmlName() const override { return(QString("text")); } void fromXml(const QDomElement &) override; const QDomElement toXml(QDomDocument &) const override; - void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));} + void setRotation(qreal angle); bool isUseless() const override; QRectF sceneGeometricRect() const override; void startUserTransformation(const QRectF &) override;