diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index a404b9a55..e461fc1da 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -608,48 +608,6 @@ void VApplication::setCurrentScene(QGraphicsScene *value) currentScene = value; } -//--------------------------------------------------------------------------------------------------------------------- -void VApplication::setOverrideCursor(const QString &pixmapPath, int hotX, int hotY) -{ -#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 ) - { - QApplication::setOverrideCursor(QCursor(newPixmap, hotX, hotY)); - } -#endif -} - -//--------------------------------------------------------------------------------------------------------------------- -void VApplication::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 ) - { - QApplication::restoreOverrideCursor(); - } -#endif -} - //--------------------------------------------------------------------------------------------------------------------- QStringList VApplication::LabelLanguages() { diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 8ccdcca44..1427e57f8 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -105,9 +105,6 @@ public: void setCurrentDocument(VPattern *doc); VPattern *getCurrentDocument()const; - static void setOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); - static void restoreOverrideCursor(const QString & pixmapPath); - static QStringList LabelLanguages(); void StartLogging(); diff --git a/src/app/options.cpp b/src/app/options.cpp index 22f45df26..2cc70763b 100644 --- a/src/app/options.cpp +++ b/src/app/options.cpp @@ -32,6 +32,3 @@ // From documantation: If you use QStringLiteral you should avoid declaring the same literal in multiple places: This // furthermore blows up the binary sizes. const QString degreeSymbol = QStringLiteral("°"); - -const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); -const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); diff --git a/src/app/options.h b/src/app/options.h index 41e50a80d..f98ddce0c 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -52,9 +52,6 @@ class QStringList; extern const QString degreeSymbol; -extern const QString cursorArrowOpenHand; -extern const QString cursorArrowCloseHand; - enum class Source : char { FromGui, FromFile, FromTool }; enum class Contour : char { OpenContour, CloseContour }; diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 7e5ec1a34..c763fa9dd 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -65,7 +65,7 @@ VToolSinglePoint::VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, VToolSinglePoint::~VToolSinglePoint() { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } //--------------------------------------------------------------------------------------------------------------------- @@ -207,7 +207,7 @@ void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) if (flags() & QGraphicsItem::ItemIsMovable) { - VApplication::setOverrideCursor(cursorArrowOpenHand, 1, 1); + SetOverrideCursor(cursorArrowOpenHand, 1, 1); } } @@ -219,7 +219,7 @@ void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) if (flags() & QGraphicsItem::ItemIsMovable) { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } } @@ -230,7 +230,7 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - VApplication::setOverrideCursor(cursorArrowCloseHand, 1, 1); + SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } VToolPoint::mousePressEvent(event); @@ -244,7 +244,7 @@ void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand - VApplication::restoreOverrideCursor(cursorArrowCloseHand); + RestoreOverrideCursor(cursorArrowCloseHand); } } VToolPoint::mouseReleaseEvent(event); diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 26aa02006..0985f93c1 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -94,7 +94,7 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const QStr VToolSpline::~VToolSpline() { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } //--------------------------------------------------------------------------------------------------------------------- @@ -345,7 +345,7 @@ void VToolSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - VApplication::setOverrideCursor(cursorArrowCloseHand, 1, 1); + SetOverrideCursor(cursorArrowCloseHand, 1, 1); oldPosition = event->scenePos(); event->accept(); } @@ -361,7 +361,7 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand - VApplication::restoreOverrideCursor(cursorArrowCloseHand); + RestoreOverrideCursor(cursorArrowCloseHand); } } VAbstractSpline::mouseReleaseEvent(event); @@ -425,7 +425,7 @@ void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if (flags() & QGraphicsItem::ItemIsMovable) { - VApplication::setOverrideCursor(cursorArrowOpenHand, 1, 1); + SetOverrideCursor(cursorArrowOpenHand, 1, 1); } VAbstractSpline::hoverEnterEvent(event); @@ -437,7 +437,7 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) if (flags() & QGraphicsItem::ItemIsMovable) { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } VAbstractSpline::hoverLeaveEvent(event); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 68b6eb81f..6d0498938 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -95,7 +95,7 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co VToolSplinePath::~VToolSplinePath() { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } //--------------------------------------------------------------------------------------------------------------------- @@ -412,7 +412,7 @@ void VToolSplinePath::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - VApplication::setOverrideCursor(cursorArrowCloseHand, 1, 1); + SetOverrideCursor(cursorArrowCloseHand, 1, 1); oldPosition = event->scenePos(); event->accept(); } @@ -428,7 +428,7 @@ void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand - VApplication::restoreOverrideCursor(cursorArrowCloseHand); + RestoreOverrideCursor(cursorArrowCloseHand); } } VAbstractSpline::mouseReleaseEvent(event); @@ -502,7 +502,7 @@ void VToolSplinePath::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if (flags() & QGraphicsItem::ItemIsMovable) { - VApplication::setOverrideCursor(cursorArrowOpenHand, 1, 1); + SetOverrideCursor(cursorArrowOpenHand, 1, 1); } VAbstractSpline::hoverEnterEvent(event); @@ -514,7 +514,7 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) if (flags() & QGraphicsItem::ItemIsMovable) { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } VAbstractSpline::hoverLeaveEvent(event); diff --git a/src/app/visualization/vcontrolpointspline.cpp b/src/app/visualization/vcontrolpointspline.cpp index 469f9328d..49f504573 100644 --- a/src/app/visualization/vcontrolpointspline.cpp +++ b/src/app/visualization/vcontrolpointspline.cpp @@ -27,12 +27,10 @@ *************************************************************************/ #include "vcontrolpointspline.h" -#include "../tools/vabstracttool.h" #include #include #include -#include "../core/vapplication.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -54,7 +52,7 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); - this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(patternUnit)))); + this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -66,7 +64,7 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP QPointF p1, p2; VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); controlLine = new QGraphicsLineItem(QLineF(splinePoint-controlPoint, p1), this); - controlLine->setPen(QPen(Qt::red, qApp->toPixel(WidthHairLine(patternUnit)))); + controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit))); controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -74,7 +72,7 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP VControlPointSpline::~VControlPointSpline() { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } //--------------------------------------------------------------------------------------------------------------------- @@ -97,17 +95,17 @@ void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsIte */ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - this->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(patternUnit)))); - VApplication::setOverrideCursor(cursorArrowOpenHand, 1, 1); + this->setPen(QPen(Qt::black, ToPixel(WidthMainLine(patternUnit), patternUnit))); + SetOverrideCursor(cursorArrowOpenHand, 1, 1); QGraphicsEllipseItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(patternUnit)))); + this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); QGraphicsEllipseItem::hoverLeaveEvent(event); } @@ -134,7 +132,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - VApplication::setOverrideCursor(cursorArrowCloseHand, 1, 1); + SetOverrideCursor(cursorArrowCloseHand, 1, 1); } QGraphicsEllipseItem::mousePressEvent(event); } @@ -145,7 +143,7 @@ void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand - VApplication::restoreOverrideCursor(cursorArrowCloseHand); + RestoreOverrideCursor(cursorArrowCloseHand); } QGraphicsEllipseItem::mouseReleaseEvent(event); } @@ -184,14 +182,14 @@ void VControlPointSpline::setEnabledPoint(bool enable) { if (enable == true) { - this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(patternUnit)))); + this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setAcceptHoverEvents(true); } else { - this->setPen(QPen(Qt::gray, qApp->toPixel(WidthHairLine(patternUnit)))); + this->setPen(QPen(Qt::gray, ToPixel(WidthHairLine(patternUnit), patternUnit))); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setFlag(QGraphicsItem::ItemIsMovable, false); this->setAcceptHoverEvents(false); diff --git a/src/app/visualization/vcontrolpointspline.h b/src/app/visualization/vcontrolpointspline.h index f4416a6c2..9b3f8ac17 100644 --- a/src/app/visualization/vcontrolpointspline.h +++ b/src/app/visualization/vcontrolpointspline.h @@ -32,7 +32,7 @@ #include #include #include "../libs/vgeometry/vsplinepath.h" -#include "../options.h" +#include "../libs/vmisc/def.h" /** * @brief The VControlPointSpline class control spline point. diff --git a/src/app/visualization/vgraphicssimpletextitem.cpp b/src/app/visualization/vgraphicssimpletextitem.cpp index a34a0610a..f201d79d4 100644 --- a/src/app/visualization/vgraphicssimpletextitem.cpp +++ b/src/app/visualization/vgraphicssimpletextitem.cpp @@ -74,7 +74,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphic VGraphicsSimpleTextItem::~VGraphicsSimpleTextItem() { //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } //--------------------------------------------------------------------------------------------------------------------- @@ -133,7 +133,7 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { this->setBrush(Qt::green); - VApplication::setOverrideCursor(cursorArrowOpenHand, 1, 1); + SetOverrideCursor(cursorArrowOpenHand, 1, 1); } QGraphicsSimpleTextItem::hoverEnterEvent(event); } @@ -151,7 +151,7 @@ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) this->setBrush(Qt::black); //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(cursorArrowOpenHand); + RestoreOverrideCursor(cursorArrowOpenHand); } QGraphicsSimpleTextItem::hoverLeaveEvent(event); } @@ -173,7 +173,7 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { - VApplication::setOverrideCursor(cursorArrowCloseHand, 1, 1); + SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } QGraphicsSimpleTextItem::mousePressEvent(event); @@ -187,7 +187,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand - VApplication::restoreOverrideCursor(cursorArrowCloseHand); + RestoreOverrideCursor(cursorArrowCloseHand); } } else diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index ac7f45c7f..ed9826849 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -28,6 +28,8 @@ #include "def.h" +#include + // Keep synchronize all names with initialization in VApllication class!!!!! //measurements //head and neck @@ -216,3 +218,48 @@ const QStringList builInFunctions = QStringList() << sin_F << cos_F << tan_F const QString cm_Oprt = QStringLiteral("cm"); const QString mm_Oprt = QStringLiteral("mm"); const QString in_Oprt = QStringLiteral("in"); + +const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); +const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); + +//--------------------------------------------------------------------------------------------------------------------- +void SetOverrideCursor(const QString &pixmapPath, int hotX, int hotY) +{ +#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 ) + { + QApplication::setOverrideCursor(QCursor(newPixmap, hotX, hotY)); + } +#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 ) + { + QApplication::restoreOverrideCursor(); + } +#endif +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 19d66def4..0bab8864f 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -368,4 +368,10 @@ extern const QString cm_Oprt; extern const QString mm_Oprt; extern const QString in_Oprt; +extern const QString cursorArrowOpenHand; +extern const QString cursorArrowCloseHand; + +void SetOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); +void RestoreOverrideCursor(const QString & pixmapPath); + #endif // DEF_H diff --git a/src/libs/vmisc/vmisc.pro b/src/libs/vmisc/vmisc.pro index b3f21da35..6a51731ce 100644 --- a/src/libs/vmisc/vmisc.pro +++ b/src/libs/vmisc/vmisc.pro @@ -7,6 +7,8 @@ # File with common stuff for whole project include(../../../Valentina.pri) +QT += widgets + # Name of library TARGET = vmisc