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:
xavier
2009-12-20 01:59:44 +00:00
parent 4b1a2882cb
commit 635c16084a
4 changed files with 65 additions and 3 deletions

View File

@@ -29,7 +29,8 @@
PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) :
QGraphicsTextItem(parent, scene),
CustomElementPart(editor),
follow_parent_rotations(true)
follow_parent_rotations(true),
rotation_angle_(0.0)
{
setDefaultTextColor(Qt::black);
setFont(QETApp::diagramTextsFont());
@@ -56,6 +57,12 @@ void PartTextField::fromXml(const QDomElement &xml_element) {
setFont(QETApp::diagramTextsFont(font_size));
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(
xml_element.attribute("x").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("text", toPlainText());
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);
}
@@ -112,6 +126,31 @@ void PartTextField::setPos(qreal x, qreal y) {
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
sinon
@@ -197,6 +236,8 @@ void PartTextField::setProperty(const QString &property, const QVariant &value)
setFont(QETApp::diagramTextsFont(value.toInt()));
} else if (property == "text") {
setPlainText(value.toString());
} else if (property == "rotation angle") {
setRotationAngle(value.toDouble());
} else if (property == "rotate") {
follow_parent_rotations = value.toBool();
}
@@ -222,6 +263,8 @@ QVariant PartTextField::property(const QString &property) {
return(font().pointSize());
} else if (property == "text") {
return(toPlainText());
} else if (property == "rotation angle") {
return(rotation_angle_);
} else if (property == "rotate") {
return(follow_parent_rotations);
}

View File

@@ -39,6 +39,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
// attributs
TextFieldEditor *infos;
bool follow_parent_rotations;
qreal rotation_angle_;
// methodes
public:
@@ -55,6 +56,8 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
QPointF pos() const;
void setPos(const QPointF &);
void setPos(qreal, qreal);
qreal rotationAngle() const;
void setRotationAngle(const qreal &);
bool followParentRotations();
void setFollowParentRotations(bool);
virtual void setProperty(const QString &, const QVariant &);

View File

@@ -32,8 +32,12 @@ TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfi
qle_text = new QLineEdit();
font_size = new QSpinBox();
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);
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_y -> setValidator(new QDoubleValidator(qle_y));
@@ -58,6 +62,11 @@ TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfi
t -> addWidget(qle_text);
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();
r -> addWidget(rotate);
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()); }
/// 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()); }
/// 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
@@ -102,6 +113,7 @@ void TextFieldEditor::updateForm() {
qle_text -> setText(part -> property("text").toString());
font_size -> setValue(part -> property("size").toInt());
rotate -> setChecked(!part -> property("rotate").toBool());
rotation_angle_ -> setValue(part -> property("rotation angle").toInt());
activeConnections(true);
}
@@ -116,11 +128,13 @@ void TextFieldEditor::activeConnections(bool active) {
connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT()));
connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS()));
connect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR()));
connect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextFieldRotationAngle()));
} else {
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextFieldX()));
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextFieldY()));
disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT()));
disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS()));
disconnect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR()));
disconnect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextFieldRotationAngle()));
}
}

View File

@@ -41,6 +41,7 @@ class TextFieldEditor : public ElementItemEditor {
QLineEdit *qle_x, *qle_y, *qle_text;
QSpinBox *font_size;
QCheckBox *rotate;
QDoubleSpinBox *rotation_angle_;
// methodes
public slots:
@@ -50,6 +51,7 @@ class TextFieldEditor : public ElementItemEditor {
void updateTextFieldT();
void updateTextFieldS();
void updateTextFieldR();
void updateTextFieldRotationAngle();
void updateForm();
private: