Fix bug with mouse cursor when use line tool.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-11-13 11:03:12 +02:00
parent 132b7c9fc6
commit 736d21d71c
2 changed files with 17 additions and 7 deletions

View File

@ -66,14 +66,15 @@ VToolLine::VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent)
firstPoint(initData.firstPoint), firstPoint(initData.firstPoint),
secondPoint(initData.secondPoint), secondPoint(initData.secondPoint),
lineColor(initData.lineColor), lineColor(initData.lineColor),
m_isHovered(false) m_isHovered(false),
m_acceptHoverEvents(true)
{ {
this->m_lineType = initData.typeLine; this->m_lineType = initData.typeLine;
//Line //Line
RefreshGeometry(); RefreshGeometry();
this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); this->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(m_acceptHoverEvents);
ToolCreation(initData.typeCreation); ToolCreation(initData.typeCreation);
} }
@ -232,7 +233,8 @@ void VToolLine::Disable(bool disable, const QString &namePP)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolLine::AllowHover(bool enabled) void VToolLine::AllowHover(bool enabled)
{ {
setAcceptHoverEvents(enabled); // Manually handle hover events. Need for setting cursor for not selectable paths.
m_acceptHoverEvents = enabled;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -285,9 +287,16 @@ void VToolLine::AddToFile()
*/ */
void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (m_acceptHoverEvents)
{
m_isHovered = true; m_isHovered = true;
setToolTip(MakeToolTip()); setToolTip(MakeToolTip());
QGraphicsLineItem::hoverEnterEvent(event); QGraphicsLineItem::hoverEnterEvent(event);
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -297,7 +306,7 @@ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
*/ */
void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (vis.isNull()) if (m_acceptHoverEvents && vis.isNull())
{ {
m_isHovered = false; m_isHovered = false;
QGraphicsLineItem::hoverLeaveEvent(event); QGraphicsLineItem::hoverLeaveEvent(event);

View File

@ -125,6 +125,7 @@ private:
QString lineColor; QString lineColor;
bool m_isHovered; bool m_isHovered;
bool m_acceptHoverEvents;
VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent = nullptr); VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent = nullptr);