mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-08 06:42:34 +01:00
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.
This commit is contained in:
@@ -1308,14 +1308,29 @@ void CustomElementGraphicPart::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
|
|
||||||
void CustomElementGraphicPart::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void CustomElementGraphicPart::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if(event->button() == Qt::LeftButton)
|
if(event->button() == Qt::LeftButton) {
|
||||||
m_origin_pos = this->pos();
|
m_origin_pos = this->pos();
|
||||||
|
m_first_move = true;
|
||||||
|
}
|
||||||
|
|
||||||
QGraphicsObject::mousePressEvent(event);
|
QGraphicsObject::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomElementGraphicPart::mouseMoveEvent(QGraphicsSceneMouseEvent *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))
|
if((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable))
|
||||||
{
|
{
|
||||||
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
||||||
|
|||||||
@@ -328,6 +328,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
|
|||||||
Color _color;
|
Color _color;
|
||||||
bool _antialiased;
|
bool _antialiased;
|
||||||
QPointF m_origin_pos;
|
QPointF m_origin_pos;
|
||||||
|
bool m_first_move;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef CustomElementGraphicPart CEGP;
|
typedef CustomElementGraphicPart CEGP;
|
||||||
|
|||||||
Reference in New Issue
Block a user