Improve working with mouse cursors. Instead of setting global value set cursor

for each item separately.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-08-01 14:35:48 +03:00
parent 145a0923cb
commit 0894f686ef
18 changed files with 63 additions and 200 deletions

View File

@ -2199,10 +2199,7 @@ void MainWindow::ArrowTool()
ui->view->AllowRubberBand(true); ui->view->AllowRubberBand(true);
RestoreOverrideCursor(cursorArrowCloseHand); ui->view->setCursor(Qt::ArrowCursor);
RestoreOverrideCursor(cursorArrowOpenHand);
QCursor cur(Qt::ArrowCursor);
ui->view->setCursor(cur);
helpLabel->setText(""); helpLabel->setText("");
ui->view->setShowToolOptions(true); ui->view->setShowToolOptions(true);
qCDebug(vMainWindow, "Enabled arrow tool."); qCDebug(vMainWindow, "Enabled arrow tool.");

View File

@ -51,6 +51,8 @@
#include <QStringData> #include <QStringData>
#include <QStringDataPtr> #include <QStringDataPtr>
#include <QtDebug> #include <QtDebug>
#include <QPixmapCache>
#include <QGraphicsItem>
#include "vabstractapplication.h" #include "vabstractapplication.h"
@ -125,97 +127,28 @@ const QString unitINCH = QStringLiteral("inch");
const QString unitPX = QStringLiteral("px"); const QString unitPX = QStringLiteral("px");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void SetOverrideCursor(const QString &pixmapPath, int hotX, int hotY) void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
{ {
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
QPixmap oldPixmap; SCASSERT(item != nullptr)
if (QCursor *oldCursor = QGuiApplication::overrideCursor())
{
oldPixmap = oldCursor->pixmap();
}
QPixmap newPixmap(pixmapPath);
QImage oldImage = oldPixmap.toImage(); QPixmap pixmap;
QImage newImage = newPixmap.toImage();
if (oldImage != newImage ) if (not QPixmapCache::find(pixmapPath, pixmap))
{ {
QGuiApplication::setOverrideCursor(QCursor(newPixmap, hotX, hotY)); pixmap = QPixmap(pixmapPath);
QPixmapCache::insert(pixmapPath, pixmap);
} }
item->setCursor(QCursor(pixmap, hotX, hotY));
#else #else
Q_UNUSED(item)
Q_UNUSED(pixmapPath) Q_UNUSED(pixmapPath)
Q_UNUSED(hotX) Q_UNUSED(hotX)
Q_UNUSED(hotY) Q_UNUSED(hotY)
#endif #endif
} }
//---------------------------------------------------------------------------------------------------------------------
void SetOverrideCursor(Qt::CursorShape shape)
{
#ifndef QT_NO_CURSOR
QPixmap oldPixmap;
QCursor* pOldCursor = QGuiApplication::overrideCursor();
if (pOldCursor != nullptr)
{
oldPixmap = pOldCursor->pixmap();
}
QCursor cursor(shape);
QPixmap newPixmap = cursor.pixmap();
if (oldPixmap.toImage() != newPixmap.toImage())
{
QGuiApplication::setOverrideCursor(cursor);
}
#else
Q_UNUSED(shape)
#endif
}
//---------------------------------------------------------------------------------------------------------------------
void RestoreOverrideCursor(const QString &pixmapPath)
{
#ifndef QT_NO_CURSOR
QPixmap oldPixmap;
if (QCursor *oldCursor = QGuiApplication::overrideCursor())
{
oldPixmap = oldCursor->pixmap();
}
QPixmap newPixmap(pixmapPath);
QImage oldImage = oldPixmap.toImage();
QImage newImage = newPixmap.toImage();
if (oldImage == newImage )
{
QGuiApplication::restoreOverrideCursor();
}
#else
Q_UNUSED(pixmapPath)
#endif
}
//---------------------------------------------------------------------------------------------------------------------
void RestoreOverrideCursor(Qt::CursorShape shape)
{
#ifndef QT_NO_CURSOR
QPixmap oldPixmap;
QCursor* pOldCursor = QGuiApplication::overrideCursor();
if (pOldCursor != nullptr)
{
oldPixmap = pOldCursor->pixmap();
}
QCursor cursor(shape);
QPixmap newPixmap = cursor.pixmap();
if (oldPixmap.toImage() == newPixmap.toImage())
{
QGuiApplication::restoreOverrideCursor();
}
#else
Q_UNUSED(shape)
#endif
}
const qreal PrintDPI = 96.0; const qreal PrintDPI = 96.0;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -51,6 +51,7 @@ template <class T> class QSharedPointer;
class QComboBox; class QComboBox;
class QMarginsF; class QMarginsF;
class VTranslateMeasurements; class VTranslateMeasurements;
class QGraphicsItem;
#define SceneSize 50000 #define SceneSize 50000
@ -373,10 +374,7 @@ extern const QString unitCM;
extern const QString unitINCH; extern const QString unitINCH;
extern const QString unitPX; extern const QString unitPX;
void SetOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); void SetItemOverrideCursor(QGraphicsItem *item, const QString & pixmapPath, int hotX = -1, int hotY = -1);
void SetOverrideCursor(Qt::CursorShape shape);
void RestoreOverrideCursor(const QString & pixmapPath);
void RestoreOverrideCursor(Qt::CursorShape shape);
extern const qreal PrintDPI; extern const qreal PrintDPI;

View File

@ -7,7 +7,7 @@
# File with common stuff for whole project # File with common stuff for whole project
include(../../../common.pri) include(../../../common.pri)
QT += widgets printsupport testlib QT += widgets printsupport testlib gui
# Name of library # Name of library
TARGET = vmisc TARGET = vmisc

View File

@ -122,13 +122,6 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co
ToolCreation(typeCreation); ToolCreation(typeCreation);
} }
//---------------------------------------------------------------------------------------------------------------------
VToolSpline::~VToolSpline()
{
//Disable cursor-arrow-openhand
RestoreOverrideCursor(cursorArrowOpenHand);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setDialog set dialog when user want change tool option. * @brief setDialog set dialog when user want change tool option.
@ -367,7 +360,7 @@ void VToolSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (IsMovable()) if (IsMovable())
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
oldPosition = event->scenePos(); oldPosition = event->scenePos();
event->accept(); event->accept();
} }
@ -385,8 +378,7 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (IsMovable()) if (IsMovable())
{ {
//Disable cursor-arrow-closehand SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
RestoreOverrideCursor(cursorArrowCloseHand);
} }
} }
} }
@ -477,7 +469,7 @@ void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (IsMovable()) if (IsMovable())
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
} }
@ -491,8 +483,7 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (IsMovable()) if (IsMovable())
{ {
//Disable cursor-arrow-openhand setCursor(QCursor());
RestoreOverrideCursor(cursorArrowOpenHand);
} }
} }

View File

@ -51,7 +51,7 @@ class VToolSpline:public VAbstractSpline
{ {
Q_OBJECT Q_OBJECT
public: public:
virtual ~VToolSpline() Q_DECL_OVERRIDE; virtual ~VToolSpline() =default;
virtual void setDialog() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE;
static VToolSpline *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, static VToolSpline *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data); VContainer *data);

View File

@ -131,13 +131,6 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
ToolCreation(typeCreation); ToolCreation(typeCreation);
} }
//---------------------------------------------------------------------------------------------------------------------
VToolSplinePath::~VToolSplinePath()
{
//Disable cursor-arrow-openhand
RestoreOverrideCursor(cursorArrowOpenHand);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setDialog set dialog when user want change tool option. * @brief setDialog set dialog when user want change tool option.
@ -491,7 +484,7 @@ void VToolSplinePath::mousePressEvent(QGraphicsSceneMouseEvent *event)
splIndex = splPath->Segment(oldPosition); splIndex = splPath->Segment(oldPosition);
if (IsMovable(splIndex)) if (IsMovable(splIndex))
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
event->accept(); event->accept();
} }
} }
@ -507,8 +500,7 @@ void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
oldPosition = event->scenePos(); oldPosition = event->scenePos();
//Disable cursor-arrow-closehand SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
RestoreOverrideCursor(cursorArrowCloseHand);
} }
} }
VAbstractSpline::mouseReleaseEvent(event); VAbstractSpline::mouseReleaseEvent(event);
@ -606,7 +598,7 @@ void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
splIndex = splPath->Segment(oldPosition); splIndex = splPath->Segment(oldPosition);
if (IsMovable(splIndex)) if (IsMovable(splIndex))
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
} }
@ -619,8 +611,7 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
oldPosition = event->scenePos(); oldPosition = event->scenePos();
//Disable cursor-arrow-openhand setCursor(QCursor());
RestoreOverrideCursor(cursorArrowOpenHand);
} }
VAbstractSpline::hoverLeaveEvent(event); VAbstractSpline::hoverLeaveEvent(event);

View File

@ -53,7 +53,7 @@ class VToolSplinePath:public VAbstractSpline
{ {
Q_OBJECT Q_OBJECT
public: public:
virtual ~VToolSplinePath() Q_DECL_OVERRIDE; virtual ~VToolSplinePath() =default;
virtual void setDialog() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE;
static VToolSplinePath *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, static VToolSplinePath *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data); VAbstractPattern *doc, VContainer *data);

View File

@ -90,13 +90,6 @@ VToolBasePoint::VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32
ToolCreation(typeCreation); ToolCreation(typeCreation);
} }
//---------------------------------------------------------------------------------------------------------------------
VToolBasePoint::~VToolBasePoint()
{
//Disable cursor-arrow-openhand
RestoreOverrideCursor(cursorArrowOpenHand);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setDialog set dialog when user want change tool option. * @brief setDialog set dialog when user want change tool option.
@ -316,7 +309,7 @@ void VToolBasePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
} }
@ -327,8 +320,7 @@ void VToolBasePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
//Disable cursor-arrow-openhand setCursor(QCursor());
RestoreOverrideCursor(cursorArrowOpenHand);
} }
} }
@ -339,7 +331,7 @@ void VToolBasePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
VToolSinglePoint::mousePressEvent(event); VToolSinglePoint::mousePressEvent(event);
@ -352,8 +344,7 @@ void VToolBasePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
//Disable cursor-arrow-closehand SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
RestoreOverrideCursor(cursorArrowCloseHand);
} }
} }
VToolSinglePoint::mouseReleaseEvent(event); VToolSinglePoint::mouseReleaseEvent(event);

View File

@ -53,7 +53,7 @@ class VToolBasePoint : public VToolSinglePoint
{ {
Q_OBJECT Q_OBJECT
public: public:
virtual ~VToolBasePoint() Q_DECL_OVERRIDE; virtual ~VToolBasePoint() =default;
virtual void setDialog() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE;
static VToolBasePoint *Create(quint32 _id, const QString &nameActivPP, VPointF *point, static VToolBasePoint *Create(quint32 _id, const QString &nameActivPP, VPointF *point,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,

View File

@ -975,7 +975,7 @@ void VToolSeamAllowance::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
@ -993,28 +993,17 @@ void VToolSeamAllowance::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
{ {
//Disable cursor-arrow-closehand SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
RestoreOverrideCursor(cursorArrowCloseHand);
} }
QGraphicsPathItem::mouseReleaseEvent(event); QGraphicsPathItem::mouseReleaseEvent(event);
} }
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
if (flags() & QGraphicsItem::ItemIsMovable)
{
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
QGraphicsPathItem::hoverEnterEvent(event); QGraphicsPathItem::hoverEnterEvent(event);
} }
@ -1025,7 +1014,7 @@ void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
//Disable cursor-arrow-openhand //Disable cursor-arrow-openhand
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
RestoreOverrideCursor(cursorArrowOpenHand); setCursor(QCursor());
} }
QGraphicsPathItem::hoverLeaveEvent(event); QGraphicsPathItem::hoverLeaveEvent(event);
} }

View File

@ -126,7 +126,6 @@ protected:
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE;
virtual void mousePressEvent( QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE; virtual void mousePressEvent( QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE;

View File

@ -91,13 +91,6 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP
SetCtrlLine(controlPoint, splinePoint); SetCtrlLine(controlPoint, splinePoint);
} }
//---------------------------------------------------------------------------------------------------------------------
VControlPointSpline::~VControlPointSpline()
{
//Disable cursor-arrow-openhand
RestoreOverrideCursor(cursorArrowOpenHand);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
@ -117,7 +110,7 @@ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (freeAngle || freeLength) if (freeAngle || freeLength)
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
VScenePoint::hoverEnterEvent(event); VScenePoint::hoverEnterEvent(event);
} }
@ -127,8 +120,7 @@ void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (freeAngle || freeLength) if (freeAngle || freeLength)
{ {
//Disable cursor-arrow-openhand setCursor(QCursor());
RestoreOverrideCursor(cursorArrowOpenHand);
} }
VScenePoint::hoverLeaveEvent(event); VScenePoint::hoverLeaveEvent(event);
} }
@ -226,7 +218,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (freeAngle || freeLength) if (freeAngle || freeLength)
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
VScenePoint::mousePressEvent(event); VScenePoint::mousePressEvent(event);
@ -239,8 +231,7 @@ void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (freeAngle || freeLength) if (freeAngle || freeLength)
{ {
//Disable cursor-arrow-closehand SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
RestoreOverrideCursor(cursorArrowCloseHand);
} }
} }
VScenePoint::mouseReleaseEvent(event); VScenePoint::mouseReleaseEvent(event);

View File

@ -53,7 +53,7 @@ public:
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem * parent = nullptr); VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem * parent = nullptr);
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint,
const QPointF &splinePoint, bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr); const QPointF &splinePoint, bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr);
virtual ~VControlPointSpline(); virtual ~VControlPointSpline() =default;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ControlPointSpline)}; enum { Type = UserType + static_cast<int>(Vis::ControlPointSpline)};

View File

@ -305,7 +305,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME)
else else
{ {
m_eMode = mRotate; m_eMode = mRotate;
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
setZValue(ACTIVE_Z); setZValue(ACTIVE_Z);
Update(); Update();
@ -336,7 +336,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME)
else else
{ {
m_eMode = mMove; m_eMode = mMove;
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
setZValue(ACTIVE_Z); setZValue(ACTIVE_Z);
@ -458,13 +458,9 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
{ {
if (pME->button() == Qt::LeftButton) if (pME->button() == Qt::LeftButton)
{ {
if (m_eMode == mMove || m_eMode == mRotate) if (m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize)
{ {
RestoreOverrideCursor(cursorArrowCloseHand); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else if (m_eMode == mResize)
{
RestoreOverrideCursor(Qt::SizeFDiagCursor);
} }
QPointF ptDiff = pME->scenePos() - m_ptStartMove; QPointF ptDiff = pME->scenePos() - m_ptStartMove;
@ -709,7 +705,7 @@ void VGrainlineItem::AllUserModifications(const QPointF &pos)
} }
else else
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
@ -720,7 +716,7 @@ void VGrainlineItem::UserRotateAndMove()
{ {
m_eMode = mMove; m_eMode = mMove;
} }
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -729,12 +725,12 @@ void VGrainlineItem::UserMoveAndResize(const QPointF &pos)
if (m_polyResize.containsPoint(pos, Qt::OddEvenFill) == true) if (m_polyResize.containsPoint(pos, Qt::OddEvenFill) == true)
{ {
m_eMode = mResize; m_eMode = mResize;
SetOverrideCursor(Qt::SizeFDiagCursor); setCursor(Qt::SizeFDiagCursor);
} }
else else
{ {
m_eMode = mMove; // block later if need m_eMode = mMove; // block later if need
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }

View File

@ -81,13 +81,6 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
} }
//---------------------------------------------------------------------------------------------------------------------
VGraphicsSimpleTextItem::~VGraphicsSimpleTextItem()
{
//Disable cursor-arrow-openhand
RestoreOverrideCursor(cursorArrowOpenHand);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
@ -194,7 +187,7 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
SetOverrideCursor(cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
this->setBrush(Qt::green); this->setBrush(Qt::green);
QGraphicsSimpleTextItem::hoverEnterEvent(event); QGraphicsSimpleTextItem::hoverEnterEvent(event);
@ -209,8 +202,7 @@ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (flags() & QGraphicsItem::ItemIsMovable) if (flags() & QGraphicsItem::ItemIsMovable)
{ {
//Disable cursor-arrow-openhand setCursor(QCursor());
RestoreOverrideCursor(cursorArrowOpenHand);
} }
this->setBrush(Qt::black); this->setBrush(Qt::black);
QGraphicsSimpleTextItem::hoverLeaveEvent(event); QGraphicsSimpleTextItem::hoverLeaveEvent(event);
@ -242,7 +234,7 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
if (selectionType == SelectionType::ByMouseRelease) if (selectionType == SelectionType::ByMouseRelease)
@ -262,8 +254,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
//Disable cursor-arrow-closehand SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
RestoreOverrideCursor(cursorArrowCloseHand);
} }
} }

View File

@ -50,7 +50,7 @@ class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem
public: public:
explicit VGraphicsSimpleTextItem(QGraphicsItem *parent = nullptr); explicit VGraphicsSimpleTextItem(QGraphicsItem *parent = nullptr);
explicit VGraphicsSimpleTextItem( const QString & text, QGraphicsItem *parent = nullptr ); explicit VGraphicsSimpleTextItem( const QString & text, QGraphicsItem *parent = nullptr );
virtual ~VGraphicsSimpleTextItem() Q_DECL_OVERRIDE; virtual ~VGraphicsSimpleTextItem() =default;
qint32 BaseFontSize()const; qint32 BaseFontSize()const;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -432,7 +432,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
else else
{ {
m_eMode = mRotate; m_eMode = mRotate;
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
setZValue(ACTIVE_Z); setZValue(ACTIVE_Z);
Update(); Update();
@ -463,7 +463,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
else else
{ {
m_eMode = mMove; m_eMode = mMove;
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
setZValue(ACTIVE_Z); setZValue(ACTIVE_Z);
@ -572,13 +572,9 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
if (pME->button() == Qt::LeftButton) if (pME->button() == Qt::LeftButton)
{ {
// restore the cursor // restore the cursor
if (m_eMode == mMove || m_eMode == mRotate) if (m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize)
{ {
RestoreOverrideCursor(cursorArrowCloseHand); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
}
else if (m_eMode == mResize)
{
RestoreOverrideCursor(Qt::SizeFDiagCursor);
} }
double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y());
// determine if this was just press/release (bShort == true) or user did some operation between press and release // determine if this was just press/release (bShort == true) or user did some operation between press and release
@ -634,11 +630,11 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE)
{ {
if (m_rectResize.contains(pHE->pos()) == true) if (m_rectResize.contains(pHE->pos()) == true)
{ {
SetOverrideCursor(Qt::SizeFDiagCursor); setCursor(Qt::SizeFDiagCursor);
} }
else else
{ {
RestoreOverrideCursor(Qt::SizeFDiagCursor); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
} }
VPieceItem::hoverMoveEvent(pHE); VPieceItem::hoverMoveEvent(pHE);
@ -651,7 +647,7 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE)
*/ */
void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE)
{ {
RestoreOverrideCursor(Qt::SizeFDiagCursor); setCursor(QCursor());
VPieceItem::hoverLeaveEvent(pHE); VPieceItem::hoverLeaveEvent(pHE);
} }
@ -694,7 +690,7 @@ void VTextGraphicsItem::AllUserModifications(const QPointF &pos)
} }
else else
{ {
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
@ -705,7 +701,7 @@ void VTextGraphicsItem::UserRotateAndMove()
{ {
m_eMode = mMove; m_eMode = mMove;
} }
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -714,11 +710,11 @@ void VTextGraphicsItem::UserMoveAndResize(const QPointF &pos)
if (m_rectResize.contains(pos) == true) if (m_rectResize.contains(pos) == true)
{ {
m_eMode = mResize; m_eMode = mResize;
SetOverrideCursor(Qt::SizeFDiagCursor); setCursor(Qt::SizeFDiagCursor);
} }
else else
{ {
m_eMode = mMove; // block later if need m_eMode = mMove; // block later if need
SetOverrideCursor(cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }