Fix bug with setting cursor QGraphicsPathItem without hover events.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-30 11:08:25 +02:00
parent 6e194e966b
commit 7a11b3497a
13 changed files with 89 additions and 57 deletions

View File

@ -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());
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -113,6 +113,7 @@ protected:
SceneObject sceneType;
bool m_isHovered;
bool detailsMode;
bool m_acceptHoverEvents;
/**
* @brief RefreshGeometry refresh item on scene.
*/

View File

@ -492,6 +492,8 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (m_acceptHoverEvents)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{
@ -499,24 +501,32 @@ void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
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);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSpline::SetVisualization()

View File

@ -653,6 +653,8 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (m_acceptHoverEvents)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{
@ -663,22 +665,32 @@ void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
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);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSplinePath::SetVisualization()

View File

@ -319,11 +319,6 @@ void VToolBasePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VToolBasePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
VToolSinglePoint::hoverLeaveEvent(event);
if (flags() & QGraphicsItem::ItemIsMovable)
{
setCursor(QCursor());
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);
@ -1131,24 +1132,33 @@ void VToolSeamAllowance::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (m_acceptHoverEvents)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
QGraphicsPathItem::hoverEnterEvent(event);
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
//Disable cursor-arrow-openhand
if (flags() & QGraphicsItem::ItemIsMovable)
if (m_acceptHoverEvents)
{
setCursor(QCursor());
}
QGraphicsPathItem::hoverLeaveEvent(event);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *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);

View File

@ -182,6 +182,8 @@ private:
QGraphicsPathItem *m_passmarks;
QGraphicsPathItem *m_placeLabels;
bool m_acceptHoverEvents;
VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr);
void UpdateExcludeState();

View File

@ -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);
}

View File

@ -522,7 +522,6 @@ void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{
setCursor(QCursor());
m_penWidth = LINE_PEN_WIDTH;
}
VPieceItem::hoverLeaveEvent(pME);

View File

@ -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);
}

View File

@ -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();

View File

@ -152,6 +152,7 @@ private:
bool showToolOptions;
bool isAllowRubberBand;
QPoint m_ptStartPos;
QCursor m_oldCursor;
};
#endif // VMAINGRAPHICSVIEW_H

View File

@ -642,10 +642,6 @@ void VTextGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME)
*/
void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{
setCursor(QCursor());
}
VPieceItem::hoverLeaveEvent(pHE);
}