diff --git a/sources/editor/parttext.cpp b/sources/editor/parttext.cpp index 8809c355c..78f4486bb 100644 --- a/sources/editor/parttext.cpp +++ b/sources/editor/parttext.cpp @@ -63,6 +63,7 @@ void PartText::fromXml(const QDomElement &xml_element) { xml_element.attribute("x").toDouble(), xml_element.attribute("y").toDouble() ); + known_position_ = pos(); } /** @@ -195,6 +196,7 @@ void PartText::setProperty(const QString &property, const QVariant &value) { } else if (property == "size") { if (!value.canConvert(QVariant::Int)) return; setFont(QETApp::diagramTextsFont(value.toInt())); + adjustItemPosition(0); } else if (property == "text") { setPlainText(value.toString()); } @@ -229,8 +231,13 @@ QVariant PartText::property(const QString &property) { @param value Valeur numerique relative au changement */ QVariant PartText::itemChange(GraphicsItemChange change, const QVariant &value) { - if (scene()) { - if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { + if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged) { + // memorise la nouvelle position "officielle" du champ de texte + // cette information servira a le recentrer en cas d'ajout / retrait de lignes + known_position_ = pos(); + infos -> updateForm(); + } else if (change == QGraphicsItem::ItemSelectedHasChanged) { + if (value.toBool() == true) { infos -> updateForm(); } } @@ -276,6 +283,18 @@ void PartText::paint(QPainter *painter, const QStyleOptionGraphicsItem *qsogi, Q #endif } +/** + Cette methode s'assure que la position du champ de texte est coherente + en repositionnant son origine (c-a-d le milieu du bord gauche du champ de + texte) a la position originale. Cela est notamment utile lorsque le champ + de texte est agrandi ou retreci verticalement (ajout ou retrait de lignes). + @param new_block_count Nombre de blocs dans le PartText +*/ +void PartText::adjustItemPosition(int new_block_count) { + Q_UNUSED(new_block_count); + setPos(known_position_); +} + #ifdef QET_DEBUG_EDITOR_TEXTS /** Dessine deux petites fleches pour mettre un point en valeur diff --git a/sources/editor/parttext.h b/sources/editor/parttext.h index f14d49796..3a483e3f7 100644 --- a/sources/editor/parttext.h +++ b/sources/editor/parttext.h @@ -56,6 +56,9 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { virtual bool isUseless() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0 ); + public slots: + void adjustItemPosition(int); + protected: virtual void focusOutEvent(QFocusEvent *); virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); @@ -68,5 +71,6 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { void drawPoint(QPainter *, const QPointF &); #endif QString previous_text; + QPointF known_position_; }; #endif diff --git a/sources/editor/parttextfield.cpp b/sources/editor/parttextfield.cpp index 9ff3d3fae..20f3c681c 100644 --- a/sources/editor/parttextfield.cpp +++ b/sources/editor/parttextfield.cpp @@ -242,6 +242,7 @@ void PartTextField::setProperty(const QString &property, const QVariant &value) } else if (property == "size") { if (!value.canConvert(QVariant::Int)) return; setFont(QETApp::diagramTextsFont(value.toInt())); + adjustItemPosition(0); } else if (property == "text") { setPlainText(value.toString()); } else if (property == "rotation angle") { @@ -343,7 +344,7 @@ void PartTextField::paint(QPainter *painter, const QStyleOptionGraphicsItem *qso en repositionnant son origine (c-a-d le milieu du bord gauche du champ de texte) a la position originale. Cela est notamment utile lorsque le champ de texte est agrandi ou retreci verticalement (ajout ou retrait de lignes). - @param new_bloc_count Nombre de blocs dans l'ElementTextItem + @param new_block_count Nombre de blocs dans le PartTextField */ void PartTextField::adjustItemPosition(int new_block_count) { Q_UNUSED(new_block_count);