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 champs de texte statique.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1090 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -558,6 +558,13 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) {
|
||||
text_document.setDefaultFont(used_font);
|
||||
text_document.setPlainText(e.attribute("text"));
|
||||
|
||||
// Pivote le systeme de coordonnees du QPainter pour effectuer le rendu
|
||||
// dans le bon sens
|
||||
qreal default_rotation_angle = 0.0;
|
||||
if (QET::attributeIsAReal(e, "rotation", &default_rotation_angle)) {
|
||||
qp.rotate(default_rotation_angle);
|
||||
}
|
||||
|
||||
/*
|
||||
Deplace le systeme de coordonnees du QPainter pour effectuer le rendu au
|
||||
bon endroit ; note : on soustrait l'ascent() de la police pour
|
||||
|
||||
@@ -41,6 +41,11 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
#endif
|
||||
setPlainText(QObject::tr("T", "default text when adding a text in the element editor"));
|
||||
|
||||
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(contentsChanged()), this, SLOT(adjustItemPosition()));
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
@@ -58,11 +63,16 @@ void PartText::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()
|
||||
);
|
||||
known_position_ = pos();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,33 +86,25 @@ const QDomElement PartText::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());
|
||||
// angle de rotation du champ de texte
|
||||
if (rotationAngle()) {
|
||||
xml_element.setAttribute("rotation", QString("%1").arg(rotationAngle()));
|
||||
}
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
Retourne la position du texte, l'origine etant le point a gauche du texte,
|
||||
sur la baseline de la premiere ligne
|
||||
@return la position du texte
|
||||
@return l'angle de rotation de ce champ de texte
|
||||
*/
|
||||
QPointF PartText::pos() const {
|
||||
return(QGraphicsTextItem::pos() + margin());
|
||||
qreal PartText::rotationAngle() const {
|
||||
return(rotation());
|
||||
}
|
||||
|
||||
/**
|
||||
Specifie la position du texte statique
|
||||
@param left_corner_pos Nouvelle position
|
||||
@param angle Le nouvel angle de rotation de ce champ de texte
|
||||
*/
|
||||
void PartText::setPos(const QPointF &left_corner_pos) {
|
||||
QGraphicsTextItem::setPos(left_corner_pos - margin());
|
||||
}
|
||||
|
||||
/**
|
||||
Specifie la position du texte statique
|
||||
@param x abscisse de la nouvelle position
|
||||
@param y ordonnee de la nouvelle position
|
||||
*/
|
||||
void PartText::setPos(qreal x, qreal y) {
|
||||
QGraphicsTextItem::setPos(QPointF(x, y) - margin());
|
||||
void PartText::setRotationAngle(const qreal &angle) {
|
||||
setRotation(QET::correctAngle(angle));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,6 +178,7 @@ void PartText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
|
||||
* y : ordonnee de la position
|
||||
* size : taille du texte
|
||||
* text : texte
|
||||
* "rotation angle" : amgle de rotation
|
||||
@param value Valeur a attribuer a la propriete
|
||||
*/
|
||||
void PartText::setProperty(const QString &property, const QVariant &value) {
|
||||
@@ -188,9 +191,10 @@ 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());
|
||||
} else if (property == "rotation angle") {
|
||||
setRotationAngle(value.toDouble());
|
||||
}
|
||||
update();
|
||||
}
|
||||
@@ -202,17 +206,20 @@ void PartText::setProperty(const QString &property, const QVariant &value) {
|
||||
* y : ordonnee de la position
|
||||
* size : taille du texte
|
||||
* text : texte
|
||||
* "rotation angle" : amgle de rotation
|
||||
@return La valeur de la propriete property
|
||||
*/
|
||||
QVariant PartText::property(const QString &property) {
|
||||
if (property == "x") {
|
||||
return((scenePos() + margin()).x());
|
||||
return(pos().x());
|
||||
} else if (property == "y") {
|
||||
return((scenePos() + margin()).y());
|
||||
return(pos().y());
|
||||
} else if (property == "size") {
|
||||
return(font().pointSize());
|
||||
} else if (property == "text") {
|
||||
return(toPlainText());
|
||||
} else if (property == "rotation angle") {
|
||||
return(rotation());
|
||||
}
|
||||
return(QVariant());
|
||||
}
|
||||
@@ -224,9 +231,6 @@ QVariant PartText::property(const QString &property) {
|
||||
*/
|
||||
QVariant PartText::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||
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();
|
||||
} else if (change == QGraphicsItem::ItemSelectedHasChanged) {
|
||||
if (value.toBool() == true) {
|
||||
@@ -284,7 +288,12 @@ void PartText::paint(QPainter *painter, const QStyleOptionGraphicsItem *qsogi, Q
|
||||
*/
|
||||
void PartText::adjustItemPosition(int new_block_count) {
|
||||
Q_UNUSED(new_block_count);
|
||||
setPos(known_position_);
|
||||
QPointF origin_offset = margin();
|
||||
|
||||
QTransform base_translation;
|
||||
base_translation.translate(-origin_offset.x(), -origin_offset.y());
|
||||
setTransform(base_translation, false);
|
||||
setTransformOriginPoint(origin_offset);
|
||||
}
|
||||
|
||||
#ifdef QET_DEBUG_EDITOR_TEXTS
|
||||
|
||||
@@ -25,6 +25,8 @@ class TextEditor;
|
||||
dessin d'un element dans l'editeur d'element.
|
||||
*/
|
||||
class PartText : public QGraphicsTextItem, public CustomElementPart {
|
||||
Q_OBJECT
|
||||
|
||||
// constructeurs, destructeur
|
||||
public:
|
||||
PartText(QETElementEditor *, QGraphicsItem * = 0, ElementScene * = 0);
|
||||
@@ -45,16 +47,15 @@ class PartText : public QGraphicsTextItem, public CustomElementPart {
|
||||
virtual QString xmlName() const { return(QString("text")); }
|
||||
void fromXml(const QDomElement &);
|
||||
const QDomElement toXml(QDomDocument &) const;
|
||||
QPointF pos() const;
|
||||
void setPos(const QPointF &);
|
||||
void setPos(qreal, qreal);
|
||||
qreal rotationAngle() const;
|
||||
void setRotationAngle(const qreal &);
|
||||
virtual void setProperty(const QString &, const QVariant &);
|
||||
virtual QVariant property(const QString &);
|
||||
virtual bool isUseless() const;
|
||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0 );
|
||||
|
||||
public slots:
|
||||
void adjustItemPosition(int);
|
||||
void adjustItemPosition(int = 0);
|
||||
|
||||
protected:
|
||||
virtual void focusOutEvent(QFocusEvent *);
|
||||
@@ -68,6 +69,5 @@ class PartText : public QGraphicsTextItem, public CustomElementPart {
|
||||
void drawPoint(QPainter *, const QPointF &);
|
||||
#endif
|
||||
QString previous_text;
|
||||
QPointF known_position_;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
#include "texteditor.h"
|
||||
#include "parttext.h"
|
||||
#include "qetapp.h"
|
||||
#include "qtextorientationspinboxwidget.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -33,6 +35,9 @@ TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent
|
||||
qle_text = new QLineEdit();
|
||||
font_size = new QSpinBox();
|
||||
font_size -> setRange(0, 144);
|
||||
QLabel *rotation_angle_label = new QLabel(tr("Angle de rotation : "));
|
||||
rotation_angle_label -> setWordWrap(true);
|
||||
rotation_angle_ = QETApp::createTextOrientationSpinBoxWidget();
|
||||
|
||||
qle_x -> setValidator(new QDoubleValidator(qle_x));
|
||||
qle_y -> setValidator(new QDoubleValidator(qle_y));
|
||||
@@ -55,7 +60,13 @@ TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent
|
||||
QHBoxLayout *t = new QHBoxLayout();
|
||||
t -> addWidget(new QLabel(tr("Texte : ")));
|
||||
t -> addWidget(qle_text);
|
||||
|
||||
QHBoxLayout *rotation_angle_layout = new QHBoxLayout();
|
||||
rotation_angle_layout -> addWidget(rotation_angle_label);
|
||||
rotation_angle_layout -> addWidget(rotation_angle_);
|
||||
|
||||
main_layout -> addLayout(t);
|
||||
main_layout -> addLayout(rotation_angle_layout);
|
||||
main_layout -> addStretch();
|
||||
setLayout(main_layout);
|
||||
|
||||
@@ -115,6 +126,8 @@ void TextEditor::updateTextY() { addChangePartCommand(tr("ordonn\351e"), part, "
|
||||
void TextEditor::updateTextT() { addChangePartCommand(tr("contenu"), part, "text", qle_text -> text()); }
|
||||
/// Met a jour la taille du texte et cree un objet d'annulation
|
||||
void TextEditor::updateTextS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
||||
/// Met a jour l'angle de rotation du champ de texte et cree un objet d'annulation
|
||||
void TextEditor::updateTextRotationAngle() { addChangePartCommand(tr("angle de rotation"), part, "rotation angle", rotation_angle_ -> value()); }
|
||||
|
||||
/**
|
||||
Met a jour le formulaire a partir du champ de texte
|
||||
@@ -126,6 +139,7 @@ void TextEditor::updateForm() {
|
||||
qle_y -> setText(part -> property("y").toString());
|
||||
qle_text -> setText(part -> property("text").toString());
|
||||
font_size -> setValue(part -> property("size").toInt());
|
||||
rotation_angle_ -> setValue(part -> property("rotation angle").toDouble());
|
||||
activeConnections(true);
|
||||
}
|
||||
|
||||
@@ -135,10 +149,12 @@ void TextEditor::activeConnections(bool active) {
|
||||
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextY()));
|
||||
connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextT()));
|
||||
connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextS()));
|
||||
connect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextRotationAngle()));
|
||||
} else {
|
||||
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextX()));
|
||||
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextY()));
|
||||
disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextT()));
|
||||
disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextS()));
|
||||
disconnect(rotation_angle_, SIGNAL(editingFinished()), this, SLOT(updateTextRotationAngle()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <QtGui>
|
||||
#include "elementitemeditor.h"
|
||||
class PartText;
|
||||
class QTextOrientationSpinBoxWidget;
|
||||
/**
|
||||
Cette classe represente un editeur de champ de texte non editable
|
||||
Elle permet d'editer a travers une interface graphique les
|
||||
@@ -39,6 +40,7 @@ class TextEditor : public ElementItemEditor {
|
||||
PartText *part;
|
||||
QLineEdit *qle_x, *qle_y, *qle_text;
|
||||
QSpinBox *font_size;
|
||||
QTextOrientationSpinBoxWidget *rotation_angle_;
|
||||
|
||||
// methodes
|
||||
public:
|
||||
@@ -51,6 +53,7 @@ class TextEditor : public ElementItemEditor {
|
||||
void updateTextY();
|
||||
void updateTextT();
|
||||
void updateTextS();
|
||||
void updateTextRotationAngle();
|
||||
void updateForm();
|
||||
|
||||
private:
|
||||
|
||||
@@ -184,9 +184,9 @@ qreal ElementTextItem::originalRotationAngle() const {
|
||||
/**
|
||||
Cette methode s'assure que la position de l'ElementTextItem est coherente
|
||||
en ajustant :
|
||||
* la transformation de base qui permet de considerer que l'origine
|
||||
* la transformation de base qui permet de considerer que l'origine
|
||||
correspond au milieu du bord gauche du champ de texte
|
||||
* l'origine utilisee lors des appels a setRotation et setScale
|
||||
* l'origine utilisee lors des appels a setRotation et setScale
|
||||
@param new_block_count Nombre de blocs dans l'ElementTextItem
|
||||
*/
|
||||
void ElementTextItem::adjustItemPosition(int new_block_count) {
|
||||
|
||||
Reference in New Issue
Block a user