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),
|
sceneType(SceneObject::Unknown),
|
||||||
m_isHovered(false),
|
m_isHovered(false),
|
||||||
detailsMode(qApp->Settings()->IsShowCurveDetails()),
|
detailsMode(qApp->Settings()->IsShowCurveDetails()),
|
||||||
|
m_acceptHoverEvents(true),
|
||||||
m_parentRefresh(false)
|
m_parentRefresh(false)
|
||||||
{
|
{
|
||||||
InitDefShape();
|
InitDefShape();
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(m_acceptHoverEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -169,12 +170,18 @@ void VAbstractSpline::DetailsMode(bool mode)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractSpline::AllowHover(bool enabled)
|
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)
|
foreach (auto *point, controlPoints)
|
||||||
{
|
{
|
||||||
point->setAcceptHoverEvents(enabled);
|
point->setAcceptHoverEvents(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (not enabled)
|
||||||
|
{
|
||||||
|
setCursor(qApp->getSceneView()->viewport()->cursor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -113,6 +113,7 @@ protected:
|
||||||
SceneObject sceneType;
|
SceneObject sceneType;
|
||||||
bool m_isHovered;
|
bool m_isHovered;
|
||||||
bool detailsMode;
|
bool detailsMode;
|
||||||
|
bool m_acceptHoverEvents;
|
||||||
/**
|
/**
|
||||||
* @brief RefreshGeometry refresh item on scene.
|
* @brief RefreshGeometry refresh item on scene.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -493,29 +493,39 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *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)
|
void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
if (m_acceptHoverEvents)
|
||||||
{
|
{
|
||||||
if (IsMovable())
|
VAbstractSpline::hoverLeaveEvent(event);
|
||||||
{
|
|
||||||
setCursor(QCursor());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VAbstractSpline::hoverLeaveEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -654,30 +654,42 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
if (m_acceptHoverEvents)
|
||||||
{
|
{
|
||||||
oldPosition = event->scenePos();
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
||||||
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(m_id);
|
|
||||||
splIndex = splPath->Segment(oldPosition);
|
|
||||||
if (IsMovable(splIndex))
|
|
||||||
{
|
{
|
||||||
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)
|
void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
if (m_acceptHoverEvents)
|
||||||
{
|
{
|
||||||
oldPosition = event->scenePos();
|
VAbstractSpline::hoverLeaveEvent(event);
|
||||||
setCursor(QCursor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VAbstractSpline::hoverLeaveEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -319,11 +319,6 @@ void VToolBasePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
void VToolBasePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void VToolBasePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
VToolSinglePoint::hoverLeaveEvent(event);
|
VToolSinglePoint::hoverLeaveEvent(event);
|
||||||
|
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
||||||
{
|
|
||||||
setCursor(QCursor());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -594,7 +594,8 @@ void VToolSeamAllowance::EnableToolMove(bool move)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSeamAllowance::AllowHover(bool enabled)
|
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_dataLabel->setAcceptHoverEvents(enabled);
|
||||||
m_patternInfo->setAcceptHoverEvents(enabled);
|
m_patternInfo->setAcceptHoverEvents(enabled);
|
||||||
m_grainLine->setAcceptHoverEvents(enabled);
|
m_grainLine->setAcceptHoverEvents(enabled);
|
||||||
|
@ -1132,22 +1133,31 @@ void VToolSeamAllowance::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *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)
|
void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
//Disable cursor-arrow-openhand
|
if (m_acceptHoverEvents)
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
||||||
{
|
{
|
||||||
setCursor(QCursor());
|
QGraphicsPathItem::hoverLeaveEvent(event);
|
||||||
}
|
}
|
||||||
QGraphicsPathItem::hoverLeaveEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1257,7 +1267,8 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
|
||||||
m_patternInfo(new VTextGraphicsItem(this)),
|
m_patternInfo(new VTextGraphicsItem(this)),
|
||||||
m_grainLine(new VGrainlineItem(this)),
|
m_grainLine(new VGrainlineItem(this)),
|
||||||
m_passmarks(new QGraphicsPathItem(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);
|
VPiece detail = initData.data->GetPiece(initData.id);
|
||||||
ReinitInternals(detail, m_sceneDetails);
|
ReinitInternals(detail, m_sceneDetails);
|
||||||
|
@ -1269,7 +1280,7 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
|
||||||
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
||||||
|
|
||||||
ToolCreation(initData.typeCreation);
|
ToolCreation(initData.typeCreation);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(m_acceptHoverEvents);
|
||||||
|
|
||||||
connect(this, &VToolSeamAllowance::ChoosedTool, m_sceneDetails, &VMainGraphicsScene::ChoosedItem);
|
connect(this, &VToolSeamAllowance::ChoosedTool, m_sceneDetails, &VMainGraphicsScene::ChoosedItem);
|
||||||
connect(m_sceneDetails, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
|
connect(m_sceneDetails, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
|
||||||
|
|
|
@ -182,6 +182,8 @@ private:
|
||||||
QGraphicsPathItem *m_passmarks;
|
QGraphicsPathItem *m_passmarks;
|
||||||
QGraphicsPathItem *m_placeLabels;
|
QGraphicsPathItem *m_placeLabels;
|
||||||
|
|
||||||
|
bool m_acceptHoverEvents;
|
||||||
|
|
||||||
VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr);
|
VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr);
|
||||||
|
|
||||||
void UpdateExcludeState();
|
void UpdateExcludeState();
|
||||||
|
|
|
@ -108,7 +108,7 @@ void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsIte
|
||||||
*/
|
*/
|
||||||
void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (freeAngle || freeLength)
|
if ((flags() & QGraphicsItem::ItemIsMovable) && (freeAngle || freeLength))
|
||||||
{
|
{
|
||||||
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
|
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
|
||||||
}
|
}
|
||||||
|
@ -118,10 +118,6 @@ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (freeAngle || freeLength)
|
|
||||||
{
|
|
||||||
setCursor(QCursor());
|
|
||||||
}
|
|
||||||
VScenePoint::hoverLeaveEvent(event);
|
VScenePoint::hoverLeaveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -522,7 +522,6 @@ void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME)
|
||||||
{
|
{
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
||||||
{
|
{
|
||||||
setCursor(QCursor());
|
|
||||||
m_penWidth = LINE_PEN_WIDTH;
|
m_penWidth = LINE_PEN_WIDTH;
|
||||||
}
|
}
|
||||||
VPieceItem::hoverLeaveEvent(pME);
|
VPieceItem::hoverLeaveEvent(pME);
|
||||||
|
|
|
@ -228,10 +228,6 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
*/
|
*/
|
||||||
void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
||||||
{
|
|
||||||
setCursor(QCursor());
|
|
||||||
}
|
|
||||||
this->setBrush(Qt::black);
|
this->setBrush(Qt::black);
|
||||||
QGraphicsSimpleTextItem::hoverLeaveEvent(event);
|
QGraphicsSimpleTextItem::hoverLeaveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -352,7 +352,8 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
||||||
zoom(new GraphicsViewZoom(this)),
|
zoom(new GraphicsViewZoom(this)),
|
||||||
showToolOptions(true),
|
showToolOptions(true),
|
||||||
isAllowRubberBand(true),
|
isAllowRubberBand(true),
|
||||||
m_ptStartPos()
|
m_ptStartPos(),
|
||||||
|
m_oldCursor()
|
||||||
{
|
{
|
||||||
this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
|
@ -469,6 +470,7 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *event)
|
||||||
if (list.size() == 0)
|
if (list.size() == 0)
|
||||||
{// Only when the user clicks on the scene background
|
{// Only when the user clicks on the scene background
|
||||||
m_ptStartPos = event->pos();
|
m_ptStartPos = event->pos();
|
||||||
|
m_oldCursor = viewport()->cursor();
|
||||||
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
|
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
|
||||||
event->accept();
|
event->accept();
|
||||||
viewport()->setCursor(Qt::ClosedHandCursor);
|
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::mouseReleaseEvent ( event ); // First because need to hide a rubber band
|
||||||
QGraphicsView::setDragMode( QGraphicsView::NoDrag );
|
QGraphicsView::setDragMode( QGraphicsView::NoDrag );
|
||||||
|
if (event->button() == Qt::MiddleButton)
|
||||||
|
{
|
||||||
|
viewport()->setCursor(m_oldCursor);
|
||||||
|
}
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
emit MouseRelease();
|
emit MouseRelease();
|
||||||
|
|
|
@ -152,6 +152,7 @@ private:
|
||||||
bool showToolOptions;
|
bool showToolOptions;
|
||||||
bool isAllowRubberBand;
|
bool isAllowRubberBand;
|
||||||
QPoint m_ptStartPos;
|
QPoint m_ptStartPos;
|
||||||
|
QCursor m_oldCursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VMAINGRAPHICSVIEW_H
|
#endif // VMAINGRAPHICSVIEW_H
|
||||||
|
|
|
@ -642,10 +642,6 @@ void VTextGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME)
|
||||||
*/
|
*/
|
||||||
void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE)
|
void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE)
|
||||||
{
|
{
|
||||||
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
||||||
{
|
|
||||||
setCursor(QCursor());
|
|
||||||
}
|
|
||||||
VPieceItem::hoverLeaveEvent(pHE);
|
VPieceItem::hoverLeaveEvent(pHE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user