[qet] qet/qet: [5223] Fix wrong behavior when move a text item group, with rotation different than 0 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5223
Author: blacksun
Date: 2018-01-28 12:16:09 +0100 (Sun, 28 Jan 2018)
Log Message:
-----------
Fix wrong behavior when move a text item group, with rotation different than 0
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagram.h
trunk/sources/elementtextsmover.cpp
trunk/sources/elementtextsmover.h
trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
trunk/sources/qetgraphicsitem/dynamicelementtextitem.h
trunk/sources/qetgraphicsitem/elementtextitem.cpp
trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp
trunk/sources/qetgraphicsitem/elementtextitemgroup.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/diagram.cpp 2018-01-28 11:16:09 UTC (rev 5223)
@@ -1480,13 +1480,9 @@
return(m_element_texts_mover -> beginMovement(this, driver_item));
}
-/**
- Prend en compte un mouvement composant un deplacement d'ElementTextItems
- @param movement mouvement a ajouter au deplacement en cours
- @see ElementTextsMover
-*/
-void Diagram::continueMoveElementTexts(const QPointF &movement) {
- m_element_texts_mover -> continueMovement(movement);
+void Diagram::continueMoveElementTexts(QGraphicsSceneMouseEvent *event)
+{
+ m_element_texts_mover->continueMovement(event);
}
/**
Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/diagram.h 2018-01-28 11:16:09 UTC (rev 5223)
@@ -194,7 +194,7 @@
void continueMoveElements(const QPointF &);
void endMoveElements();
int beginMoveElementTexts(QGraphicsItem * = nullptr);
- void continueMoveElementTexts(const QPointF &);
+ void continueMoveElementTexts(QGraphicsSceneMouseEvent *event);
void endMoveElementTexts();
bool usesElement(const ElementsLocation &);
bool usesTitleBlockTemplate(const QString &);
Modified: trunk/sources/elementtextsmover.cpp
===================================================================
--- trunk/sources/elementtextsmover.cpp 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/elementtextsmover.cpp 2018-01-28 11:16:09 UTC (rev 5223)
@@ -51,20 +51,8 @@
m_diagram = diagram;
m_movement_driver = driver_item;
- m_last_pos = driver_item->pos();
m_items_hash.clear();
m_text_count = m_group_count =0;
-// m_texts_hash.clear();
-// m_grps_hash.clear();
-
-// for(QGraphicsItem *item : diagram->selectedItems())
-// {
-// if (item->type() == ElementTextItem::Type || item->type() == DynamicElementTextItem::Type)
-// {
-// DiagramTextItem *dti = static_cast<DiagramTextItem *> (item);
-// m_texts_hash.insert(dti, dti->pos());
-// }
-// }
for(QGraphicsItem *item : diagram->selectedItems())
{
@@ -83,8 +71,6 @@
}
}
-// if (!m_texts_hash.size())
-// return(-1);
if(m_items_hash.isEmpty())
return -1;
@@ -92,40 +78,27 @@
m_movement_running = true;
return m_items_hash.size();
-
-// return(m_texts_hash.size());
}
-/**
- * @brief ElementTextsMover::continueMovement
- * Add @movement to the current movement
- * The movement must be in scene coordinate.
- * @param movement
- */
-void ElementTextsMover::continueMovement(const QPointF &movement)
+void ElementTextsMover::continueMovement(QGraphicsSceneMouseEvent *event)
{
- if (!m_movement_running || movement.isNull())
+ if(!m_movement_running)
return;
-
- QPointF move = m_movement_driver->pos() - m_last_pos;
- m_last_pos = m_movement_driver->pos();
-
+
for(QGraphicsItem *qgi : m_items_hash.keys())
{
if(qgi == m_movement_driver)
continue;
- qgi->setPos(qgi->pos() + move);
+ QPointF current_parent_pos;
+ QPointF button_down_parent_pos;
+
+ current_parent_pos = qgi->mapToParent(qgi->mapFromScene(event->scenePos()));
+ button_down_parent_pos = qgi->mapToParent(qgi->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
+
+ QPointF new_pos = m_items_hash.value(qgi) + current_parent_pos - button_down_parent_pos;
+ event->modifiers() == Qt::ControlModifier ? qgi->setPos(new_pos) : qgi->setPos(Diagram::snapToGrid(new_pos));
}
-
-// for(DiagramTextItem *text_item : m_texts_hash.keys())
-// {
-// if (text_item == m_movement_driver)
-// continue;
-
-// QPointF applied_movement = text_item->mapMovementToParent(text_item->mapMovementFromScene(movement));
-// text_item->setPos(text_item->pos() + applied_movement);
-// }
}
/**
@@ -133,25 +106,7 @@
* Finish the movement by pushing an undo command to the parent diagram of text item
*/
void ElementTextsMover::endMovement()
-{
-// //No movement running, or no text to move
-// if (!m_movement_running || m_texts_hash.isEmpty())
-// return;
-
-// //Movement is null
-// DiagramTextItem *dti = m_texts_hash.keys().first();
-// if (dti->pos() == m_texts_hash.value(dti))
-// return;
-
-// QUndoCommand *undo = new QUndoCommand(m_texts_hash.size() == 1 ? QString(QObject::tr("Déplacer un texte d'élément")) :
-// QString(QObject::tr("Déplacer %1 textes d'élément").arg(m_texts_hash.size())));
-
-// for (DiagramTextItem *dti : m_texts_hash.keys())
-// {
-// QPropertyUndoCommand *child_undo = new QPropertyUndoCommand(dti, "pos", m_texts_hash.value(dti), dti->pos(), undo);
-// child_undo->enableAnimation();
-// }
-
+{
//No movement or no items to move
if(!m_movement_running || m_items_hash.isEmpty())
return;
Modified: trunk/sources/elementtextsmover.h
===================================================================
--- trunk/sources/elementtextsmover.h 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/elementtextsmover.h 2018-01-28 11:16:09 UTC (rev 5223)
@@ -25,6 +25,7 @@
class DiagramTextItem;
class Diagram;
class QGraphicsItemGroup;
+class QGraphicsSceneMouseEvent;
/**
This class manages the interactive movement of element text items on a
@@ -40,7 +41,7 @@
public:
bool isReady() const;
int beginMovement(Diagram *diagram, QGraphicsItem *driver_item = nullptr);
- void continueMovement(const QPointF &);
+ void continueMovement(QGraphicsSceneMouseEvent *event);
void endMovement();
private:
@@ -53,7 +54,6 @@
QHash <DiagramTextItem *, QPointF> m_texts_hash;
QHash <QGraphicsItemGroup *, QPointF> m_grps_hash;
QHash <QGraphicsItem *, QPointF> m_items_hash;
- QPointF m_last_pos;
int m_text_count = 0,
m_group_count = 0;
};
Modified: trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp 2018-01-28 11:16:09 UTC (rev 5223)
@@ -501,33 +501,33 @@
* @param event
*/
void DynamicElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
-{
- if(event->buttons() & Qt::LeftButton)
+{
+ if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
{
- QPointF old_pos = pos(); //The old pos
- QPointF movement = event->pos() - event->buttonDownPos(Qt::LeftButton); //The movement since the button down pos
- QPointF new_pos = pos() + mapMovementToParent(movement); //The new pos with this event
- event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
+ if(diagram() && m_first_move)
+ diagram()->beginMoveElementTexts(this);
- if(m_parent_element && m_parent_element->diagram())
+ if(m_first_move)
{
- Diagram *diagram = m_parent_element->diagram();
-
- if(m_first_move)
- {
- if(diagram->beginMoveElementTexts(this) == 1)
- m_parent_element->setHighlighted(true);
- }
-
- //Because setPos() can be snaped to grid or not, we calcule the real movement
- QPointF effective_movement = pos() - old_pos;
- QPointF scene_effective_movement = mapMovementToScene(mapMovementFromParent(effective_movement));
- diagram->continueMoveElementTexts(scene_effective_movement);
+ m_initial_position = pos();
+ if(parentElement())
+ parentElement()->setHighlighted(true);
}
+
+ QPointF current_parent_pos;
+ QPointF button_down_parent_pos;
+ current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
+ button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
+
+ QPointF new_pos = m_initial_position + current_parent_pos - button_down_parent_pos;
+ event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
+
+ if(diagram())
+ diagram()->continueMoveElementTexts(event);
+ } else {
+ event->ignore();
}
- else
- event->ignore();
-
+
if(m_first_move)
m_first_move = false;
}
Modified: trunk/sources/qetgraphicsitem/dynamicelementtextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/dynamicelementtextitem.h 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/qetgraphicsitem/dynamicelementtextitem.h 2018-01-28 11:16:09 UTC (rev 5223)
@@ -152,6 +152,7 @@
CrossRefItem *m_Xref_item = nullptr;
QGraphicsTextItem *m_slave_Xref_item = nullptr;
qreal m_text_width = -1;
+ QPointF m_initial_position;
};
#endif // DYNAMICELEMENTTEXTITEM_H
Modified: trunk/sources/qetgraphicsitem/elementtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitem.cpp 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/qetgraphicsitem/elementtextitem.cpp 2018-01-28 11:16:09 UTC (rev 5223)
@@ -272,7 +272,7 @@
QPointF scene_effective_movement = mapMovementToScene(mapMovementFromParent(effective_movement));
// on applique le mouvement subi aux autres textes a deplacer
- diagram_ptr -> continueMoveElementTexts(scene_effective_movement);
+ diagram_ptr -> continueMoveElementTexts(event);
}
} else event -> ignore();
Modified: trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp 2018-01-28 11:16:09 UTC (rev 5223)
@@ -394,28 +394,31 @@
*/
void ElementTextItemGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if(isSelected() && event->buttons() & Qt::LeftButton)
+ if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
{
if(diagram() && m_first_move)
diagram()->beginMoveElementTexts(this);
- QPointF old_pos = pos();
if(m_first_move)
{
- m_mouse_to_origin_movement = old_pos - event->buttonDownScenePos(Qt::LeftButton);
+ m_initial_position = pos();
if(parentElement())
parentElement()->setHighlighted(true);
}
- QPointF expected_pos = event->scenePos() + m_mouse_to_origin_movement;
- event->modifiers() == Qt::ControlModifier ? setPos(expected_pos) : setPos(Diagram::snapToGrid(expected_pos));
+ QPointF current_parent_pos;
+ QPointF button_down_parent_pos;
+ current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
+ button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
- QPointF effective_movement = pos() - old_pos;
+ QPointF new_pos = m_initial_position + current_parent_pos - button_down_parent_pos;
+ event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
+
if(diagram())
- diagram()->continueMoveElementTexts(effective_movement);
+ diagram()->continueMoveElementTexts(event);
+ } else {
+ event->ignore();
}
- else
- event->ignore();
if(m_first_move)
m_first_move = false;
Modified: trunk/sources/qetgraphicsitem/elementtextitemgroup.h
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitemgroup.h 2018-01-27 23:55:25 UTC (rev 5222)
+++ trunk/sources/qetgraphicsitem/elementtextitemgroup.h 2018-01-28 11:16:09 UTC (rev 5223)
@@ -91,7 +91,7 @@
Qt::Alignment m_alignment = Qt::AlignJustify;
QString m_name;
bool m_first_move = true;
- QPointF m_mouse_to_origin_movement;
+ QPointF m_initial_position;
int m_vertical_adjustment = 0;
CrossRefItem *m_Xref_item = nullptr;
Element *m_parent_element = nullptr;