From 7a11b3497a0dbc6f419dbbb476fdf7a2362193a7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 30 Oct 2017 11:08:25 +0200 Subject: [PATCH] Fix bug with setting cursor QGraphicsPathItem without hover events. --HG-- branch : develop --- .../drawTools/toolcurve/vabstractspline.cpp | 11 +++++- .../drawTools/toolcurve/vabstractspline.h | 1 + .../tools/drawTools/toolcurve/vtoolspline.cpp | 34 +++++++++++------ .../drawTools/toolcurve/vtoolsplinepath.cpp | 38 ++++++++++++------- .../toolsinglepoint/vtoolbasepoint.cpp | 5 --- src/libs/vtools/tools/vtoolseamallowance.cpp | 31 ++++++++++----- src/libs/vtools/tools/vtoolseamallowance.h | 2 + src/libs/vwidgets/vcontrolpointspline.cpp | 6 +-- src/libs/vwidgets/vgrainlineitem.cpp | 1 - src/libs/vwidgets/vgraphicssimpletextitem.cpp | 4 -- src/libs/vwidgets/vmaingraphicsview.cpp | 8 +++- src/libs/vwidgets/vmaingraphicsview.h | 1 + src/libs/vwidgets/vtextgraphicsitem.cpp | 4 -- 13 files changed, 89 insertions(+), 57 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index c8b2236ab..31a0df1e7 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -62,10 +62,11 @@ VAbstractSpline::VAbstractSpline(VAbstractPattern *doc, VContainer *data, quint3 sceneType(SceneObject::Unknown), m_isHovered(false), detailsMode(qApp->Settings()->IsShowCurveDetails()), + m_acceptHoverEvents(true), m_parentRefresh(false) { InitDefShape(); - setAcceptHoverEvents(true); + setAcceptHoverEvents(m_acceptHoverEvents); } //--------------------------------------------------------------------------------------------------------------------- @@ -169,12 +170,18 @@ void VAbstractSpline::DetailsMode(bool mode) //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::AllowHover(bool enabled) { - setAcceptHoverEvents(enabled); + // Manually handle hover events. Need for setting cursor for not selectable paths. + m_acceptHoverEvents = enabled; foreach (auto *point, controlPoints) { point->setAcceptHoverEvents(enabled); } + + if (not enabled) + { + setCursor(qApp->getSceneView()->viewport()->cursor()); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 14a02a721..1e8f42042 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -113,6 +113,7 @@ protected: SceneObject sceneType; bool m_isHovered; bool detailsMode; + bool m_acceptHoverEvents; /** * @brief RefreshGeometry refresh item on scene. */ diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 1cc52ecca..11ee3e7eb 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -493,29 +493,39 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - if (flags() & QGraphicsItem::ItemIsMovable) + if (m_acceptHoverEvents) { - if (IsMovable()) + if (flags() & QGraphicsItem::ItemIsMovable) { - SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + if (IsMovable()) + { + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); + } + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); } - } - VAbstractSpline::hoverEnterEvent(event); + VAbstractSpline::hoverEnterEvent(event); + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); + } } //--------------------------------------------------------------------------------------------------------------------- void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - if (flags() & QGraphicsItem::ItemIsMovable) + if (m_acceptHoverEvents) { - if (IsMovable()) - { - setCursor(QCursor()); - } + VAbstractSpline::hoverLeaveEvent(event); } - - VAbstractSpline::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index eae3b0b2a..0c2426d4a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -654,30 +654,42 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - if (flags() & QGraphicsItem::ItemIsMovable) + if (m_acceptHoverEvents) { - oldPosition = event->scenePos(); - const auto splPath = VAbstractTool::data.GeometricObject(m_id); - splIndex = splPath->Segment(oldPosition); - if (IsMovable(splIndex)) + if (flags() & QGraphicsItem::ItemIsMovable) { - SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + oldPosition = event->scenePos(); + const auto splPath = VAbstractTool::data.GeometricObject(m_id); + splIndex = splPath->Segment(oldPosition); + if (IsMovable(splIndex)) + { + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); + } + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); } - } - VAbstractSpline::hoverEnterEvent(event); + VAbstractSpline::hoverEnterEvent(event); + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); + } } //--------------------------------------------------------------------------------------------------------------------- void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - if (flags() & QGraphicsItem::ItemIsMovable) + if (m_acceptHoverEvents) { - oldPosition = event->scenePos(); - setCursor(QCursor()); + VAbstractSpline::hoverLeaveEvent(event); } - - VAbstractSpline::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index 7cad4e6d3..b190492f3 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -319,11 +319,6 @@ void VToolBasePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolBasePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { VToolSinglePoint::hoverLeaveEvent(event); - - if (flags() & QGraphicsItem::ItemIsMovable) - { - setCursor(QCursor()); - } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 4aec2865f..e17f48799 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -594,7 +594,8 @@ void VToolSeamAllowance::EnableToolMove(bool move) //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AllowHover(bool enabled) { - setAcceptHoverEvents(enabled); + // Manually handle hover events. Need for setting cursor for not selectable paths. + m_acceptHoverEvents = enabled; m_dataLabel->setAcceptHoverEvents(enabled); m_patternInfo->setAcceptHoverEvents(enabled); m_grainLine->setAcceptHoverEvents(enabled); @@ -1132,22 +1133,31 @@ void VToolSeamAllowance::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - if (flags() & QGraphicsItem::ItemIsMovable) + if (m_acceptHoverEvents) { - SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + if (flags() & QGraphicsItem::ItemIsMovable) + { + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); + } + QGraphicsPathItem::hoverEnterEvent(event); + } + else + { + setCursor(qApp->getSceneView()->viewport()->cursor()); } - QGraphicsPathItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - //Disable cursor-arrow-openhand - if (flags() & QGraphicsItem::ItemIsMovable) + if (m_acceptHoverEvents) { - setCursor(QCursor()); + QGraphicsPathItem::hoverLeaveEvent(event); } - QGraphicsPathItem::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -1257,7 +1267,8 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat m_patternInfo(new VTextGraphicsItem(this)), m_grainLine(new VGrainlineItem(this)), m_passmarks(new QGraphicsPathItem(this)), - m_placeLabels(new QGraphicsPathItem(this)) + m_placeLabels(new QGraphicsPathItem(this)), + m_acceptHoverEvents(true) { VPiece detail = initData.data->GetPiece(initData.id); ReinitInternals(detail, m_sceneDetails); @@ -1269,7 +1280,7 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus ToolCreation(initData.typeCreation); - setAcceptHoverEvents(true); + setAcceptHoverEvents(m_acceptHoverEvents); connect(this, &VToolSeamAllowance::ChoosedTool, m_sceneDetails, &VMainGraphicsScene::ChoosedItem); connect(m_sceneDetails, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove); diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 27b35f03b..47c68015c 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -182,6 +182,8 @@ private: QGraphicsPathItem *m_passmarks; QGraphicsPathItem *m_placeLabels; + bool m_acceptHoverEvents; + VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr); void UpdateExcludeState(); diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index 02563e995..10451af46 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -108,7 +108,7 @@ void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsIte */ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - if (freeAngle || freeLength) + if ((flags() & QGraphicsItem::ItemIsMovable) && (freeAngle || freeLength)) { SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } @@ -118,10 +118,6 @@ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - if (freeAngle || freeLength) - { - setCursor(QCursor()); - } VScenePoint::hoverLeaveEvent(event); } diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index f9e09b762..257553fa0 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -522,7 +522,6 @@ void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME) { if (flags() & QGraphicsItem::ItemIsMovable) { - setCursor(QCursor()); m_penWidth = LINE_PEN_WIDTH; } VPieceItem::hoverLeaveEvent(pME); diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 26489f3db..5667dbd08 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -228,10 +228,6 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) */ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - if (flags() & QGraphicsItem::ItemIsMovable) - { - setCursor(QCursor()); - } this->setBrush(Qt::black); QGraphicsSimpleTextItem::hoverLeaveEvent(event); } diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index 9ba8bf5c5..400bd7b1e 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -352,7 +352,8 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent) zoom(new GraphicsViewZoom(this)), showToolOptions(true), isAllowRubberBand(true), - m_ptStartPos() + m_ptStartPos(), + m_oldCursor() { this->setResizeAnchor(QGraphicsView::AnchorUnderMouse); this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); @@ -469,6 +470,7 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *event) if (list.size() == 0) {// Only when the user clicks on the scene background m_ptStartPos = event->pos(); + m_oldCursor = viewport()->cursor(); QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); event->accept(); viewport()->setCursor(Qt::ClosedHandCursor); @@ -508,6 +510,10 @@ void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event) { QGraphicsView::mouseReleaseEvent ( event ); // First because need to hide a rubber band QGraphicsView::setDragMode( QGraphicsView::NoDrag ); + if (event->button() == Qt::MiddleButton) + { + viewport()->setCursor(m_oldCursor); + } if (event->button() == Qt::LeftButton) { emit MouseRelease(); diff --git a/src/libs/vwidgets/vmaingraphicsview.h b/src/libs/vwidgets/vmaingraphicsview.h index c97e1d668..9c51e0df4 100644 --- a/src/libs/vwidgets/vmaingraphicsview.h +++ b/src/libs/vwidgets/vmaingraphicsview.h @@ -152,6 +152,7 @@ private: bool showToolOptions; bool isAllowRubberBand; QPoint m_ptStartPos; + QCursor m_oldCursor; }; #endif // VMAINGRAPHICSVIEW_H diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index cb2ae0d79..2c6784c59 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -642,10 +642,6 @@ void VTextGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME) */ void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) { - if (flags() & QGraphicsItem::ItemIsMovable) - { - setCursor(QCursor()); - } VPieceItem::hoverLeaveEvent(pHE); }