New hack to restore mouse cursor.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-01 16:16:50 +02:00
parent a99212e89a
commit 34d1b91225
5 changed files with 32 additions and 1 deletions

View File

@ -608,6 +608,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
QPixmap pixmap(cursorResource);
QCursor cur(pixmap, 2, 2);
ui->view->viewport()->setCursor(cur);
ui->view->setCurrentCursorShape(); // Hack to fix problem with a cursor
helpLabel->setText(toolTip);
ui->view->setShowToolOptions(false);
dialogTool = QSharedPointer<Dialog>(new Dialog(pattern, 0, this));
@ -2315,7 +2316,9 @@ void MainWindow::ArrowTool(bool checked)
emit EnableDetailHover(true);
ui->view->AllowRubberBand(true);
ui->view->viewport()->unsetCursor();
ui->view->viewport()->setCursor(QCursor(Qt::ArrowCursor));
ui->view->setCurrentCursorShape(); // Hack to fix problem with a cursor
helpLabel->setText("");
ui->view->setShowToolOptions(true);
qCDebug(vMainWindow, "Enabled arrow tool.");

View File

@ -358,12 +358,14 @@ void VToolSinglePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
void VToolSinglePoint::AllowHover(bool enabled)
{
setAcceptHoverEvents(enabled);
AllowLabelHover(enabled);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::AllowSelecting(bool enabled)
{
setFlag(QGraphicsItem::ItemIsSelectable, enabled);
AllowLabelSelecting(enabled);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -48,6 +48,7 @@
#include "global.h"
#include "vscenepoint.h"
#include "../vmisc/vmath.h"
#include "../vmisc/vabstractapplication.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -211,6 +212,11 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else
{
setCursor(qApp->getSceneView()->viewport()->cursor());
}
this->setBrush(Qt::green);
if(QGraphicsItem *parent = parentItem())

View File

@ -353,7 +353,8 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
showToolOptions(true),
isAllowRubberBand(true),
m_ptStartPos(),
m_oldCursor()
m_oldCursor(),
m_currentCursor(Qt::ArrowCursor)
{
this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
@ -486,6 +487,16 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
// Hack to fix problem with mouse cursor. Looks like after we switch cursor back it is rewrited back by a dialog.
// Because no real way to catch this call we will check state for each move and compare to excpected state.
if (dragMode() != QGraphicsView::ScrollHandDrag &&
// No way to restore bitmap from shape and we really don't need this for now.
m_currentCursor != Qt::BitmapCursor &&
m_currentCursor != viewport()->cursor().shape())
{
viewport()->setCursor(m_currentCursor);
}
if (dragMode() == QGraphicsView::ScrollHandDrag)
{
QScrollBar *hBar = horizontalScrollBar();
@ -566,6 +577,12 @@ void VMainGraphicsView::EnsureVisibleWithDelay(const QGraphicsItem *item, unsign
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::setCurrentCursorShape()
{
m_currentCursor = viewport()->cursor().shape();
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::setShowToolOptions(bool value)
{

View File

@ -129,6 +129,8 @@ public:
static const unsigned long scrollDelay;
void setCurrentCursorShape();
signals:
/**
* @brief MouseRelease help catch mouse release event.
@ -153,6 +155,7 @@ private:
bool isAllowRubberBand;
QPoint m_ptStartPos;
QCursor m_oldCursor;
Qt::CursorShape m_currentCursor;
};
#endif // VMAINGRAPHICSVIEW_H