mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
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:
@@ -598,7 +598,7 @@ RotateElementsCommand::~RotateElementsCommand() {
|
|||||||
/// defait le pivotement
|
/// defait le pivotement
|
||||||
void RotateElementsCommand::undo() {
|
void RotateElementsCommand::undo() {
|
||||||
foreach(Element *e, elements_to_rotate.keys()) {
|
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) {
|
foreach(DiagramTextItem *dti, texts_to_rotate) {
|
||||||
dti -> rotateBy(-applied_rotation_angle_);
|
dti -> rotateBy(-applied_rotation_angle_);
|
||||||
@@ -608,8 +608,7 @@ void RotateElementsCommand::undo() {
|
|||||||
/// refait le pivotement
|
/// refait le pivotement
|
||||||
void RotateElementsCommand::redo() {
|
void RotateElementsCommand::redo() {
|
||||||
foreach(Element *e, elements_to_rotate.keys()) {
|
foreach(Element *e, elements_to_rotate.keys()) {
|
||||||
e -> setOrientation(e -> orientation().next());
|
rotateElement(e, e -> orientation().next());
|
||||||
e -> update();
|
|
||||||
}
|
}
|
||||||
foreach(DiagramTextItem *dti, texts_to_rotate) {
|
foreach(DiagramTextItem *dti, texts_to_rotate) {
|
||||||
dti -> rotateBy(applied_rotation_angle_);
|
dti -> rotateBy(applied_rotation_angle_);
|
||||||
@@ -630,6 +629,36 @@ void RotateElementsCommand::setAppliedRotationAngle(const qreal &angle) {
|
|||||||
applied_rotation_angle_ = QET::correctAngle(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
|
Constructeur
|
||||||
@param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action
|
@param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action
|
||||||
|
|||||||
@@ -319,6 +319,8 @@ class RotateElementsCommand : public QUndoCommand {
|
|||||||
virtual void redo();
|
virtual void redo();
|
||||||
qreal appliedRotationAngle() const;
|
qreal appliedRotationAngle() const;
|
||||||
void setAppliedRotationAngle(const qreal &);
|
void setAppliedRotationAngle(const qreal &);
|
||||||
|
private:
|
||||||
|
void rotateElement(Element *, QET::Orientation);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -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).
|
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
|
@param angle Angle de la rotation a effectuer
|
||||||
*/
|
*/
|
||||||
void DiagramTextItem::applyRotation(const qreal &angle) {
|
void DiagramTextItem::applyRotation(const qreal &angle) {
|
||||||
// un simple appel a QGraphicsTextItem::rotate suffit
|
// un simple appel a QGraphicsTextItem::setRotation suffit
|
||||||
QGraphicsTextItem::rotate(angle);
|
QGraphicsTextItem::setRotation(QGraphicsTextItem::rotation() + angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -185,19 +185,7 @@ bool Element::setOrientation(QET::Orientation o) {
|
|||||||
foreach(QGraphicsItem *qgi, childItems()) {
|
foreach(QGraphicsItem *qgi, childItems()) {
|
||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
||||||
p -> updateConductor();
|
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);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ ElementTextItem::ElementTextItem(Element *parent_element, Diagram *parent_diagra
|
|||||||
// par defaut, les DiagramTextItem sont Selectable et Movable
|
// par defaut, les DiagramTextItem sont Selectable et Movable
|
||||||
// cela nous convient, on ne touche pas a ces flags
|
// cela nous convient, on ne touche pas a ces flags
|
||||||
|
|
||||||
|
adjustItemPosition(1);
|
||||||
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
|
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
|
||||||
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
|
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
|
// par defaut, les DiagramTextItem sont Selectable et Movable
|
||||||
// cela nous convient, on ne touche pas a ces flags
|
// cela nous convient, on ne touche pas a ces flags
|
||||||
|
|
||||||
|
adjustItemPosition(1);
|
||||||
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
|
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
|
||||||
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
|
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
|
@param pos La nouvelle position du champ de texte
|
||||||
*/
|
*/
|
||||||
void ElementTextItem::setPos(const QPointF &pos) {
|
void ElementTextItem::setPos(const QPointF &pos) {
|
||||||
// annule toute transformation (rotation notamment)
|
QGraphicsTextItem::setPos(pos);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,9 +93,7 @@ void ElementTextItem::setPos(qreal x, qreal y) {
|
|||||||
@return La position (bidouillee) du champ de texte
|
@return La position (bidouillee) du champ de texte
|
||||||
*/
|
*/
|
||||||
QPointF ElementTextItem::pos() const {
|
QPointF ElementTextItem::pos() const {
|
||||||
QPointF actual_pos = DiagramTextItem::pos();
|
return(QGraphicsTextItem::pos());
|
||||||
actual_pos += QPointF(0.0, boundingRect().bottom() / 2.0);
|
|
||||||
return(actual_pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +189,12 @@ qreal ElementTextItem::originalRotationAngle() const {
|
|||||||
*/
|
*/
|
||||||
void ElementTextItem::adjustItemPosition(int new_block_count) {
|
void ElementTextItem::adjustItemPosition(int new_block_count) {
|
||||||
Q_UNUSED(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
|
@param angle Angle de la rotation a effectuer
|
||||||
*/
|
*/
|
||||||
void ElementTextItem::applyRotation(const qreal &angle) {
|
void ElementTextItem::applyRotation(const qreal &angle) {
|
||||||
qreal origin_offset = boundingRect().bottom() / 2.0;
|
QGraphicsTextItem::setRotation(QGraphicsTextItem::rotation() + angle);
|
||||||
|
|
||||||
QTransform rotation;
|
|
||||||
rotation.translate(0.0, origin_offset);
|
|
||||||
rotation.rotate(angle);
|
|
||||||
rotation.translate(0.0, -origin_offset);
|
|
||||||
|
|
||||||
QGraphicsTextItem::setTransform(rotation, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -309,17 +298,3 @@ void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
QGraphicsTextItem::mouseReleaseEvent(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));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class ElementTextItem : public DiagramTextItem {
|
|||||||
Element *parent_element_;
|
Element *parent_element_;
|
||||||
bool follow_parent_rotations;
|
bool follow_parent_rotations;
|
||||||
QPointF original_position;
|
QPointF original_position;
|
||||||
QPointF known_position_;
|
|
||||||
qreal original_rotation_angle_;
|
qreal original_rotation_angle_;
|
||||||
bool first_move_;
|
bool first_move_;
|
||||||
|
|
||||||
@@ -75,7 +74,6 @@ class ElementTextItem : public DiagramTextItem {
|
|||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user