Class VControlPointSpline more independent.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-06-15 16:47:44 +03:00
parent 78dbb63c1b
commit fe704484c5
13 changed files with 87 additions and 85 deletions

View file

@ -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()
{

View file

@ -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();

View file

@ -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");

View file

@ -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 };

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -27,12 +27,10 @@
*************************************************************************/
#include "vcontrolpointspline.h"
#include "../tools/vabstracttool.h"
#include <QGraphicsSceneMouseEvent>
#include <QPen>
#include <QStyleOptionGraphicsItem>
#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);

View file

@ -32,7 +32,7 @@
#include <QGraphicsEllipseItem>
#include <QObject>
#include "../libs/vgeometry/vsplinepath.h"
#include "../options.h"
#include "../libs/vmisc/def.h"
/**
* @brief The VControlPointSpline class control spline point.

View file

@ -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

View file

@ -28,6 +28,8 @@
#include "def.h"
#include <QApplication>
// 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
}

View file

@ -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

View file

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