element-editor: add rotation-functions to "text" and "dynamic_text"

This commit is contained in:
plc-user
2025-02-16 15:42:33 +01:00
parent 2aeae1fe46
commit da109b1522
5 changed files with 48 additions and 5 deletions

View File

@@ -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()
);