mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Editeur d'elements : mise a jour de la gestion du positionnement et de la rotation des champs de texte dynamiques.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1089 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -29,8 +29,7 @@
|
|||||||
PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) :
|
PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) :
|
||||||
QGraphicsTextItem(parent, scene),
|
QGraphicsTextItem(parent, scene),
|
||||||
CustomElementPart(editor),
|
CustomElementPart(editor),
|
||||||
follow_parent_rotations(true),
|
follow_parent_rotations(true)
|
||||||
rotation_angle_(0.0)
|
|
||||||
{
|
{
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QETApp::diagramTextsFont());
|
setFont(QETApp::diagramTextsFont());
|
||||||
@@ -40,8 +39,10 @@ PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QG
|
|||||||
#endif
|
#endif
|
||||||
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"));
|
||||||
|
|
||||||
// ajuste la position du champ de texte lorsqu'on lui ajoute/retire des lignes
|
adjustItemPosition(1);
|
||||||
|
// ajuste la position du champ de texte lorsqu'on lui ajoute/retire des lignes ou lorsqu'on change sa taille de police
|
||||||
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
|
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
|
||||||
|
connect(document(), SIGNAL(contentsChanged()), this, SLOT(adjustItemPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -69,7 +70,6 @@ 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");
|
||||||
}
|
}
|
||||||
@@ -96,58 +96,18 @@ const QDomElement PartTextField::toXml(QDomDocument &xml_document) const {
|
|||||||
return(xml_element);
|
return(xml_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Retourne la position du texte, l'origine etant le milieu du bord gauche du
|
|
||||||
champ
|
|
||||||
@return la position du texte
|
|
||||||
*/
|
|
||||||
QPointF PartTextField::pos() const {
|
|
||||||
return(mapToScene(margin()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Specifie la position du champ de texte
|
|
||||||
@param new_pos Nouvelle position
|
|
||||||
*/
|
|
||||||
void PartTextField::setPos(const QPointF &new_pos) {
|
|
||||||
// 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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Specifie la position du champ de texte
|
|
||||||
@param x abscisse de la nouvelle position
|
|
||||||
@param y ordonnee de la nouvelle position
|
|
||||||
*/
|
|
||||||
void PartTextField::setPos(qreal x, qreal y) {
|
|
||||||
PartTextField::setPos(QPointF(x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return l'angle de rotation de ce champ de texte
|
@return l'angle de rotation de ce champ de texte
|
||||||
*/
|
*/
|
||||||
qreal PartTextField::rotationAngle() const {
|
qreal PartTextField::rotationAngle() const {
|
||||||
return(rotation_angle_);
|
return(rotation());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@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) {
|
||||||
qreal applied_rotation = QET::correctAngle(angle);
|
setRotation(QET::correctAngle(angle));
|
||||||
|
|
||||||
QPointF t = margin();
|
|
||||||
translate(t.x(), t.y());
|
|
||||||
rotate(applied_rotation - rotation_angle_);
|
|
||||||
rotation_angle_ = applied_rotation;
|
|
||||||
translate(-t.x(), -t.y());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,7 +194,6 @@ void PartTextField::setProperty(const QString &property, const QVariant &value)
|
|||||||
} else if (property == "size") {
|
} else if (property == "size") {
|
||||||
if (!value.canConvert(QVariant::Int)) return;
|
if (!value.canConvert(QVariant::Int)) return;
|
||||||
setFont(QETApp::diagramTextsFont(value.toInt()));
|
setFont(QETApp::diagramTextsFont(value.toInt()));
|
||||||
adjustItemPosition(0);
|
|
||||||
} else if (property == "text") {
|
} else if (property == "text") {
|
||||||
setPlainText(value.toString());
|
setPlainText(value.toString());
|
||||||
} else if (property == "rotation angle") {
|
} else if (property == "rotation angle") {
|
||||||
@@ -265,7 +224,7 @@ QVariant PartTextField::property(const QString &property) {
|
|||||||
} else if (property == "text") {
|
} else if (property == "text") {
|
||||||
return(toPlainText());
|
return(toPlainText());
|
||||||
} else if (property == "rotation angle") {
|
} else if (property == "rotation angle") {
|
||||||
return(rotation_angle_);
|
return(rotation());
|
||||||
} else if (property == "rotate") {
|
} else if (property == "rotate") {
|
||||||
return(follow_parent_rotations);
|
return(follow_parent_rotations);
|
||||||
}
|
}
|
||||||
@@ -279,9 +238,6 @@ QVariant PartTextField::property(const QString &property) {
|
|||||||
*/
|
*/
|
||||||
QVariant PartTextField::itemChange(GraphicsItemChange change, const QVariant &value) {
|
QVariant PartTextField::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||||
if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged) {
|
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();
|
|
||||||
updateCurrentPartEditor();
|
updateCurrentPartEditor();
|
||||||
} else if (change == QGraphicsItem::ItemSelectedHasChanged) {
|
} else if (change == QGraphicsItem::ItemSelectedHasChanged) {
|
||||||
if (value.toBool() == true) {
|
if (value.toBool() == true) {
|
||||||
@@ -340,7 +296,12 @@ void PartTextField::paint(QPainter *painter, const QStyleOptionGraphicsItem *qso
|
|||||||
*/
|
*/
|
||||||
void PartTextField::adjustItemPosition(int new_block_count) {
|
void PartTextField::adjustItemPosition(int new_block_count) {
|
||||||
Q_UNUSED(new_block_count);
|
Q_UNUSED(new_block_count);
|
||||||
setPos(known_position_);
|
qreal origin_offset = boundingRect().bottom() / 2.0;
|
||||||
|
|
||||||
|
QTransform base_translation;
|
||||||
|
base_translation.translate(0.0, -origin_offset);
|
||||||
|
setTransform(base_translation, false);
|
||||||
|
setTransformOriginPoint(0.0, origin_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef QET_DEBUG_EDITOR_TEXTS
|
#ifdef QET_DEBUG_EDITOR_TEXTS
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
bool follow_parent_rotations;
|
bool follow_parent_rotations;
|
||||||
qreal rotation_angle_;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
@@ -54,9 +53,6 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
virtual QString xmlName() const { return(QString("input")); }
|
virtual QString xmlName() const { return(QString("input")); }
|
||||||
void fromXml(const QDomElement &);
|
void fromXml(const QDomElement &);
|
||||||
const QDomElement toXml(QDomDocument &) const;
|
const QDomElement toXml(QDomDocument &) const;
|
||||||
QPointF pos() const;
|
|
||||||
void setPos(const QPointF &);
|
|
||||||
void setPos(qreal, qreal);
|
|
||||||
qreal rotationAngle() const;
|
qreal rotationAngle() const;
|
||||||
void setRotationAngle(const qreal &);
|
void setRotationAngle(const qreal &);
|
||||||
bool followParentRotations();
|
bool followParentRotations();
|
||||||
@@ -67,7 +63,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0 );
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0 );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void adjustItemPosition(int);
|
void adjustItemPosition(int = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void focusOutEvent(QFocusEvent *);
|
virtual void focusOutEvent(QFocusEvent *);
|
||||||
@@ -81,6 +77,5 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user