mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-06-24 00:14:12 +02:00
fix(editor): suppress spurious first-click element moves (#481)
When an item type is selected for the first time the properties dock expands, causing the QGraphicsView viewport to shrink. Qt recalculates scene coordinates and fires one or more synthetic mouseMoveEvents before the user has actually moved the mouse. The original code used a single-shot m_first_move flag in CustomElementGraphicPart, which absorbed exactly one spurious event. PartText and PartDynamicTextField had no protection at all. Fix: compare screen-coordinate displacement against QApplication::startDragDistance() (~4 px). Screen coordinates are stable across viewport resizes, so the check correctly rejects synthetic dock-expansion events while allowing genuine drags. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
#include "../../qetapp.h"
|
||||
#include "../elementscene.h"
|
||||
#include <QApplication>
|
||||
|
||||
#include <QColor>
|
||||
#include <QFont>
|
||||
@@ -495,12 +496,16 @@ bool PartDynamicTextField::keepVisualRotation() const {
|
||||
@param event
|
||||
*/
|
||||
void PartDynamicTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if((event -> buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||
QPointF pos = event -> scenePos() + (m_origin_pos - event -> buttonDownScenePos(Qt::LeftButton));
|
||||
event -> modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene() -> snapToGrid(pos));
|
||||
}
|
||||
else
|
||||
if ((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||
// Suppress spurious moves from the properties dock resizing the viewport.
|
||||
const QPointF d = event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton);
|
||||
if (d.manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
||||
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
||||
} else {
|
||||
QGraphicsObject::mouseMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user