mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-22 06:14:14 +02:00
Width handles: read the drag in the text's coordinates as they were at the press
The text moves on every step of a drag to keep its alignment point in place. Mapping the mouse with its current transform made the delta grow with every step, so a right or centre aligned text ran away: 90 px of mouse gave +1220 px of width. The probe now drags in 30 steps and checks the width grows by exactly as much as the mouse moved. Reported by ispyisail in the review of #1555. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1050,7 +1050,11 @@ void DynamicElementTextItem::handlerMousePressEvent(QetGraphicsHandlerItem *hand
|
||||
//A concrete baseline for the live drag's delta math, which can't
|
||||
//start from -1.
|
||||
m_resize_baseline_width = (m_resize_original_width < 0) ? frameRect().width() : m_resize_original_width;
|
||||
m_resize_start_local_x = mapFromScene(event->scenePos()).x();
|
||||
//The text moves while it is dragged, to keep its alignment point
|
||||
//in place: read the mouse in the text's coordinates as they were
|
||||
//at the press, otherwise the delta grows with every step
|
||||
m_resize_scene_to_local = sceneTransform().inverted();
|
||||
m_resize_start_local_x = m_resize_scene_to_local.map(event->scenePos()).x();
|
||||
|
||||
//The point the text is aligned on stays where it is: remember it
|
||||
//in the parent's coordinates, which take the text's rotation
|
||||
@@ -1093,7 +1097,7 @@ QPointF DynamicElementTextItem::resizeAnchor() const
|
||||
*/
|
||||
void DynamicElementTextItem::handlerMouseMoveEvent(QetGraphicsHandlerItem *handle, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
qreal local_x = mapFromScene(event->scenePos()).x();
|
||||
qreal local_x = m_resize_scene_to_local.map(event->scenePos()).x();
|
||||
qreal delta = local_x - m_resize_start_local_x;
|
||||
if (handle == m_left_resize_handle)
|
||||
delta = -delta;
|
||||
|
||||
@@ -216,6 +216,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
qreal m_resize_start_local_x = 0;
|
||||
QPointF m_resize_start_pos,
|
||||
m_resize_fixed_parent;
|
||||
QTransform m_resize_scene_to_local;
|
||||
QMetaObject::Connection m_resize_handles_con;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user