Fix bug with setting cursor QGraphicsPathItem without hover events.
--HG-- branch : develop
This commit is contained in:
parent
6e194e966b
commit
7a11b3497a
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -113,6 +113,7 @@ protected:
|
|||
SceneObject sceneType;
|
||||
bool m_isHovered;
|
||||
bool detailsMode;
|
||||
bool m_acceptHoverEvents;
|
||||
/**
|
||||
* @brief RefreshGeometry refresh item on scene.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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<VSplinePath>(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<VSplinePath>(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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -319,11 +319,6 @@ void VToolBasePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||
void VToolBasePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
VToolSinglePoint::hoverLeaveEvent(event);
|
||||
|
||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
||||
{
|
||||
setCursor(QCursor());
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -182,6 +182,8 @@ private:
|
|||
QGraphicsPathItem *m_passmarks;
|
||||
QGraphicsPathItem *m_placeLabels;
|
||||
|
||||
bool m_acceptHoverEvents;
|
||||
|
||||
VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr);
|
||||
|
||||
void UpdateExcludeState();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -522,7 +522,6 @@ void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME)
|
|||
{
|
||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
||||
{
|
||||
setCursor(QCursor());
|
||||
m_penWidth = LINE_PEN_WIDTH;
|
||||
}
|
||||
VPieceItem::hoverLeaveEvent(pME);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -152,6 +152,7 @@ private:
|
|||
bool showToolOptions;
|
||||
bool isAllowRubberBand;
|
||||
QPoint m_ptStartPos;
|
||||
QCursor m_oldCursor;
|
||||
};
|
||||
|
||||
#endif // VMAINGRAPHICSVIEW_H
|
||||
|
|
|
@ -642,10 +642,6 @@ void VTextGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME)
|
|||
*/
|
||||
void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE)
|
||||
{
|
||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
||||
{
|
||||
setCursor(QCursor());
|
||||
}
|
||||
VPieceItem::hoverLeaveEvent(pHE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user