Correction de problemes de positionnement des champs de texte des elements.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@824 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2010-01-01 14:41:15 +00:00
parent e36312285c
commit 6562436063
3 changed files with 55 additions and 16 deletions

View File

@@ -38,6 +38,9 @@ PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QG
setPlainText(QObject::tr("_", "default text when adding a textfield in the element editor")); setPlainText(QObject::tr("_", "default text when adding a textfield in the element editor"));
infos = new TextFieldEditor(elementEditor(), this); infos = new TextFieldEditor(elementEditor(), this);
infos -> setElementTypeName(name()); infos -> setElementTypeName(name());
// ajuste la position du champ de texte lorsqu'on lui ajoute/retire des lignes
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
} }
/// Destructeur /// Destructeur
@@ -67,6 +70,7 @@ void PartTextField::fromXml(const QDomElement &xml_element) {
xml_element.attribute("x").toDouble(), xml_element.attribute("x").toDouble(),
xml_element.attribute("y").toDouble() xml_element.attribute("y").toDouble()
); );
known_position_ = pos();
follow_parent_rotations = (xml_element.attribute("rotate") == "true"); follow_parent_rotations = (xml_element.attribute("rotate") == "true");
} }
@@ -106,7 +110,7 @@ QWidget *PartTextField::elementInformations() {
@return la position du texte @return la position du texte
*/ */
QPointF PartTextField::pos() const { QPointF PartTextField::pos() const {
return(QGraphicsTextItem::pos() + margin()); return(mapToScene(margin()));
} }
/** /**
@@ -114,7 +118,15 @@ QPointF PartTextField::pos() const {
@param new_pos Nouvelle position @param new_pos Nouvelle position
*/ */
void PartTextField::setPos(const QPointF &new_pos) { void PartTextField::setPos(const QPointF &new_pos) {
QGraphicsTextItem::setPos(new_pos - margin()); // annule toute transformation (rotation notamment)
resetTransform();
// effectue le positionnement en lui-meme
QPointF m = margin();
QGraphicsTextItem::setPos(new_pos - m);
// applique a nouveau la rotation du champ de texte
setTransform(QTransform().translate(m.x(), m.y()).rotate(rotation_angle_).translate(-m.x(), -m.y()));
} }
/** /**
@@ -123,7 +135,7 @@ void PartTextField::setPos(const QPointF &new_pos) {
@param y ordonnee de la nouvelle position @param y ordonnee de la nouvelle position
*/ */
void PartTextField::setPos(qreal x, qreal y) { void PartTextField::setPos(qreal x, qreal y) {
QGraphicsTextItem::setPos(QPointF(x, y) - margin()); PartTextField::setPos(QPointF(x, y));
} }
/** /**
@@ -137,18 +149,13 @@ qreal PartTextField::rotationAngle() const {
@param angle Le nouvel angle de rotation de ce champ de texte @param angle Le nouvel angle de rotation de ce champ de texte
*/ */
void PartTextField::setRotationAngle(const qreal &angle) { void PartTextField::setRotationAngle(const qreal &angle) {
rotation_angle_ = QET::correctAngle(angle); qreal applied_rotation = QET::correctAngle(angle);
// annule toute rotation precedente QPointF t = margin();
resetTransform(); translate(t.x(), t.y());
rotate(applied_rotation - rotation_angle_);
QPointF pos_margin = margin(); rotation_angle_ = applied_rotation;
QTransform rotation; translate(-t.x(), -t.y());
rotation.translate(pos_margin.x(), pos_margin.y());
rotation.rotate(rotation_angle_);
rotation.translate(-pos_margin.x(), -pos_margin.y());
QGraphicsTextItem::setTransform(rotation, true);
} }
/** /**
@@ -279,8 +286,15 @@ QVariant PartTextField::property(const QString &property) {
*/ */
QVariant PartTextField::itemChange(GraphicsItemChange change, const QVariant &value) { QVariant PartTextField::itemChange(GraphicsItemChange change, const QVariant &value) {
if (scene()) { if (scene()) {
if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { if (change == QGraphicsItem::ItemPositionHasChanged) {
// 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(); infos -> updateForm();
} else if (change == QGraphicsItem::ItemSelectedHasChanged) {
if (value.toBool() == true) {
infos -> updateForm();
}
} }
} }
return(QGraphicsTextItem::itemChange(change, value)); return(QGraphicsTextItem::itemChange(change, value));
@@ -326,6 +340,18 @@ void PartTextField::paint(QPainter *painter, const QStyleOptionGraphicsItem *qso
#endif #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_bloc_count Nombre de blocs dans l'ElementTextItem
*/
void PartTextField::adjustItemPosition(int new_block_count) {
Q_UNUSED(new_block_count);
setPos(known_position_);
}
#ifdef QET_DEBUG_EDITOR_TEXTS #ifdef QET_DEBUG_EDITOR_TEXTS
/** /**
Dessine deux petites fleches pour mettre un point en valeur Dessine deux petites fleches pour mettre un point en valeur

View File

@@ -28,6 +28,8 @@ class QETElementEditor;
lorsque l'element sera pose sur un schema. lorsque l'element sera pose sur un schema.
*/ */
class PartTextField : public QGraphicsTextItem, public CustomElementPart { class PartTextField : public QGraphicsTextItem, public CustomElementPart {
Q_OBJECT
// constructeurs, destructeur // constructeurs, destructeur
public: public:
PartTextField(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); PartTextField(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0);
@@ -65,6 +67,9 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
virtual bool isUseless() const; virtual bool isUseless() const;
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0 ); virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0 );
public slots:
void adjustItemPosition(int);
protected: protected:
virtual void focusOutEvent(QFocusEvent *); virtual void focusOutEvent(QFocusEvent *);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
@@ -77,5 +82,6 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
void drawPoint(QPainter *, const QPointF &); void drawPoint(QPainter *, const QPointF &);
#endif #endif
QString previous_text; QString previous_text;
QPointF known_position_;
}; };
#endif #endif

View File

@@ -65,9 +65,16 @@ ElementTextItem::~ElementTextItem() {
@param pos La nouvelle position du champ de texte @param pos La nouvelle position du champ de texte
*/ */
void ElementTextItem::setPos(const QPointF &pos) { void ElementTextItem::setPos(const QPointF &pos) {
// annule toute transformation (rotation notamment)
resetTransform();
// effectue le positionnement en lui-meme
QPointF actual_pos = pos; QPointF actual_pos = pos;
actual_pos -= QPointF(0.0, boundingRect().bottom() / 2.0); actual_pos -= QPointF(0.0, boundingRect().bottom() / 2.0);
QGraphicsTextItem::setPos(actual_pos); QGraphicsTextItem::setPos(actual_pos);
// applique a nouveau la rotation du champ de texte
applyRotation(rotationAngle());
} }
/** /**
@@ -159,7 +166,7 @@ qreal ElementTextItem::originalRotationAngle() const {
en repositionnant son origine (c-a-d le milieu du bord gauche du champ de 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 texte) a la position originale. Cela est notamment utile lorsque le champ
de texte est agrandi ou retreci verticalement (ajout ou retrait de lignes). 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 l'ElementTextItem
@see originalPos() @see originalPos()
*/ */
void ElementTextItem::adjustItemPosition(int new_block_count) { void ElementTextItem::adjustItemPosition(int new_block_count) {