From 7cb47f3b9ee70051f96c0968c32ecb94a3be5c7f Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 7 Apr 2021 12:56:43 +0200 Subject: [PATCH] Fix unwanted moving part in element editor. Fix an unwanted behavior when the properties dock widget is displayed : 1 there is no selection 2 the dock widget width is set to minimum 3 select a part, the dock widget gain new widgets used to edit the current selected part and the width of the dock grow so the width of the QGraphicsView is reduced and cause a mouse move event. When this case occur the part is moved but they should not. --- .../graphicspart/customelementgraphicpart.cpp | 17 ++++++++++++++++- .../graphicspart/customelementgraphicpart.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sources/editor/graphicspart/customelementgraphicpart.cpp b/sources/editor/graphicspart/customelementgraphicpart.cpp index e3d2c9291..e8b09c784 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.cpp +++ b/sources/editor/graphicspart/customelementgraphicpart.cpp @@ -1290,14 +1290,29 @@ void CustomElementGraphicPart::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void CustomElementGraphicPart::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(event->button() == Qt::LeftButton) + if(event->button() == Qt::LeftButton) { m_origin_pos = this->pos(); + m_first_move = true; + } QGraphicsObject::mousePressEvent(event); } void CustomElementGraphicPart::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + //m_first_move is used to avoid an unwanted behavior + //when the properties dock widget is displayed : + //1 there is no selection + //2 the dock widget width is set to minimum + //3 select a part, the dock widget gain new widgets used to edit + //the current selected part and the width of the dock grow + //so the width of the QGraphicsView is reduced and cause a mouse move event. + //When this case occur the part is moved but they should not. This bool fix it. + if (Q_UNLIKELY(m_first_move)) { + m_first_move = false; + return; + } + if((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) { QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton)); diff --git a/sources/editor/graphicspart/customelementgraphicpart.h b/sources/editor/graphicspart/customelementgraphicpart.h index 6b1084c67..d1a232e67 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.h +++ b/sources/editor/graphicspart/customelementgraphicpart.h @@ -326,6 +326,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar Color _color; bool _antialiased; QPointF m_origin_pos; + bool m_first_move; }; typedef CustomElementGraphicPart CEGP;