Remise en place de la contre-rotation pour les champs de texte rattaches a un element et ne presentant pas l'option "FollowParentRotation"

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1082 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2010-07-18 01:46:30 +00:00
parent 4fd8b390c5
commit 0031d51b01
6 changed files with 49 additions and 57 deletions

View File

@@ -598,7 +598,7 @@ RotateElementsCommand::~RotateElementsCommand() {
/// defait le pivotement
void RotateElementsCommand::undo() {
foreach(Element *e, elements_to_rotate.keys()) {
e -> setOrientation(elements_to_rotate[e]);
rotateElement(e, elements_to_rotate[e]);
}
foreach(DiagramTextItem *dti, texts_to_rotate) {
dti -> rotateBy(-applied_rotation_angle_);
@@ -608,8 +608,7 @@ void RotateElementsCommand::undo() {
/// refait le pivotement
void RotateElementsCommand::redo() {
foreach(Element *e, elements_to_rotate.keys()) {
e -> setOrientation(e -> orientation().next());
e -> update();
rotateElement(e, e -> orientation().next());
}
foreach(DiagramTextItem *dti, texts_to_rotate) {
dti -> rotateBy(applied_rotation_angle_);
@@ -630,6 +629,36 @@ void RotateElementsCommand::setAppliedRotationAngle(const qreal &angle) {
applied_rotation_angle_ = QET::correctAngle(angle);
}
/**
Passe un element a une orientation donnee, en prenant soin de gerer ses textes enfants
@param element Element a orienter soigneusement
@param orientation Nouvelle orientation de l'element
*/
void RotateElementsCommand::rotateElement(Element *element, QET::Orientation orientation) {
qreal rotation_value = 90.0 * (orientation - element -> orientation().current());
element -> setOrientation(orientation);
element -> update();
if (rotation_value) {
// repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations"
foreach(ElementTextItem *eti, element -> texts()) {
if (!eti -> followParentRotations()) {
// on souhaite pivoter le champ de texte par rapport a son centre
QPointF eti_center = eti -> boundingRect().center();
// pour ce faire, on repere la position de son centre par rapport a son parent
QPointF parent_eti_center_before = eti -> mapToParent(eti_center);
// on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte
eti -> rotateBy(-rotation_value);
// on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent
QPointF parent_eti_center_after = eti -> mapToParent(eti_center);
// on determine la translation a appliquer
QPointF eti_translation = parent_eti_center_before - parent_eti_center_after;
// on applique cette translation
eti -> setPos(eti -> pos() + eti_translation);
}
}
}
}
/**
Constructeur
@param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action

View File

@@ -319,6 +319,8 @@ class RotateElementsCommand : public QUndoCommand {
virtual void redo();
qreal appliedRotationAngle() const;
void setAppliedRotationAngle(const qreal &);
private:
void rotateElement(Element *, QET::Orientation);
// attributs
private:

View File

@@ -249,14 +249,14 @@ void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
}
/**
Effetue la rotation du texte en elle-meme
Effectue la rotation du texte en elle-meme
Pour les DiagramTextItem, la rotation s'effectue autour du point (0, 0).
Cette methode peut toutefois etre redefinie dans des classes
Cette methode peut toutefois etre redefinie dans des classes filles
@param angle Angle de la rotation a effectuer
*/
void DiagramTextItem::applyRotation(const qreal &angle) {
// un simple appel a QGraphicsTextItem::rotate suffit
QGraphicsTextItem::rotate(angle);
// un simple appel a QGraphicsTextItem::setRotation suffit
QGraphicsTextItem::setRotation(QGraphicsTextItem::rotation() + angle);
}
/**

View File

@@ -185,20 +185,8 @@ bool Element::setOrientation(QET::Orientation o) {
foreach(QGraphicsItem *qgi, childItems()) {
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
p -> updateConductor();
} /* else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
// applique une rotation contraire si besoin
if (!eti -> followParentRotations()) {
QMatrix new_matrix = eti -> matrix();
qreal dx = eti -> boundingRect().width() / 2.0;
qreal dy = eti -> boundingRect().height() / 2.0;
new_matrix.translate(dx, dy);
new_matrix.rotate(-rotation_value);
new_matrix.translate(-dx, -dy);
eti -> setMatrix(new_matrix);
}
}
*/
}
return(true);
}

View File

@@ -35,6 +35,7 @@ ElementTextItem::ElementTextItem(Element *parent_element, Diagram *parent_diagra
// par defaut, les DiagramTextItem sont Selectable et Movable
// cela nous convient, on ne touche pas a ces flags
adjustItemPosition(1);
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
}
@@ -55,6 +56,7 @@ ElementTextItem::ElementTextItem(const QString &text, Element *parent_element, D
// par defaut, les DiagramTextItem sont Selectable et Movable
// cela nous convient, on ne touche pas a ces flags
adjustItemPosition(1);
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
}
@@ -75,16 +77,7 @@ Element *ElementTextItem::parentElement() const {
@param pos La nouvelle position du champ de texte
*/
void ElementTextItem::setPos(const QPointF &pos) {
// annule toute transformation (rotation notamment)
resetTransform();
// effectue le positionnement en lui-meme
QPointF actual_pos = pos;
actual_pos -= QPointF(0.0, boundingRect().bottom() / 2.0);
QGraphicsTextItem::setPos(actual_pos);
// applique a nouveau la rotation du champ de texte
applyRotation(rotationAngle());
QGraphicsTextItem::setPos(pos);
}
/**
@@ -100,9 +93,7 @@ void ElementTextItem::setPos(qreal x, qreal y) {
@return La position (bidouillee) du champ de texte
*/
QPointF ElementTextItem::pos() const {
QPointF actual_pos = DiagramTextItem::pos();
actual_pos += QPointF(0.0, boundingRect().bottom() / 2.0);
return(actual_pos);
return(QGraphicsTextItem::pos());
}
/**
@@ -198,7 +189,12 @@ qreal ElementTextItem::originalRotationAngle() const {
*/
void ElementTextItem::adjustItemPosition(int 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);
}
/**
@@ -208,14 +204,7 @@ void ElementTextItem::adjustItemPosition(int new_block_count) {
@param angle Angle de la rotation a effectuer
*/
void ElementTextItem::applyRotation(const qreal &angle) {
qreal origin_offset = boundingRect().bottom() / 2.0;
QTransform rotation;
rotation.translate(0.0, origin_offset);
rotation.rotate(angle);
rotation.translate(0.0, -origin_offset);
QGraphicsTextItem::setTransform(rotation, true);
QGraphicsTextItem::setRotation(QGraphicsTextItem::rotation() + angle);
}
/**
@@ -309,17 +298,3 @@ void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
QGraphicsTextItem::mouseReleaseEvent(e);
}
}
/**
Gere les changements intervenant sur ce champ de texte
@param change Type de changement
@param value Valeur numerique relative au changement
*/
QVariant ElementTextItem::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();
}
return(DiagramTextItem::itemChange(change, value));
}

View File

@@ -45,7 +45,6 @@ class ElementTextItem : public DiagramTextItem {
Element *parent_element_;
bool follow_parent_rotations;
QPointF original_position;
QPointF known_position_;
qreal original_rotation_angle_;
bool first_move_;
@@ -75,7 +74,6 @@ class ElementTextItem : public DiagramTextItem {
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
};
/**