Merge pull request #694 from IBSYSLevi/feature/center-rotation-option-for-textfields

Feature added: Rotation point center property for dynamic text fields
This commit is contained in:
Laurent Trinques
2026-08-09 21:09:19 +02:00
committed by GitHub
9 changed files with 83 additions and 9 deletions
@@ -99,7 +99,8 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.setAttribute("font", QETUtils::fontToString(font()));
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
root_element.setAttribute("rotation_point_center", m_rotation_point_center ? "true" : "false");
QMetaEnum me = textFromMetaEnum();
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
@@ -164,6 +165,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
setKeepVisualRotation(dom_elmt.attribute("keep_visual_rotation", "true") == "true"? true : false);
setRotationPointCenter(dom_elmt.attribute("rotation_point_center", "false") == "true"? true : false);
if (dom_elmt.hasAttribute("font"))
{
@@ -1311,6 +1313,7 @@ void DynamicElementTextItem::parentElementRotationChanged()
//We temporally disconnect for not change m_visual_rotation value.
//We don't use block signal, because rotationChanged signal is used in other place.
disconnect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
setTransformOriginPoint(m_rotation_point_center ? boundingRect().center() : QPointF(0, 0));
this->setRotation(QET::correctAngle(m_visual_rotation_ref - m_parent_element->rotation(), true));
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
}
@@ -1513,6 +1516,7 @@ void DynamicElementTextItem::setKeepVisualRotation(bool set)
emit keepVisualRotationChanged(set);
if (set) {
m_visual_rotation_ref = this->rotation() + m_parent_element->rotation();
setTransformOriginPoint(m_rotation_point_center ? boundingRect().center() : QPointF(0,0));
connect(m_parent_element, &Element::rotationChanged, this, &DynamicElementTextItem::parentElementRotationChanged);
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
}
@@ -1526,3 +1530,15 @@ bool DynamicElementTextItem::keepVisualRotation() const {
return m_keep_visual_rotation;
}
void DynamicElementTextItem::setRotationPointCenter(bool center)
{
if (m_rotation_point_center == center) return;
m_rotation_point_center = center;
if (m_keep_visual_rotation)
setTransformOriginPoint(center ? boundingRect().center() : QPointF(0,0));
emit rotationPointCenterChanged(center);
}
bool DynamicElementTextItem::rotationPointCenter() const {
return m_rotation_point_center;
}
@@ -51,7 +51,7 @@ class DynamicElementTextItem : public DiagramTextItem
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
Q_PROPERTY(bool keepVisualRotation READ keepVisualRotation WRITE setKeepVisualRotation NOTIFY keepVisualRotationChanged)
Q_PROPERTY(bool rotationPointCenter READ rotationPointCenter WRITE setRotationPointCenter NOTIFY rotationPointCenterChanged)
public:
enum TextFrom {
@@ -72,6 +72,7 @@ class DynamicElementTextItem : public DiagramTextItem
void plainTextChanged();
void textWidthChanged(qreal width);
void keepVisualRotationChanged(bool keep);
void rotationPointCenterChanged(bool center);
public:
DynamicElementTextItem(Element *parent_element);
@@ -113,6 +114,9 @@ class DynamicElementTextItem : public DiagramTextItem
void setKeepVisualRotation(bool set);
bool keepVisualRotation() const;
void setRotationPointCenter(bool set);
bool rotationPointCenter() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
@@ -172,6 +176,7 @@ class DynamicElementTextItem : public DiagramTextItem
qreal m_text_width = -1;
QPointF m_initial_position;
bool m_keep_visual_rotation = true;
bool m_rotation_point_center = false;
qreal m_visual_rotation_ref = 0;
bool m_move_parent = true;
};