From 8683b69f13b188b2583ebdff76ae42bc0ad36a34 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 11 Feb 2016 13:05:08 +0200 Subject: [PATCH] Select an item inside mousePressEvent() instead mouseReleaseEvent(). --HG-- branch : feature --- .../tools/drawTools/toolcurve/vabstractspline.cpp | 6 +++--- .../vtools/tools/drawTools/toolcurve/vabstractspline.h | 2 +- .../toolpoint/toolsinglepoint/vtoolsinglepoint.cpp | 6 +++--- .../toolpoint/toolsinglepoint/vtoolsinglepoint.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 10 +++++++--- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 8 ++++---- src/libs/vwidgets/vsimplepoint.cpp | 4 ++-- src/libs/vwidgets/vsimplepoint.h | 2 +- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 2648fc3b1..ca01fb50b 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -204,16 +204,16 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief mouseReleaseEvent handle mouse release events. + * @brief mousePressEvent handle mouse press events. * @param event mouse release event. */ -void VAbstractSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VAbstractSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { emit ChoosedTool(id, sceneType); } - QGraphicsItem::mouseReleaseEvent(event); + QGraphicsPathItem::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 61aca125e..54129b110 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -88,7 +88,7 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 63d995980..d0cf96a75 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -177,16 +177,16 @@ void VToolSinglePoint::FullUpdateFromFile() //--------------------------------------------------------------------------------------------------------------------- /** - * @brief mouseReleaseEvent handle mouse release events. + * @brief mousePressEvent handle mouse press events. * @param event mouse release event. */ -void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { PointChoosed(); } - QGraphicsEllipseItem::mouseReleaseEvent(event); + QGraphicsEllipseItem::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 112285ee8..0a1c7f809 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -73,7 +73,7 @@ protected: QGraphicsLineItem *lineName; virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void RefreshPointGeometry(const VPointF &point); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index b3f222d32..7262c5258 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -446,9 +446,14 @@ void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { SetOverrideCursor(cursorArrowCloseHand, 1, 1); - event->accept(); } } + + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + { + emit ChoosedTool(id, SceneObject::Detail); + } + VNoBrushScalePathItem::mousePressEvent(event); } @@ -461,11 +466,10 @@ void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, SceneObject::Detail); //Disable cursor-arrow-closehand RestoreOverrideCursor(cursorArrowCloseHand); } - QGraphicsItem::mouseReleaseEvent(event); + VNoBrushScalePathItem::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 5a92bac76..21b13359f 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -217,6 +217,9 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } + + emit PointChoosed(); + QGraphicsSimpleTextItem::mousePressEvent(event); } @@ -231,10 +234,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) RestoreOverrideCursor(cursorArrowCloseHand); } } - else - { - emit PointChoosed(); - } + QGraphicsSimpleTextItem::mouseReleaseEvent(event); } diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 5cca38fdd..51447b629 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -173,13 +173,13 @@ void VSimplePoint::ContextMenu(QGraphicsSceneContextMenuEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { emit Choosed(id); } - QGraphicsEllipseItem::mouseReleaseEvent(event); + QGraphicsEllipseItem::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index 84d8fee0b..ffb45f869 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -75,7 +75,7 @@ public slots: void ContextMenu(QGraphicsSceneContextMenuEvent * event); protected: - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;