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