mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
Il est desormais possible de pivoter les textes dynamiques des elements dans l'editeur d'element.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@818 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -29,7 +29,8 @@
|
|||||||
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());
|
||||||
@@ -56,6 +57,12 @@ void PartTextField::fromXml(const QDomElement &xml_element) {
|
|||||||
|
|
||||||
setFont(QETApp::diagramTextsFont(font_size));
|
setFont(QETApp::diagramTextsFont(font_size));
|
||||||
setPlainText(xml_element.attribute("text"));
|
setPlainText(xml_element.attribute("text"));
|
||||||
|
|
||||||
|
qreal default_rotation_angle = 0.0;
|
||||||
|
if (QET::attributeIsAReal(xml_element, "rotation", &default_rotation_angle)) {
|
||||||
|
setRotationAngle(default_rotation_angle);
|
||||||
|
}
|
||||||
|
|
||||||
setPos(
|
setPos(
|
||||||
xml_element.attribute("x").toDouble(),
|
xml_element.attribute("x").toDouble(),
|
||||||
xml_element.attribute("y").toDouble()
|
xml_element.attribute("y").toDouble()
|
||||||
@@ -75,7 +82,14 @@ const QDomElement PartTextField::toXml(QDomDocument &xml_document) const {
|
|||||||
xml_element.setAttribute("y", QString("%1").arg(pos().y()));
|
xml_element.setAttribute("y", QString("%1").arg(pos().y()));
|
||||||
xml_element.setAttribute("text", toPlainText());
|
xml_element.setAttribute("text", toPlainText());
|
||||||
xml_element.setAttribute("size", font().pointSize());
|
xml_element.setAttribute("size", font().pointSize());
|
||||||
if (follow_parent_rotations) xml_element.setAttribute("rotate", "true");
|
// angle de rotation du champ de texte
|
||||||
|
if (rotationAngle()) {
|
||||||
|
xml_element.setAttribute("rotation", QString("%1").arg(rotationAngle()));
|
||||||
|
}
|
||||||
|
// suivi (ou non) des rotations de l'element parent par le champ de texte
|
||||||
|
if (follow_parent_rotations) {
|
||||||
|
xml_element.setAttribute("rotate", "true");
|
||||||
|
}
|
||||||
return(xml_element);
|
return(xml_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +126,31 @@ void PartTextField::setPos(qreal x, qreal y) {
|
|||||||
QGraphicsTextItem::setPos(QPointF(x, y) - margin());
|
QGraphicsTextItem::setPos(QPointF(x, y) - margin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return l'angle de rotation de ce champ de texte
|
||||||
|
*/
|
||||||
|
qreal PartTextField::rotationAngle() const {
|
||||||
|
return(rotation_angle_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param angle Le nouvel angle de rotation de ce champ de texte
|
||||||
|
*/
|
||||||
|
void PartTextField::setRotationAngle(const qreal &angle) {
|
||||||
|
rotation_angle_ = QET::correctAngle(angle);
|
||||||
|
|
||||||
|
// annule toute rotation precedente
|
||||||
|
resetTransform();
|
||||||
|
|
||||||
|
QPointF pos_margin = margin();
|
||||||
|
QTransform rotation;
|
||||||
|
rotation.translate(pos_margin.x(), pos_margin.y());
|
||||||
|
rotation.rotate(rotation_angle_);
|
||||||
|
rotation.translate(-pos_margin.x(), -pos_margin.y());
|
||||||
|
|
||||||
|
QGraphicsTextItem::setTransform(rotation, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return true si le champ de texte suit les rotation de l'element, false
|
@return true si le champ de texte suit les rotation de l'element, false
|
||||||
sinon
|
sinon
|
||||||
@@ -197,6 +236,8 @@ void PartTextField::setProperty(const QString &property, const QVariant &value)
|
|||||||
setFont(QETApp::diagramTextsFont(value.toInt()));
|
setFont(QETApp::diagramTextsFont(value.toInt()));
|
||||||
} else if (property == "text") {
|
} else if (property == "text") {
|
||||||
setPlainText(value.toString());
|
setPlainText(value.toString());
|
||||||
|
} else if (property == "rotation angle") {
|
||||||
|
setRotationAngle(value.toDouble());
|
||||||
} else if (property == "rotate") {
|
} else if (property == "rotate") {
|
||||||
follow_parent_rotations = value.toBool();
|
follow_parent_rotations = value.toBool();
|
||||||
}
|
}
|
||||||
@@ -222,6 +263,8 @@ QVariant PartTextField::property(const QString &property) {
|
|||||||
return(font().pointSize());
|
return(font().pointSize());
|
||||||
} else if (property == "text") {
|
} else if (property == "text") {
|
||||||
return(toPlainText());
|
return(toPlainText());
|
||||||
|
} else if (property == "rotation angle") {
|
||||||
|
return(rotation_angle_);
|
||||||
} else if (property == "rotate") {
|
} else if (property == "rotate") {
|
||||||
return(follow_parent_rotations);
|
return(follow_parent_rotations);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
// attributs
|
// attributs
|
||||||
TextFieldEditor *infos;
|
TextFieldEditor *infos;
|
||||||
bool follow_parent_rotations;
|
bool follow_parent_rotations;
|
||||||
|
qreal rotation_angle_;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
@@ -55,6 +56,8 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
QPointF pos() const;
|
QPointF pos() const;
|
||||||
void setPos(const QPointF &);
|
void setPos(const QPointF &);
|
||||||
void setPos(qreal, qreal);
|
void setPos(qreal, qreal);
|
||||||
|
qreal rotationAngle() const;
|
||||||
|
void setRotationAngle(const qreal &);
|
||||||
bool followParentRotations();
|
bool followParentRotations();
|
||||||
void setFollowParentRotations(bool);
|
void setFollowParentRotations(bool);
|
||||||
virtual void setProperty(const QString &, const QVariant &);
|
virtual void setProperty(const QString &, const QVariant &);
|
||||||
|
|||||||
@@ -32,8 +32,12 @@ TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfi
|
|||||||
qle_text = new QLineEdit();
|
qle_text = new QLineEdit();
|
||||||
font_size = new QSpinBox();
|
font_size = new QSpinBox();
|
||||||
font_size -> setRange(0, 144);
|
font_size -> setRange(0, 144);
|
||||||
rotate = new QCheckBox(tr("Maintenir horizontal malgr\351\n les rotations de l'\351l\351ment"));
|
rotate = new QCheckBox(tr("Ne pas subir les rotations de l'\351l\351ment parent"));
|
||||||
rotate -> setChecked(true);
|
rotate -> setChecked(true);
|
||||||
|
rotation_angle_ = new QDoubleSpinBox();
|
||||||
|
rotation_angle_ -> setRange(-360.0, 360.0);
|
||||||
|
rotation_angle_ -> setSingleStep(-90.0);
|
||||||
|
rotation_angle_ -> setSuffix("\260");
|
||||||
|
|
||||||
qle_x -> setValidator(new QDoubleValidator(qle_x));
|
qle_x -> setValidator(new QDoubleValidator(qle_x));
|
||||||
qle_y -> setValidator(new QDoubleValidator(qle_y));
|
qle_y -> setValidator(new QDoubleValidator(qle_y));
|
||||||
@@ -58,6 +62,11 @@ TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfi
|
|||||||
t -> addWidget(qle_text);
|
t -> addWidget(qle_text);
|
||||||
main_layout -> addLayout(t);
|
main_layout -> addLayout(t);
|
||||||
|
|
||||||
|
QHBoxLayout *rotation_angle_layout = new QHBoxLayout();
|
||||||
|
rotation_angle_layout -> addWidget(new QLabel(tr("Angle de rotation par d\351faut : ")));
|
||||||
|
rotation_angle_layout -> addWidget(rotation_angle_);
|
||||||
|
main_layout -> addLayout(rotation_angle_layout);
|
||||||
|
|
||||||
QHBoxLayout *r = new QHBoxLayout();
|
QHBoxLayout *r = new QHBoxLayout();
|
||||||
r -> addWidget(rotate);
|
r -> addWidget(rotate);
|
||||||
main_layout -> addLayout(r);
|
main_layout -> addLayout(r);
|
||||||
@@ -91,6 +100,8 @@ void TextFieldEditor::updateTextFieldT() { addChangePartCommand(tr("contenu"),
|
|||||||
void TextFieldEditor::updateTextFieldS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
void TextFieldEditor::updateTextFieldS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
||||||
/// Met a jour la taille du champ de texte et cree un objet d'annulation
|
/// Met a jour la taille du champ de texte et cree un objet d'annulation
|
||||||
void TextFieldEditor::updateTextFieldR() { addChangePartCommand(tr("propri\351t\351"), part, "rotate", !rotate -> isChecked()); }
|
void TextFieldEditor::updateTextFieldR() { addChangePartCommand(tr("propri\351t\351"), part, "rotate", !rotate -> isChecked()); }
|
||||||
|
/// Met a jour l'angle de rotation du champ de texte et cree un objet d'annulation
|
||||||
|
void TextFieldEditor::updateTextFieldRotationAngle() { addChangePartCommand(tr("angle de rotation"), part, "rotation angle", rotation_angle_ -> value()); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met a jour le formulaire d'edition
|
Met a jour le formulaire d'edition
|
||||||
@@ -102,6 +113,7 @@ void TextFieldEditor::updateForm() {
|
|||||||
qle_text -> setText(part -> property("text").toString());
|
qle_text -> setText(part -> property("text").toString());
|
||||||
font_size -> setValue(part -> property("size").toInt());
|
font_size -> setValue(part -> property("size").toInt());
|
||||||
rotate -> setChecked(!part -> property("rotate").toBool());
|
rotate -> setChecked(!part -> property("rotate").toBool());
|
||||||
|
rotation_angle_ -> setValue(part -> property("rotation angle").toInt());
|
||||||
activeConnections(true);
|
activeConnections(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,11 +128,13 @@ void TextFieldEditor::activeConnections(bool active) {
|
|||||||
connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT()));
|
connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT()));
|
||||||
connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS()));
|
connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS()));
|
||||||
connect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR()));
|
connect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR()));
|
||||||
|
connect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextFieldRotationAngle()));
|
||||||
} else {
|
} else {
|
||||||
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextFieldX()));
|
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextFieldX()));
|
||||||
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextFieldY()));
|
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextFieldY()));
|
||||||
disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT()));
|
disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT()));
|
||||||
disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS()));
|
disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS()));
|
||||||
disconnect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR()));
|
disconnect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR()));
|
||||||
|
disconnect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextFieldRotationAngle()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class TextFieldEditor : public ElementItemEditor {
|
|||||||
QLineEdit *qle_x, *qle_y, *qle_text;
|
QLineEdit *qle_x, *qle_y, *qle_text;
|
||||||
QSpinBox *font_size;
|
QSpinBox *font_size;
|
||||||
QCheckBox *rotate;
|
QCheckBox *rotate;
|
||||||
|
QDoubleSpinBox *rotation_angle_;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public slots:
|
public slots:
|
||||||
@@ -50,6 +51,7 @@ class TextFieldEditor : public ElementItemEditor {
|
|||||||
void updateTextFieldT();
|
void updateTextFieldT();
|
||||||
void updateTextFieldS();
|
void updateTextFieldS();
|
||||||
void updateTextFieldR();
|
void updateTextFieldR();
|
||||||
|
void updateTextFieldRotationAngle();
|
||||||
void updateForm();
|
void updateForm();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user