From 0894f686ef37736736b19d2d2538555d7be4c20a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 1 Aug 2017 14:35:48 +0300 Subject: [PATCH] Improve working with mouse cursors. Instead of setting global value set cursor for each item separately. --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 5 +- src/libs/vmisc/def.cpp | 89 +++---------------- src/libs/vmisc/def.h | 6 +- src/libs/vmisc/vmisc.pro | 2 +- .../tools/drawTools/toolcurve/vtoolspline.cpp | 17 +--- .../tools/drawTools/toolcurve/vtoolspline.h | 2 +- .../drawTools/toolcurve/vtoolsplinepath.cpp | 17 +--- .../drawTools/toolcurve/vtoolsplinepath.h | 2 +- .../toolsinglepoint/vtoolbasepoint.cpp | 17 +--- .../toolsinglepoint/vtoolbasepoint.h | 2 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 19 +--- src/libs/vtools/tools/vtoolseamallowance.h | 1 - src/libs/vwidgets/vcontrolpointspline.cpp | 17 +--- src/libs/vwidgets/vcontrolpointspline.h | 2 +- src/libs/vwidgets/vgrainlineitem.cpp | 20 ++--- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 17 +--- src/libs/vwidgets/vgraphicssimpletextitem.h | 2 +- src/libs/vwidgets/vtextgraphicsitem.cpp | 26 +++--- 18 files changed, 63 insertions(+), 200 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d2483cd60..299e437a3 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2199,10 +2199,7 @@ void MainWindow::ArrowTool() ui->view->AllowRubberBand(true); - RestoreOverrideCursor(cursorArrowCloseHand); - RestoreOverrideCursor(cursorArrowOpenHand); - QCursor cur(Qt::ArrowCursor); - ui->view->setCursor(cur); + ui->view->setCursor(Qt::ArrowCursor); helpLabel->setText(""); ui->view->setShowToolOptions(true); qCDebug(vMainWindow, "Enabled arrow tool."); diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 9f84557d1..4bb1adb3d 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -51,6 +51,8 @@ #include #include #include +#include +#include #include "vabstractapplication.h" @@ -125,97 +127,28 @@ const QString unitINCH = QStringLiteral("inch"); 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 - QPixmap oldPixmap; - if (QCursor *oldCursor = QGuiApplication::overrideCursor()) - { - oldPixmap = oldCursor->pixmap(); - } - QPixmap newPixmap(pixmapPath); + SCASSERT(item != nullptr) - QImage oldImage = oldPixmap.toImage(); - QImage newImage = newPixmap.toImage(); + QPixmap pixmap; - 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 + Q_UNUSED(item) Q_UNUSED(pixmapPath) Q_UNUSED(hotX) Q_UNUSED(hotY) #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; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 64a4cbd3d..23cff43ea 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -51,6 +51,7 @@ template class QSharedPointer; class QComboBox; class QMarginsF; class VTranslateMeasurements; +class QGraphicsItem; #define SceneSize 50000 @@ -373,10 +374,7 @@ extern const QString unitCM; extern const QString unitINCH; extern const QString unitPX; -void SetOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); -void SetOverrideCursor(Qt::CursorShape shape); -void RestoreOverrideCursor(const QString & pixmapPath); -void RestoreOverrideCursor(Qt::CursorShape shape); +void SetItemOverrideCursor(QGraphicsItem *item, const QString & pixmapPath, int hotX = -1, int hotY = -1); extern const qreal PrintDPI; diff --git a/src/libs/vmisc/vmisc.pro b/src/libs/vmisc/vmisc.pro index 6b9083695..b57844181 100644 --- a/src/libs/vmisc/vmisc.pro +++ b/src/libs/vmisc/vmisc.pro @@ -7,7 +7,7 @@ # File with common stuff for whole project include(../../../common.pri) -QT += widgets printsupport testlib +QT += widgets printsupport testlib gui # Name of library TARGET = vmisc diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 86758caba..40f863f0c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -122,13 +122,6 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co ToolCreation(typeCreation); } -//--------------------------------------------------------------------------------------------------------------------- -VToolSpline::~VToolSpline() -{ - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. @@ -367,7 +360,7 @@ void VToolSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (IsMovable()) { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); oldPosition = event->scenePos(); event->accept(); } @@ -385,8 +378,7 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (IsMovable()) { - //Disable cursor-arrow-closehand - RestoreOverrideCursor(cursorArrowCloseHand); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } } @@ -477,7 +469,7 @@ void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if (IsMovable()) { - SetOverrideCursor(cursorArrowOpenHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } @@ -491,8 +483,7 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { if (IsMovable()) { - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); + setCursor(QCursor()); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index 83f9b24e2..ed7f09faf 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -51,7 +51,7 @@ class VToolSpline:public VAbstractSpline { Q_OBJECT public: - virtual ~VToolSpline() Q_DECL_OVERRIDE; + virtual ~VToolSpline() =default; virtual void setDialog() Q_DECL_OVERRIDE; static VToolSpline *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index b4f21f940..5e3336a2d 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -131,13 +131,6 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 ToolCreation(typeCreation); } -//--------------------------------------------------------------------------------------------------------------------- -VToolSplinePath::~VToolSplinePath() -{ - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. @@ -491,7 +484,7 @@ void VToolSplinePath::mousePressEvent(QGraphicsSceneMouseEvent *event) splIndex = splPath->Segment(oldPosition); if (IsMovable(splIndex)) { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); event->accept(); } } @@ -507,8 +500,7 @@ void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { oldPosition = event->scenePos(); - //Disable cursor-arrow-closehand - RestoreOverrideCursor(cursorArrowCloseHand); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } VAbstractSpline::mouseReleaseEvent(event); @@ -606,7 +598,7 @@ void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event) splIndex = splPath->Segment(oldPosition); 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) { oldPosition = event->scenePos(); - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); + setCursor(QCursor()); } VAbstractSpline::hoverLeaveEvent(event); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index 35be7af14..0866b249b 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -53,7 +53,7 @@ class VToolSplinePath:public VAbstractSpline { Q_OBJECT public: - virtual ~VToolSplinePath() Q_DECL_OVERRIDE; + virtual ~VToolSplinePath() =default; virtual void setDialog() Q_DECL_OVERRIDE; static VToolSplinePath *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index 45a639f2f..565aa89ab 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -90,13 +90,6 @@ VToolBasePoint::VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 ToolCreation(typeCreation); } -//--------------------------------------------------------------------------------------------------------------------- -VToolBasePoint::~VToolBasePoint() -{ - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. @@ -316,7 +309,7 @@ void VToolBasePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) 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) { - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); + setCursor(QCursor()); } } @@ -339,7 +331,7 @@ void VToolBasePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } } VToolSinglePoint::mousePressEvent(event); @@ -352,8 +344,7 @@ void VToolBasePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - //Disable cursor-arrow-closehand - RestoreOverrideCursor(cursorArrowCloseHand); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } VToolSinglePoint::mouseReleaseEvent(event); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index c6ef49140..c41fd8dce 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -53,7 +53,7 @@ class VToolBasePoint : public VToolSinglePoint { Q_OBJECT public: - virtual ~VToolBasePoint() Q_DECL_OVERRIDE; + virtual ~VToolBasePoint() =default; virtual void setDialog() Q_DECL_OVERRIDE; static VToolBasePoint *Create(quint32 _id, const QString &nameActivPP, VPointF *point, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index d2d5deb29..0b36ce074 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -975,7 +975,7 @@ void VToolSeamAllowance::mousePressEvent(QGraphicsSceneMouseEvent *event) { 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) { - //Disable cursor-arrow-closehand - RestoreOverrideCursor(cursorArrowCloseHand); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } QGraphicsPathItem::mouseReleaseEvent(event); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolSeamAllowance::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - if (flags() & QGraphicsItem::ItemIsMovable) - { - SetOverrideCursor(cursorArrowOpenHand, 1, 1); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if (flags() & QGraphicsItem::ItemIsMovable) { - SetOverrideCursor(cursorArrowOpenHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } QGraphicsPathItem::hoverEnterEvent(event); } @@ -1025,7 +1014,7 @@ void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) //Disable cursor-arrow-openhand if (flags() & QGraphicsItem::ItemIsMovable) { - RestoreOverrideCursor(cursorArrowOpenHand); + setCursor(QCursor()); } QGraphicsPathItem::hoverLeaveEvent(event); } diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index d11f8fd4c..502286a95 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -126,7 +126,6 @@ protected: virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void mousePressEvent( 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 hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index 94a1171a5..fa8e13bce 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -91,13 +91,6 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP SetCtrlLine(controlPoint, splinePoint); } -//--------------------------------------------------------------------------------------------------------------------- -VControlPointSpline::~VControlPointSpline() -{ - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); -} - //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -117,7 +110,7 @@ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if (freeAngle || freeLength) { - SetOverrideCursor(cursorArrowOpenHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } VScenePoint::hoverEnterEvent(event); } @@ -127,8 +120,7 @@ void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { if (freeAngle || freeLength) { - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); + setCursor(QCursor()); } VScenePoint::hoverLeaveEvent(event); } @@ -226,7 +218,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (freeAngle || freeLength) { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } } VScenePoint::mousePressEvent(event); @@ -239,8 +231,7 @@ void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (freeAngle || freeLength) { - //Disable cursor-arrow-closehand - RestoreOverrideCursor(cursorArrowCloseHand); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } VScenePoint::mouseReleaseEvent(event); diff --git a/src/libs/vwidgets/vcontrolpointspline.h b/src/libs/vwidgets/vcontrolpointspline.h index d0409b282..2c337903d 100644 --- a/src/libs/vwidgets/vcontrolpointspline.h +++ b/src/libs/vwidgets/vcontrolpointspline.h @@ -53,7 +53,7 @@ public: VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem * parent = nullptr); VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, const QPointF &splinePoint, bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr); - virtual ~VControlPointSpline(); + virtual ~VControlPointSpline() =default; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ControlPointSpline)}; diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 4b7818b69..970aab0af 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -305,7 +305,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) else { m_eMode = mRotate; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); Update(); @@ -336,7 +336,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) else { m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); @@ -458,13 +458,9 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { - if (m_eMode == mMove || m_eMode == mRotate) + if (m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) { - RestoreOverrideCursor(cursorArrowCloseHand); - } - else if (m_eMode == mResize) - { - RestoreOverrideCursor(Qt::SizeFDiagCursor); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } QPointF ptDiff = pME->scenePos() - m_ptStartMove; @@ -709,7 +705,7 @@ void VGrainlineItem::AllUserModifications(const QPointF &pos) } else { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } } @@ -720,7 +716,7 @@ void VGrainlineItem::UserRotateAndMove() { 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) { m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); + setCursor(Qt::SizeFDiagCursor); } else { m_eMode = mMove; // block later if need - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 6d0387983..ffa108351 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -81,13 +81,6 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic this->setAcceptHoverEvents(true); } -//--------------------------------------------------------------------------------------------------------------------- -VGraphicsSimpleTextItem::~VGraphicsSimpleTextItem() -{ - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); -} - //--------------------------------------------------------------------------------------------------------------------- void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -194,7 +187,7 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if (flags() & QGraphicsItem::ItemIsMovable) { - SetOverrideCursor(cursorArrowOpenHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } this->setBrush(Qt::green); QGraphicsSimpleTextItem::hoverEnterEvent(event); @@ -209,8 +202,7 @@ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { if (flags() & QGraphicsItem::ItemIsMovable) { - //Disable cursor-arrow-openhand - RestoreOverrideCursor(cursorArrowOpenHand); + setCursor(QCursor()); } this->setBrush(Qt::black); QGraphicsSimpleTextItem::hoverLeaveEvent(event); @@ -242,7 +234,7 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } } if (selectionType == SelectionType::ByMouseRelease) @@ -262,8 +254,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - //Disable cursor-arrow-closehand - RestoreOverrideCursor(cursorArrowCloseHand); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.h b/src/libs/vwidgets/vgraphicssimpletextitem.h index aa48fc277..98fc5d629 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.h +++ b/src/libs/vwidgets/vgraphicssimpletextitem.h @@ -50,7 +50,7 @@ class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem public: explicit VGraphicsSimpleTextItem(QGraphicsItem *parent = nullptr); explicit VGraphicsSimpleTextItem( const QString & text, QGraphicsItem *parent = nullptr ); - virtual ~VGraphicsSimpleTextItem() Q_DECL_OVERRIDE; + virtual ~VGraphicsSimpleTextItem() =default; qint32 BaseFontSize()const; virtual int type() const Q_DECL_OVERRIDE {return Type;} diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 6e50c9c7a..cd916d53f 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -432,7 +432,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) else { m_eMode = mRotate; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); Update(); @@ -463,7 +463,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) else { m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); @@ -572,13 +572,9 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) if (pME->button() == Qt::LeftButton) { // restore the cursor - if (m_eMode == mMove || m_eMode == mRotate) + if (m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) { - RestoreOverrideCursor(cursorArrowCloseHand); - } - else if (m_eMode == mResize) - { - RestoreOverrideCursor(Qt::SizeFDiagCursor); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } 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 @@ -634,11 +630,11 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) { if (m_rectResize.contains(pHE->pos()) == true) { - SetOverrideCursor(Qt::SizeFDiagCursor); + setCursor(Qt::SizeFDiagCursor); } else { - RestoreOverrideCursor(Qt::SizeFDiagCursor); + SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); } } VPieceItem::hoverMoveEvent(pHE); @@ -651,7 +647,7 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) */ void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) { - RestoreOverrideCursor(Qt::SizeFDiagCursor); + setCursor(QCursor()); VPieceItem::hoverLeaveEvent(pHE); } @@ -694,7 +690,7 @@ void VTextGraphicsItem::AllUserModifications(const QPointF &pos) } else { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } } @@ -705,7 +701,7 @@ void VTextGraphicsItem::UserRotateAndMove() { 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) { m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); + setCursor(Qt::SizeFDiagCursor); } else { m_eMode = mMove; // block later if need - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); } }