Set (restore) cursor only if not active (active).

--HG--
branch : develop
This commit is contained in:
dismine 2014-09-08 14:02:14 +03:00
parent cfeaf2ffa0
commit fc92e0b4a4
5 changed files with 60 additions and 43 deletions

View file

@ -202,10 +202,7 @@ void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
VToolPoint::hoverEnterEvent(event); VToolPoint::hoverEnterEvent(event);
#ifndef QT_NO_CURSOR VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-openhand.png"));
QApplication::setOverrideCursor(QCursor(pixmap, 1, 1));
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -214,9 +211,7 @@ void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
VToolPoint::hoverLeaveEvent(event); VToolPoint::hoverLeaveEvent(event);
//Disable cursor-arrow-openhand //Disable cursor-arrow-openhand
#ifndef QT_NO_CURSOR VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
QApplication::restoreOverrideCursor();
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -224,10 +219,7 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
#ifndef QT_NO_CURSOR VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png"));
QApplication::setOverrideCursor(QCursor(pixmap, 1, 1));
#endif
} }
VToolPoint::mousePressEvent(event); VToolPoint::mousePressEvent(event);
} }
@ -238,9 +230,7 @@ void VToolSinglePoint::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 //Disable cursor-arrow-closehand
#ifndef QT_NO_CURSOR VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
QApplication::restoreOverrideCursor();
#endif
} }
VToolPoint::mouseReleaseEvent(event); VToolPoint::mouseReleaseEvent(event);
} }

View file

@ -88,10 +88,7 @@ void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsIte
void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
#ifndef QT_NO_CURSOR VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-openhand.png"));
QApplication::setOverrideCursor(QCursor(pixmap, 1, 1));
#endif
QGraphicsEllipseItem::hoverEnterEvent(event); QGraphicsEllipseItem::hoverEnterEvent(event);
} }
@ -100,9 +97,7 @@ void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())));
//Disable cursor-arrow-openhand //Disable cursor-arrow-openhand
#ifndef QT_NO_CURSOR VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
QApplication::restoreOverrideCursor();
#endif
QGraphicsEllipseItem::hoverLeaveEvent(event); QGraphicsEllipseItem::hoverLeaveEvent(event);
} }
@ -129,10 +124,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
#ifndef QT_NO_CURSOR VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png"));
QApplication::setOverrideCursor(QCursor(pixmap, 1, 1));
#endif
} }
QGraphicsEllipseItem::mousePressEvent(event); QGraphicsEllipseItem::mousePressEvent(event);
} }
@ -143,9 +135,7 @@ void VControlPointSpline::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 //Disable cursor-arrow-closehand
#ifndef QT_NO_CURSOR VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
QApplication::restoreOverrideCursor();
#endif
} }
QGraphicsEllipseItem::mouseReleaseEvent(event); QGraphicsEllipseItem::mouseReleaseEvent(event);
} }

View file

@ -33,6 +33,8 @@
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include "../widgets/vapplication.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VGraphicsSimpleTextItem default constructor. * @brief VGraphicsSimpleTextItem default constructor.
@ -105,10 +107,7 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
this->setBrush(Qt::green); this->setBrush(Qt::green);
#ifndef QT_NO_CURSOR VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-openhand.png"));
QApplication::setOverrideCursor(QCursor(pixmap, 1, 1));
#endif
QGraphicsSimpleTextItem::hoverEnterEvent(event); QGraphicsSimpleTextItem::hoverEnterEvent(event);
} }
@ -123,9 +122,7 @@ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
this->setBrush(Qt::black); this->setBrush(Qt::black);
//Disable cursor-arrow-openhand //Disable cursor-arrow-openhand
#ifndef QT_NO_CURSOR VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
QApplication::restoreOverrideCursor();
#endif
QGraphicsSimpleTextItem::hoverLeaveEvent(event); QGraphicsSimpleTextItem::hoverLeaveEvent(event);
} }
@ -144,10 +141,7 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
#ifndef QT_NO_CURSOR VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png"));
QApplication::setOverrideCursor(QCursor(pixmap, 1, 1));
#endif
} }
QGraphicsSimpleTextItem::mousePressEvent(event); QGraphicsSimpleTextItem::mousePressEvent(event);
} }
@ -158,9 +152,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 //Disable cursor-arrow-closehand
#ifndef QT_NO_CURSOR VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
QApplication::restoreOverrideCursor();
#endif
} }
QGraphicsSimpleTextItem::mouseReleaseEvent(event); QGraphicsSimpleTextItem::mouseReleaseEvent(event);
} }

View file

@ -2029,3 +2029,45 @@ void VApplication::setCurrentScene(VMainGraphicsScene *value)
{ {
currentScene = 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, 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::restoreOverrideCursor();
}
#endif
}

View file

@ -95,6 +95,9 @@ public:
void setCurrentDocument(VPattern *doc); void setCurrentDocument(VPattern *doc);
VPattern *getCurrentDocument()const; VPattern *getCurrentDocument()const;
static void setOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1);
static void restoreOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1);
private: private:
Q_DISABLE_COPY(VApplication) Q_DISABLE_COPY(VApplication)
Unit _patternUnit; Unit _patternUnit;