diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index 027a07ac4..958dcd0b8 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -235,7 +235,10 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) { m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString())); setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false); + //The saved position is the one to keep + m_block_alignment = true; setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble()); + m_block_alignment = false; QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); m_text_from = DynamicElementTextItem::TextFrom( @@ -431,13 +434,23 @@ bool PartDynamicTextField::frame() const return m_frame; } +/** + @brief PartDynamicTextField::setTextWidth + Set the width of this text (-1 = automatic width). The point of the text + chosen by its alignment stays in place, as when the text changes: a + right-aligned or centred field no longer grows to the right only, and + undoing a width change puts it back where it was. + @param width +*/ void PartDynamicTextField::setTextWidth(qreal width) { + prepareAlignment(); this -> document() -> setTextWidth(width); //Adjust the width, to ideal width if needed if(width > 0 && document() -> size().width() > width) document() -> setTextWidth(document() -> idealWidth()); + finishAlignment(); m_text_width = document() -> textWidth(); emit textWidthChanged(m_text_width); }