Il est desormais possible de pivoter les textes independants et les textes des conducteurs.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@798 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2009-11-29 21:56:48 +00:00
parent 121bd1f432
commit 5204ffe9ab
7 changed files with 84 additions and 10 deletions

View File

@@ -874,6 +874,7 @@ bool Conductor::fromXml(QDomElement &e) {
// recupere la "configuration" du conducteur
properties_.fromXml(e);
readProperties();
text_item -> setRotationAngle(e.attribute("rotation").toDouble());
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
// les segments non valides sont ignores
@@ -968,6 +969,9 @@ QDomElement Conductor::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_
// exporte la "configuration" du conducteur
properties_.toXml(e);
if (text_item -> rotationAngle()) {
e.setAttribute("rotation", QString("%1").arg(text_item -> rotationAngle()));
}
return(e);
}

View File

@@ -1070,7 +1070,9 @@ DiagramContent Diagram::selectedContent() {
*/
bool Diagram::canRotateSelection() const {
foreach(QGraphicsItem * qgi, selectedItems()) {
if (Element *e = qgraphicsitem_cast<Element *>(qgi)) {
if (/*DiagramTextItem *dti = */qgraphicsitem_cast<DiagramTextItem *>(qgi)) {
return(true);
} else if (Element *e = qgraphicsitem_cast<Element *>(qgi)) {
// l'element est-il pivotable ?
if (e -> orientation().current() != e -> orientation().next()) {
return(true);

View File

@@ -407,9 +407,10 @@ void ChangeDiagramTextCommand::redo() {
@param elements Elements a pivoter associes a leur orientation d'origine
@param parent QUndoCommand parent
*/
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, QUndoCommand *parent) :
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, QUndoCommand *parent) :
QUndoCommand(parent),
elements_to_rotate(elements)
elements_to_rotate(elements),
texts_to_rotate(texts)
{
setText(
QString(
@@ -417,7 +418,7 @@ RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orienta
"pivoter %1",
"undo caption - %1 is a sentence listing the rotated content"
)
).arg(QET::ElementsAndConductorsSentence(elements.count(), 0))
).arg(QET::ElementsAndConductorsSentence(elements.count(), 0, texts.count()))
);
}
@@ -430,6 +431,9 @@ void RotateElementsCommand::undo() {
foreach(Element *e, elements_to_rotate.keys()) {
e -> setOrientation(elements_to_rotate[e]);
}
foreach(DiagramTextItem *dti, texts_to_rotate) {
dti -> rotateBy(90.0);
}
}
/// refait le pivotement
@@ -438,6 +442,9 @@ void RotateElementsCommand::redo() {
e -> setOrientation(e -> orientation().next());
e -> update();
}
foreach(DiagramTextItem *dti, texts_to_rotate) {
dti -> rotateBy(-90.0);
}
}
/**

View File

@@ -232,7 +232,7 @@ class ChangeDiagramTextCommand : public QUndoCommand {
class RotateElementsCommand : public QUndoCommand {
// constructeurs, destructeur
public:
RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, QUndoCommand * = 0);
RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &, QUndoCommand * = 0);
virtual ~RotateElementsCommand();
private:
RotateElementsCommand(const RotateElementsCommand &);
@@ -246,6 +246,8 @@ class RotateElementsCommand : public QUndoCommand {
private:
/// elements pivotes associes a leur ancienne orientation
QHash<Element *, QET::Orientation> elements_to_rotate;
/// textes a pivoter
QList<DiagramTextItem *> texts_to_rotate;
};
/**

View File

@@ -25,7 +25,8 @@
@param scene La scene a laquelle appartient le champ de texte
*/
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
QGraphicsTextItem(parent, scene)
QGraphicsTextItem(parent, scene),
rotation_angle_(0.0)
{
setDefaultTextColor(Qt::black);
setFont(QETApp::diagramTextsFont());
@@ -41,7 +42,8 @@ DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
*/
DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) :
QGraphicsTextItem(text, parent, scene),
previous_text(text)
previous_text(text),
rotation_angle_(0.0)
{
setDefaultTextColor(Qt::black);
setFont(QETApp::diagramTextsFont());
@@ -58,6 +60,42 @@ Diagram *DiagramTextItem::diagram() const {
return(qobject_cast<Diagram *>(scene()));
}
/**
@return l'angle de rotation actuel de ce texte
*/
qreal DiagramTextItem::rotationAngle() const {
return(rotation_angle_);
}
/**
Permet de tourner le texte a un angle donne. La rotation s'effectue par
rapport au point (0, 0) du texte.
@param rotation Nouvel angle de rotation de ce texte
*/
void DiagramTextItem::setRotationAngle(const qreal &rotation) {
// ramene l'angle demande entre -360.0 et +360.0 degres
qreal applied_rotation = rotation;
while (applied_rotation < -360.0) applied_rotation += 360.0;
while (applied_rotation > 360.0) applied_rotation -= 360.0;
rotate(applied_rotation - rotation_angle_);
rotation_angle_ = applied_rotation;
}
/**
Ajoute
@param added_rotation Angle a ajouter a la rotation actuelle
*/
void DiagramTextItem::rotateBy(const qreal &added_rotation) {
// ramene l'angle demande entre -360.0 et +360.0 degres
qreal applied_added_rotation = added_rotation;
while (applied_added_rotation < 360.0) applied_added_rotation += 360.0;
while (applied_added_rotation > 360.0) applied_added_rotation -= 360.0;
rotation_angle_ += applied_added_rotation;
rotate(applied_added_rotation);
}
/**
gere la perte de focus du champ de texte
*/
@@ -91,6 +129,7 @@ void DiagramTextItem::fromXml(const QDomElement &e) {
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
setPlainText(e.attribute("text"));
previous_text = e.attribute("text");
setRotationAngle(e.attribute("rotation").toDouble());
}
/**
@@ -102,6 +141,9 @@ QDomElement DiagramTextItem::toXml(QDomDocument &document) const {
result.setAttribute("x", QString("%1").arg(pos().x()));
result.setAttribute("y", QString("%1").arg(pos().y()));
result.setAttribute("text", toPlainText());
if (rotation_angle_) {
result.setAttribute("rotation", QString("%1").arg(rotation_angle_));
}
return(result);
}

View File

@@ -48,6 +48,9 @@ class DiagramTextItem : public QGraphicsTextItem {
virtual QDomElement toXml(QDomDocument &) const;
virtual void setPos(const QPointF &);
virtual void setPos(qreal, qreal);
qreal rotationAngle() const;
void setRotationAngle(const qreal &);
void rotateBy(const qreal &);
protected:
virtual void focusOutEvent(QFocusEvent *);
@@ -66,5 +69,10 @@ class DiagramTextItem : public QGraphicsTextItem {
// slots
public slots:
void setNonFocusable();
// attributs prives
private:
/// angle de rotation du champ de texte
qreal rotation_angle_;
};
#endif

View File

@@ -23,6 +23,7 @@
#include "diagramcommands.h"
#include "diagramposition.h"
#include "conductorpropertieswidget.h"
#include "elementtextitem.h"
#include "insetpropertieswidget.h"
#include "qetapp.h"
#include "qetproject.h"
@@ -114,14 +115,22 @@ void DiagramView::deleteSelection() {
*/
void DiagramView::rotateSelection() {
if (scene -> isReadOnly()) return;
// recupere les elements et les champs de texte a pivoter
QHash<Element *, QET::Orientation> elements_to_rotate;
QList<DiagramTextItem *> texts_to_rotate;
foreach (QGraphicsItem *item, scene -> selectedItems()) {
if (Element *e = qgraphicsitem_cast<Element *>(item)) {
elements_to_rotate.insert(e, e -> orientation().current());
}
} else if (DiagramTextItem *dti = qgraphicsitem_cast<DiagramTextItem *>(item)) {
texts_to_rotate << dti;
} /*else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(item)) {
}*/
}
if (elements_to_rotate.isEmpty()) return;
scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate));
// effectue les rotations s'il y a quelque chose a pivoter
if (elements_to_rotate.isEmpty() && texts_to_rotate.isEmpty()) return;
scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate, texts_to_rotate));
}
/**