Fix QGraphicsView cursor regression.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-12 14:31:45 +02:00
parent b8c8c284a8
commit 15339939ef
3 changed files with 20 additions and 10 deletions

View file

@ -208,11 +208,8 @@ const QString unitINCH = QStringLiteral("inch");
const QString unitPX = QStringLiteral("px");
//---------------------------------------------------------------------------------------------------------------------
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
QPixmap QPixmapFromCache(const QString &pixmapPath)
{
#ifndef QT_NO_CURSOR
SCASSERT(item != nullptr)
QPixmap pixmap;
if (not QPixmapCache::find(pixmapPath, pixmap))
@ -220,8 +217,15 @@ void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int h
pixmap = QPixmap(pixmapPath);
QPixmapCache::insert(pixmapPath, pixmap);
}
return pixmap;
}
item->setCursor(QCursor(pixmap, hotX, hotY));
//---------------------------------------------------------------------------------------------------------------------
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
{
#ifndef QT_NO_CURSOR
SCASSERT(item != nullptr)
item->setCursor(QCursor(QPixmapFromCache(pixmapPath), hotX, hotY));
#else
Q_UNUSED(item)
Q_UNUSED(pixmapPath)

View file

@ -413,6 +413,7 @@ extern const QString unitCM;
extern const QString unitINCH;
extern const QString unitPX;
QPixmap QPixmapFromCache(const QString &pixmapPath);
void SetItemOverrideCursor(QGraphicsItem *item, const QString & pixmapPath, int hotX = -1, int hotY = -1);
Q_REQUIRED_RESULT double ToPixel(double val, const Unit &unit);

View file

@ -504,12 +504,17 @@ 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())
if (dragMode() != QGraphicsView::ScrollHandDrag)
{
viewport()->setCursor(m_currentCursor);
QCursor cur = viewport()->cursor();
// No way to restore bitmap from shape and we really don't need this for now.
if (m_currentCursor != Qt::BitmapCursor
&& cur.shape() == Qt::BitmapCursor
&& cur.pixmap().cacheKey() != QPixmapFromCache(cursorArrowOpenHand).cacheKey()
&& cur.pixmap().cacheKey() != QPixmapFromCache(cursorArrowCloseHand).cacheKey())
{
viewport()->setCursor(m_currentCursor);
}
}
if (dragMode() == QGraphicsView::ScrollHandDrag)