Refactoring. Grainline and label have common parent.
--HG-- branch : feature
This commit is contained in:
parent
6ee0c42d53
commit
84b285cbe4
|
@ -61,7 +61,8 @@ HEADERS += \
|
||||||
$$PWD/drawTools/toolcurve/vtoolellipticalarc.h \
|
$$PWD/drawTools/toolcurve/vtoolellipticalarc.h \
|
||||||
$$PWD/nodeDetails/vnodeellipticalarc.h \
|
$$PWD/nodeDetails/vnodeellipticalarc.h \
|
||||||
$$PWD/vtoolseamallowance.h \
|
$$PWD/vtoolseamallowance.h \
|
||||||
$$PWD/nodeDetails/vtoolpiecepath.h
|
$$PWD/nodeDetails/vtoolpiecepath.h \
|
||||||
|
$$PWD/vpieceitem.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/vtooldetail.cpp \
|
$$PWD/vtooldetail.cpp \
|
||||||
|
@ -120,4 +121,5 @@ SOURCES += \
|
||||||
$$PWD/drawTools/toolcurve/vtoolellipticalarc.cpp \
|
$$PWD/drawTools/toolcurve/vtoolellipticalarc.cpp \
|
||||||
$$PWD/nodeDetails/vnodeellipticalarc.cpp \
|
$$PWD/nodeDetails/vnodeellipticalarc.cpp \
|
||||||
$$PWD/vtoolseamallowance.cpp \
|
$$PWD/vtoolseamallowance.cpp \
|
||||||
$$PWD/nodeDetails/vtoolpiecepath.cpp
|
$$PWD/nodeDetails/vtoolpiecepath.cpp \
|
||||||
|
$$PWD/vpieceitem.cpp
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QGraphicsScene>
|
|
||||||
|
|
||||||
#include "../vmisc/def.h"
|
#include "../vmisc/def.h"
|
||||||
#include "../vmisc/vmath.h"
|
#include "../vmisc/vmath.h"
|
||||||
|
@ -45,7 +44,6 @@
|
||||||
#define RESIZE_RECT_SIZE 10
|
#define RESIZE_RECT_SIZE 10
|
||||||
#define ROTATE_CIRC_R 7
|
#define ROTATE_CIRC_R 7
|
||||||
#define ACTIVE_Z 10
|
#define ACTIVE_Z 10
|
||||||
#define INACTIVE_Z 5
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -53,13 +51,10 @@
|
||||||
* @param pParent pointer to the parent item
|
* @param pParent pointer to the parent item
|
||||||
*/
|
*/
|
||||||
VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent)
|
VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent)
|
||||||
: QGraphicsObject(pParent),
|
: VPieceItem(pParent),
|
||||||
m_eMode(VGrainlineItem::mNormal),
|
|
||||||
m_bReleased(false),
|
|
||||||
m_dRotation(0),
|
m_dRotation(0),
|
||||||
m_dStartRotation(0),
|
m_dStartRotation(0),
|
||||||
m_dLength(0),
|
m_dLength(0),
|
||||||
m_rectBoundingBox(),
|
|
||||||
m_polyBound(),
|
m_polyBound(),
|
||||||
m_ptStartPos(),
|
m_ptStartPos(),
|
||||||
m_ptStartMove(),
|
m_ptStartMove(),
|
||||||
|
@ -69,12 +64,10 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent)
|
||||||
m_ptStart(),
|
m_ptStart(),
|
||||||
m_ptFinish(),
|
m_ptFinish(),
|
||||||
m_ptCenter(),
|
m_ptCenter(),
|
||||||
m_ptRotCenter(),
|
|
||||||
m_dAngle(0),
|
m_dAngle(0),
|
||||||
m_eArrowType(VGrainlineGeometry::atBoth)
|
m_eArrowType(VGrainlineGeometry::atBoth)
|
||||||
{
|
{
|
||||||
m_rectBoundingBox.setTopLeft(QPointF(0, 0));
|
m_inactiveZ = 5;
|
||||||
setAcceptHoverEvents(true);
|
|
||||||
Reset();
|
Reset();
|
||||||
UpdateRectangle();
|
UpdateRectangle();
|
||||||
}
|
}
|
||||||
|
@ -212,43 +205,7 @@ void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal
|
||||||
m_eArrowType = eAT;
|
m_eArrowType = eAT;
|
||||||
|
|
||||||
UpdateRectangle();
|
UpdateRectangle();
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VGrainlineItem::boundingRect returns the bounding rect around the grainline
|
|
||||||
* @return bounding rect
|
|
||||||
*/
|
|
||||||
QRectF VGrainlineItem::boundingRect() const
|
|
||||||
{
|
|
||||||
return m_rectBoundingBox;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VGrainlineItem::Reset resets the item parameters.
|
|
||||||
*/
|
|
||||||
void VGrainlineItem::Reset()
|
|
||||||
{
|
|
||||||
if (QGraphicsScene *toolScene = scene())
|
|
||||||
{
|
|
||||||
toolScene->clearSelection();
|
|
||||||
}
|
|
||||||
m_bReleased = false;
|
|
||||||
m_eMode = mNormal;
|
|
||||||
setZValue(INACTIVE_Z);
|
|
||||||
UpdateBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VGrainlineItem::IsIdle returns the idle flag.
|
|
||||||
* @return true, if item mode is normal and false otherwise.
|
|
||||||
*/
|
|
||||||
bool VGrainlineItem::IsIdle() const
|
|
||||||
{
|
|
||||||
return m_eMode == mNormal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -323,7 +280,7 @@ void VGrainlineItem::SetScale(qreal dScale)
|
||||||
{
|
{
|
||||||
m_dScale = dScale;
|
m_dScale = dScale;
|
||||||
UpdateRectangle();
|
UpdateRectangle();
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -360,7 +317,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
||||||
}
|
}
|
||||||
setZValue(ACTIVE_Z);
|
setZValue(ACTIVE_Z);
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +340,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
pt.setY(pt.y() + dY);
|
pt.setY(pt.y() + dY);
|
||||||
}
|
}
|
||||||
setPos(pt);
|
setPos(pt);
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
else if (m_eMode == mResize)
|
else if (m_eMode == mResize)
|
||||||
{
|
{
|
||||||
|
@ -400,7 +357,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
m_dLength = dPrevLen;
|
m_dLength = dPrevLen;
|
||||||
}
|
}
|
||||||
UpdateRectangle();
|
UpdateRectangle();
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
else if (m_eMode == mRotate)
|
else if (m_eMode == mRotate)
|
||||||
{
|
{
|
||||||
|
@ -424,7 +381,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
setPos(ptNewPos);
|
setPos(ptNewPos);
|
||||||
m_dRotation = m_dStartRotation + dAng;
|
m_dRotation = m_dStartRotation + dAng;
|
||||||
UpdateRectangle();
|
UpdateRectangle();
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,7 +416,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
if (m_bReleased == true)
|
if (m_bReleased == true)
|
||||||
{
|
{
|
||||||
m_eMode = mRotate;
|
m_eMode = mRotate;
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -472,7 +429,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
{
|
{
|
||||||
emit SignalResized(m_dLength);
|
emit SignalResized(m_dLength);
|
||||||
}
|
}
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -485,7 +442,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
{
|
{
|
||||||
emit SignalRotated(m_dRotation, m_ptStart);
|
emit SignalRotated(m_dRotation, m_ptStart);
|
||||||
}
|
}
|
||||||
UpdateBox();
|
Update();
|
||||||
}
|
}
|
||||||
m_bReleased = true;
|
m_bReleased = true;
|
||||||
}
|
}
|
||||||
|
@ -495,7 +452,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
/**
|
/**
|
||||||
* @brief VGrainlineItem::UpdateBox updates the item
|
* @brief VGrainlineItem::UpdateBox updates the item
|
||||||
*/
|
*/
|
||||||
void VGrainlineItem::UpdateBox()
|
void VGrainlineItem::Update()
|
||||||
{
|
{
|
||||||
update(m_rectBoundingBox);
|
update(m_rectBoundingBox);
|
||||||
}
|
}
|
||||||
|
@ -554,28 +511,6 @@ void VGrainlineItem::UpdateRectangle()
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VGrainlineItem::GetAngle calculates the angle between the line, which goes from
|
|
||||||
* rotation center to pt and x axis
|
|
||||||
* @param pt point of interest
|
|
||||||
* @return the angle between line from rotation center and point of interest and x axis
|
|
||||||
*/
|
|
||||||
qreal VGrainlineItem::GetAngle(const QPointF& pt) const
|
|
||||||
{
|
|
||||||
double dX = pt.x() - m_ptRotCenter.x();
|
|
||||||
double dY = pt.y() - m_ptRotCenter.y();
|
|
||||||
|
|
||||||
if (fabs(dX) < 1 && fabs(dY) < 1)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return qAtan2(-dY, dX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VGrainlineItem::Rotate rotates point pt around ptCenter by angle dAng [rad]
|
* @brief VGrainlineItem::Rotate rotates point pt around ptCenter by angle dAng [rad]
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
#ifndef VGRAINLINEITEM_H
|
#ifndef VGRAINLINEITEM_H
|
||||||
#define VGRAINLINEITEM_H
|
#define VGRAINLINEITEM_H
|
||||||
|
|
||||||
#include <QGraphicsObject>
|
#include "vpieceitem.h"
|
||||||
|
|
||||||
#include "../vpatterndb/vgrainlinegeometry.h"
|
#include "../vpatterndb/vgrainlinegeometry.h"
|
||||||
|
|
||||||
class QGraphicsObject;
|
class QGraphicsObject;
|
||||||
|
@ -38,66 +37,50 @@ class QPainter;
|
||||||
class QStyleOptionGraphicsItem;
|
class QStyleOptionGraphicsItem;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
class VGrainlineItem : public QGraphicsObject
|
class VGrainlineItem : public VPieceItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
enum Mode {
|
|
||||||
mNormal,
|
|
||||||
mMove,
|
|
||||||
mResize,
|
|
||||||
mRotate
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VGrainlineItem(QGraphicsItem* pParent = nullptr);
|
explicit VGrainlineItem(QGraphicsItem* pParent = nullptr);
|
||||||
virtual ~VGrainlineItem();
|
virtual ~VGrainlineItem();
|
||||||
|
|
||||||
void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget);
|
virtual void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) Q_DECL_OVERRIDE;
|
||||||
void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength,
|
void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength,
|
||||||
VGrainlineGeometry::ArrowType eAT);
|
VGrainlineGeometry::ArrowType eAT);
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const;
|
||||||
void Reset();
|
void SetScale(qreal dScale);
|
||||||
bool IsIdle() const;
|
|
||||||
bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const;
|
|
||||||
void SetScale(qreal dScale);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
|
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent* pME);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME);
|
|
||||||
void UpdateBox();
|
|
||||||
void UpdateRectangle();
|
|
||||||
|
|
||||||
qreal GetAngle(const QPointF& pt) const;
|
|
||||||
QPointF Rotate(const QPointF& pt, const QPointF& ptCenter, qreal dAng) const;
|
|
||||||
QPointF GetInsideCorner(int i, qreal dDist) const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SignalMoved(const QPointF& ptPos);
|
void SignalResized(qreal dLength);
|
||||||
void SignalResized(qreal dLength);
|
void SignalRotated(qreal dRot, const QPointF& ptNewPos);
|
||||||
void SignalRotated(qreal dRot, const QPointF& ptNewPos);
|
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
||||||
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
||||||
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
||||||
|
virtual void Update() Q_DECL_OVERRIDE;
|
||||||
|
void UpdateRectangle();
|
||||||
|
|
||||||
|
QPointF Rotate(const QPointF& pt, const QPointF& ptCenter, qreal dAng) const;
|
||||||
|
QPointF GetInsideCorner(int i, qreal dDist) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mode m_eMode;
|
Q_DISABLE_COPY(VGrainlineItem)
|
||||||
bool m_bReleased;
|
qreal m_dRotation;
|
||||||
qreal m_dRotation;
|
qreal m_dStartRotation;
|
||||||
qreal m_dStartRotation;
|
qreal m_dLength;
|
||||||
qreal m_dLength;
|
QPolygonF m_polyBound;
|
||||||
QRectF m_rectBoundingBox;
|
QPointF m_ptStartPos;
|
||||||
QPolygonF m_polyBound;
|
QPointF m_ptStartMove;
|
||||||
QPointF m_ptStartPos;
|
qreal m_dScale;
|
||||||
QPointF m_ptStartMove;
|
QPolygonF m_polyResize;
|
||||||
qreal m_dScale;
|
qreal m_dStartLength;
|
||||||
QPolygonF m_polyResize;
|
QPointF m_ptStart;
|
||||||
qreal m_dStartLength;
|
QPointF m_ptFinish;
|
||||||
QPointF m_ptStart;
|
QPointF m_ptCenter;
|
||||||
QPointF m_ptFinish;
|
qreal m_dAngle;
|
||||||
QPointF m_ptCenter;
|
VGrainlineGeometry::ArrowType m_eArrowType;
|
||||||
QPointF m_ptRotCenter;
|
|
||||||
qreal m_dAngle;
|
|
||||||
VGrainlineGeometry::ArrowType m_eArrowType;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VGRAINLINEITEM_H
|
#endif // VGRAINLINEITEM_H
|
||||||
|
|
108
src/libs/vtools/tools/vpieceitem.cpp
Normal file
108
src/libs/vtools/tools/vpieceitem.cpp
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 18 1, 2017
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentine project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2017 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#include "vpieceitem.h"
|
||||||
|
#include "../vmisc/vmath.h"
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPieceItem::VPieceItem(QGraphicsItem *pParent)
|
||||||
|
: QGraphicsObject(pParent),
|
||||||
|
m_rectBoundingBox(),
|
||||||
|
m_eMode(VPieceItem::mNormal),
|
||||||
|
m_bReleased(false),
|
||||||
|
m_ptRotCenter(),
|
||||||
|
m_inactiveZ(1)
|
||||||
|
{
|
||||||
|
m_rectBoundingBox.setTopLeft(QPointF(0, 0));
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPieceItem::~VPieceItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief boundingRect returns the item bounding box
|
||||||
|
* @return item bounding box
|
||||||
|
*/
|
||||||
|
QRectF VPieceItem::boundingRect() const
|
||||||
|
{
|
||||||
|
return m_rectBoundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Reset resets the item, putting the mode and z coordinate to normal and redraws it
|
||||||
|
*/
|
||||||
|
void VPieceItem::Reset()
|
||||||
|
{
|
||||||
|
if (QGraphicsScene *toolScene = scene())
|
||||||
|
{
|
||||||
|
toolScene->clearSelection();
|
||||||
|
}
|
||||||
|
m_eMode = mNormal;
|
||||||
|
m_bReleased = false;
|
||||||
|
Update();
|
||||||
|
setZValue(m_inactiveZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief IsIdle returns the idle flag.
|
||||||
|
* @return true, if item mode is normal and false otherwise.
|
||||||
|
*/
|
||||||
|
bool VPieceItem::IsIdle() const
|
||||||
|
{
|
||||||
|
return m_eMode == mNormal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis
|
||||||
|
* @param pt point of interest
|
||||||
|
* @return the angle between line from rotation center and point of interest and x axis
|
||||||
|
*/
|
||||||
|
double VPieceItem::GetAngle(const QPointF &pt) const
|
||||||
|
{
|
||||||
|
const double dX = pt.x() - m_ptRotCenter.x();
|
||||||
|
const double dY = pt.y() - m_ptRotCenter.y();
|
||||||
|
|
||||||
|
if (fabs(dX) < 1 && fabs(dY) < 1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return qAtan2(dY, dX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
73
src/libs/vtools/tools/vpieceitem.h
Normal file
73
src/libs/vtools/tools/vpieceitem.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 18 1, 2017
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentine project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2017 Valentina project
|
||||||
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VPIECEITEM_H
|
||||||
|
#define VPIECEITEM_H
|
||||||
|
|
||||||
|
#include <QtCore/qglobal.h>
|
||||||
|
#include <QGraphicsObject>
|
||||||
|
|
||||||
|
class VPieceItem : public QGraphicsObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit VPieceItem(QGraphicsItem* pParent = nullptr);
|
||||||
|
virtual ~VPieceItem();
|
||||||
|
|
||||||
|
virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
virtual void Update() =0;
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
bool IsIdle() const;
|
||||||
|
|
||||||
|
double GetAngle(const QPointF &pt) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void SignalMoved(const QPointF &ptPos);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
enum Mode
|
||||||
|
{
|
||||||
|
mNormal,
|
||||||
|
mMove,
|
||||||
|
mResize,
|
||||||
|
mRotate
|
||||||
|
};
|
||||||
|
QRectF m_rectBoundingBox;
|
||||||
|
Mode m_eMode;
|
||||||
|
bool m_bReleased;
|
||||||
|
QPointF m_ptRotCenter;
|
||||||
|
|
||||||
|
qreal m_inactiveZ;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VPieceItem)
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VPIECEITEM_H
|
|
@ -37,7 +37,6 @@
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QGraphicsScene>
|
|
||||||
|
|
||||||
#include "../vmisc/def.h"
|
#include "../vmisc/def.h"
|
||||||
#include "../vmisc/vmath.h"
|
#include "../vmisc/vmath.h"
|
||||||
|
@ -56,32 +55,85 @@ const qreal rotateCircle = (2./*mm*/ / 25.4) * PrintDPI;
|
||||||
#define ROTATE_ARC 50
|
#define ROTATE_ARC 50
|
||||||
const qreal minW = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
|
const qreal minW = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
|
||||||
const qreal minH = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
|
const qreal minH = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
|
||||||
#define INACTIVE_Z 2
|
|
||||||
#define ACTIVE_Z 10
|
#define ACTIVE_Z 10
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetBoundingRect calculates the bounding box around rectBB rectangle, rotated around its center by dRot degrees
|
||||||
|
* @param rectBB rectangle of interest
|
||||||
|
* @param dRot rectangle rotation
|
||||||
|
* @return bounding box around rectBB rotated by dRot
|
||||||
|
*/
|
||||||
|
QRectF GetBoundingRect(QRectF rectBB, qreal dRot)
|
||||||
|
{
|
||||||
|
QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() };
|
||||||
|
QPointF ptCenter = rectBB.center();
|
||||||
|
|
||||||
|
qreal dX1 = 0;
|
||||||
|
qreal dX2 = 0;
|
||||||
|
qreal dY1 = 0;
|
||||||
|
qreal dY2 = 0;
|
||||||
|
|
||||||
|
double dAng = qDegreesToRadians(dRot);
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
QPointF pt = apt[i] - ptCenter;
|
||||||
|
qreal dX = pt.x()*cos(dAng) + pt.y()*sin(dAng);
|
||||||
|
qreal dY = -pt.x()*sin(dAng) + pt.y()*cos(dAng);
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
dX1 = dX2 = dX;
|
||||||
|
dY1 = dY2 = dY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (dX < dX1)
|
||||||
|
{
|
||||||
|
dX1 = dX;
|
||||||
|
}
|
||||||
|
else if (dX > dX2)
|
||||||
|
{
|
||||||
|
dX2 = dX;
|
||||||
|
}
|
||||||
|
if (dY < dY1)
|
||||||
|
{
|
||||||
|
dY1 = dY;
|
||||||
|
}
|
||||||
|
else if (dY > dY2)
|
||||||
|
{
|
||||||
|
dY2 = dY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QRectF rect;
|
||||||
|
rect.setTopLeft(ptCenter + QPointF(dX1, dY1));
|
||||||
|
rect.setWidth(dX2 - dX1);
|
||||||
|
rect.setHeight(dY2 - dY1);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
}//static functions
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VTextGraphicsItem::VTextGraphicsItem constructor
|
* @brief VTextGraphicsItem::VTextGraphicsItem constructor
|
||||||
* @param pParent pointer to the parent item
|
* @param pParent pointer to the parent item
|
||||||
*/
|
*/
|
||||||
VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent)
|
VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent)
|
||||||
: QGraphicsObject(pParent),
|
: VPieceItem(pParent),
|
||||||
m_eMode(VTextGraphicsItem::mNormal),
|
|
||||||
m_bReleased(false),
|
|
||||||
m_ptStartPos(),
|
m_ptStartPos(),
|
||||||
m_ptStart(),
|
m_ptStart(),
|
||||||
m_ptRotCenter(),
|
|
||||||
m_szStart(),
|
m_szStart(),
|
||||||
m_dRotation(0),
|
m_dRotation(0),
|
||||||
m_dAngle(0),
|
m_dAngle(0),
|
||||||
m_rectResize(),
|
m_rectResize(),
|
||||||
m_rectBoundingBox(),
|
|
||||||
m_tm()
|
m_tm()
|
||||||
{
|
{
|
||||||
m_rectBoundingBox.setTopLeft(QPointF(0, 0));
|
m_inactiveZ = 2;
|
||||||
SetSize(minW, minH);
|
SetSize(minW, minH);
|
||||||
setZValue(INACTIVE_Z);
|
setZValue(m_inactiveZ);
|
||||||
setAcceptHoverEvents(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -196,32 +248,6 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::Reset resets the item, putting the mode and z coordinate to normal and redraws it
|
|
||||||
*/
|
|
||||||
void VTextGraphicsItem::Reset()
|
|
||||||
{
|
|
||||||
if (QGraphicsScene *toolScene = scene())
|
|
||||||
{
|
|
||||||
toolScene->clearSelection();
|
|
||||||
}
|
|
||||||
m_eMode = mNormal;
|
|
||||||
m_bReleased = false;
|
|
||||||
Update();
|
|
||||||
setZValue(INACTIVE_Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::IsIdle checks if the item is in normal mode.
|
|
||||||
* @return true, if item is in normal mode and false otherwise.
|
|
||||||
*/
|
|
||||||
bool VTextGraphicsItem::IsIdle() const
|
|
||||||
{
|
|
||||||
return m_eMode == mNormal;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VTextGraphicsItem::AddLine adds a line of text to the label list.
|
* @brief VTextGraphicsItem::AddLine adds a line of text to the label list.
|
||||||
|
@ -374,16 +400,6 @@ int VTextGraphicsItem::GetFontSize() const
|
||||||
return m_tm.GetFont().pixelSize();
|
return m_tm.GetFont().pixelSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::boundingRect returns the label bounding box
|
|
||||||
* @return label bounding box
|
|
||||||
*/
|
|
||||||
QRectF VTextGraphicsItem::boundingRect() const
|
|
||||||
{
|
|
||||||
return m_rectBoundingBox;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VTextGraphicsItem::mousePressEvent handles left button mouse press events
|
* @brief VTextGraphicsItem::mousePressEvent handles left button mouse press events
|
||||||
|
@ -617,82 +633,3 @@ void VTextGraphicsItem::CorrectLabel()
|
||||||
m_tm.FitFontSize(m_rectBoundingBox.width(), m_rectBoundingBox.height());
|
m_tm.FitFontSize(m_rectBoundingBox.width(), m_rectBoundingBox.height());
|
||||||
UpdateBox();
|
UpdateBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::GetAngle calculates the angle between the line, which goes from
|
|
||||||
* rotation center to pt and x axis
|
|
||||||
* @param pt point of interest
|
|
||||||
* @return the angle between line from rotation center and point of interest and x axis
|
|
||||||
*/
|
|
||||||
double VTextGraphicsItem::GetAngle(QPointF pt) const
|
|
||||||
{
|
|
||||||
double dX = pt.x() - m_ptRotCenter.x();
|
|
||||||
double dY = pt.y() - m_ptRotCenter.y();
|
|
||||||
|
|
||||||
if (fabs(dX) < 1 && fabs(dY) < 1)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return qAtan2(dY, dX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::GetBoundingRect calculates the bounding box
|
|
||||||
* around rectBB rectangle, rotated around its center by dRot degrees
|
|
||||||
* @param rectBB rectangle of interest
|
|
||||||
* @param dRot rectangle rotation
|
|
||||||
* @return bounding box around rectBB rotated by dRot
|
|
||||||
*/
|
|
||||||
QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const
|
|
||||||
{
|
|
||||||
QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() };
|
|
||||||
QPointF ptCenter = rectBB.center();
|
|
||||||
|
|
||||||
qreal dX1 = 0;
|
|
||||||
qreal dX2 = 0;
|
|
||||||
qreal dY1 = 0;
|
|
||||||
qreal dY2 = 0;
|
|
||||||
|
|
||||||
double dAng = qDegreesToRadians(dRot);
|
|
||||||
for (int i = 0; i < 4; ++i)
|
|
||||||
{
|
|
||||||
QPointF pt = apt[i] - ptCenter;
|
|
||||||
qreal dX = pt.x()*cos(dAng) + pt.y()*sin(dAng);
|
|
||||||
qreal dY = -pt.x()*sin(dAng) + pt.y()*cos(dAng);
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
dX1 = dX2 = dX;
|
|
||||||
dY1 = dY2 = dY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (dX < dX1)
|
|
||||||
{
|
|
||||||
dX1 = dX;
|
|
||||||
}
|
|
||||||
else if (dX > dX2)
|
|
||||||
{
|
|
||||||
dX2 = dX;
|
|
||||||
}
|
|
||||||
if (dY < dY1)
|
|
||||||
{
|
|
||||||
dY1 = dY;
|
|
||||||
}
|
|
||||||
else if (dY > dY2)
|
|
||||||
{
|
|
||||||
dY2 = dY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QRectF rect;
|
|
||||||
rect.setTopLeft(ptCenter + QPointF(dX1, dY1));
|
|
||||||
rect.setWidth(dX2 - dX1);
|
|
||||||
rect.setHeight(dY2 - dY1);
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include "vpieceitem.h"
|
||||||
#include "../vlayout/vtextmanager.h"
|
#include "../vlayout/vtextmanager.h"
|
||||||
|
|
||||||
class QFont;
|
class QFont;
|
||||||
|
@ -59,70 +60,50 @@ class VPatternPieceData;
|
||||||
* which can be dragged around, resized and rotated within the parent item. The text font
|
* which can be dragged around, resized and rotated within the parent item. The text font
|
||||||
* size will be automatically updated, so that the entire text will fit into the item.
|
* size will be automatically updated, so that the entire text will fit into the item.
|
||||||
*/
|
*/
|
||||||
class VTextGraphicsItem : public QGraphicsObject
|
class VTextGraphicsItem : public VPieceItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
enum Mode {
|
|
||||||
mNormal,
|
|
||||||
mMove,
|
|
||||||
mResize,
|
|
||||||
mRotate
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr);
|
explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr);
|
||||||
virtual ~VTextGraphicsItem();
|
virtual ~VTextGraphicsItem();
|
||||||
|
|
||||||
void SetFont(const QFont& fnt);
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
virtual void Update() Q_DECL_OVERRIDE;
|
||||||
QWidget *widget) Q_DECL_OVERRIDE;
|
|
||||||
|
|
||||||
void Reset();
|
void SetFont(const QFont& fnt);
|
||||||
bool IsIdle() const;
|
int GetFontSize() const;
|
||||||
|
void AddLine(const TextLine& tl);
|
||||||
int GetFontSize() const;
|
void Clear();
|
||||||
virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
|
void SetSize(qreal fW, qreal fH);
|
||||||
void AddLine(const TextLine& tl);
|
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
|
||||||
void Clear();
|
void UpdateData(const QString& qsName, const VPatternPieceData& data);
|
||||||
void SetSize(qreal fW, qreal fH);
|
void UpdateData(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight);
|
||||||
void Update();
|
int GetTextLines() const;
|
||||||
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
|
|
||||||
void UpdateData(const QString& qsName, const VPatternPieceData& data);
|
|
||||||
void UpdateData(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight);
|
|
||||||
int GetTextLines() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
|
||||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
|
||||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
|
||||||
void UpdateBox();
|
|
||||||
void CorrectLabel();
|
|
||||||
|
|
||||||
double GetAngle(QPointF pt) const;
|
void UpdateBox();
|
||||||
|
void CorrectLabel();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SignalMoved(const QPointF& ptPos);
|
void SignalResized(qreal iTW, int iFontSize);
|
||||||
void SignalResized(qreal iTW, int iFontSize);
|
void SignalRotated(qreal dAng);
|
||||||
void SignalRotated(qreal dAng);
|
void SignalShrink();
|
||||||
void SignalShrink();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mode m_eMode;
|
Q_DISABLE_COPY(VTextGraphicsItem)
|
||||||
bool m_bReleased;
|
QPointF m_ptStartPos;
|
||||||
QPointF m_ptStartPos;
|
QPointF m_ptStart;
|
||||||
QPointF m_ptStart;
|
QSizeF m_szStart;
|
||||||
QPointF m_ptRotCenter;
|
double m_dRotation;
|
||||||
QSizeF m_szStart;
|
double m_dAngle;
|
||||||
double m_dRotation;
|
QRectF m_rectResize;
|
||||||
double m_dAngle;
|
VTextManager m_tm;
|
||||||
QRectF m_rectResize;
|
|
||||||
QRectF m_rectBoundingBox;
|
|
||||||
VTextManager m_tm;
|
|
||||||
|
|
||||||
QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VTEXTGRAPHICSITEM_H
|
#endif // VTEXTGRAPHICSITEM_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user