diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 6a43ce9da..ee9c190a6 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -61,7 +61,8 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolellipticalarc.h \ $$PWD/nodeDetails/vnodeellipticalarc.h \ $$PWD/vtoolseamallowance.h \ - $$PWD/nodeDetails/vtoolpiecepath.h + $$PWD/nodeDetails/vtoolpiecepath.h \ + $$PWD/vpieceitem.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -120,4 +121,5 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolellipticalarc.cpp \ $$PWD/nodeDetails/vnodeellipticalarc.cpp \ $$PWD/vtoolseamallowance.cpp \ - $$PWD/nodeDetails/vtoolpiecepath.cpp + $$PWD/nodeDetails/vtoolpiecepath.cpp \ + $$PWD/vpieceitem.cpp diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index dfe1c5ff9..954216651 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -45,7 +44,6 @@ #define RESIZE_RECT_SIZE 10 #define ROTATE_CIRC_R 7 #define ACTIVE_Z 10 -#define INACTIVE_Z 5 //--------------------------------------------------------------------------------------------------------------------- /** @@ -53,13 +51,10 @@ * @param pParent pointer to the parent item */ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) - : QGraphicsObject(pParent), - m_eMode(VGrainlineItem::mNormal), - m_bReleased(false), + : VPieceItem(pParent), m_dRotation(0), m_dStartRotation(0), m_dLength(0), - m_rectBoundingBox(), m_polyBound(), m_ptStartPos(), m_ptStartMove(), @@ -69,12 +64,10 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) m_ptStart(), m_ptFinish(), m_ptCenter(), - m_ptRotCenter(), m_dAngle(0), m_eArrowType(VGrainlineGeometry::atBoth) { - m_rectBoundingBox.setTopLeft(QPointF(0, 0)); - setAcceptHoverEvents(true); + m_inactiveZ = 5; Reset(); UpdateRectangle(); } @@ -212,43 +205,7 @@ void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal m_eArrowType = eAT; UpdateRectangle(); - UpdateBox(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @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; + Update(); } //--------------------------------------------------------------------------------------------------------------------- @@ -323,7 +280,7 @@ void VGrainlineItem::SetScale(qreal dScale) { m_dScale = dScale; UpdateRectangle(); - UpdateBox(); + Update(); } //--------------------------------------------------------------------------------------------------------------------- @@ -360,7 +317,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); - UpdateBox(); + Update(); } } @@ -383,7 +340,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) pt.setY(pt.y() + dY); } setPos(pt); - UpdateBox(); + Update(); } else if (m_eMode == mResize) { @@ -400,7 +357,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) m_dLength = dPrevLen; } UpdateRectangle(); - UpdateBox(); + Update(); } else if (m_eMode == mRotate) { @@ -424,7 +381,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) setPos(ptNewPos); m_dRotation = m_dStartRotation + dAng; UpdateRectangle(); - UpdateBox(); + Update(); } } } @@ -459,7 +416,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) if (m_bReleased == true) { m_eMode = mRotate; - UpdateBox(); + Update(); } } else @@ -472,7 +429,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { emit SignalResized(m_dLength); } - UpdateBox(); + Update(); } } else @@ -485,7 +442,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { emit SignalRotated(m_dRotation, m_ptStart); } - UpdateBox(); + Update(); } m_bReleased = true; } @@ -495,7 +452,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) /** * @brief VGrainlineItem::UpdateBox updates the item */ -void VGrainlineItem::UpdateBox() +void VGrainlineItem::Update() { update(m_rectBoundingBox); } @@ -554,28 +511,6 @@ void VGrainlineItem::UpdateRectangle() 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] diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h index 41ea59eb5..7f4217d54 100644 --- a/src/libs/vtools/tools/vgrainlineitem.h +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -29,8 +29,7 @@ #ifndef VGRAINLINEITEM_H #define VGRAINLINEITEM_H -#include - +#include "vpieceitem.h" #include "../vpatterndb/vgrainlinegeometry.h" class QGraphicsObject; @@ -38,66 +37,50 @@ class QPainter; class QStyleOptionGraphicsItem; class QWidget; -class VGrainlineItem : public QGraphicsObject +class VGrainlineItem : public VPieceItem { Q_OBJECT - - enum Mode { - mNormal, - mMove, - mResize, - mRotate - }; - public: explicit VGrainlineItem(QGraphicsItem* pParent = nullptr); virtual ~VGrainlineItem(); - void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget); - void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, - VGrainlineGeometry::ArrowType eAT); + virtual void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) Q_DECL_OVERRIDE; + void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, + VGrainlineGeometry::ArrowType eAT); - QRectF boundingRect() const; - void Reset(); - 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; + bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const; + void SetScale(qreal dScale); signals: - void SignalMoved(const QPointF& ptPos); - void SignalResized(qreal dLength); - void SignalRotated(qreal dRot, const QPointF& ptNewPos); + void SignalResized(qreal dLength); + 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: - Mode m_eMode; - bool m_bReleased; - qreal m_dRotation; - qreal m_dStartRotation; - qreal m_dLength; - QRectF m_rectBoundingBox; - QPolygonF m_polyBound; - QPointF m_ptStartPos; - QPointF m_ptStartMove; - qreal m_dScale; - QPolygonF m_polyResize; - qreal m_dStartLength; - QPointF m_ptStart; - QPointF m_ptFinish; - QPointF m_ptCenter; - QPointF m_ptRotCenter; - qreal m_dAngle; - VGrainlineGeometry::ArrowType m_eArrowType; + Q_DISABLE_COPY(VGrainlineItem) + qreal m_dRotation; + qreal m_dStartRotation; + qreal m_dLength; + QPolygonF m_polyBound; + QPointF m_ptStartPos; + QPointF m_ptStartMove; + qreal m_dScale; + QPolygonF m_polyResize; + qreal m_dStartLength; + QPointF m_ptStart; + QPointF m_ptFinish; + QPointF m_ptCenter; + qreal m_dAngle; + VGrainlineGeometry::ArrowType m_eArrowType; }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vtools/tools/vpieceitem.cpp b/src/libs/vtools/tools/vpieceitem.cpp new file mode 100644 index 000000000..f7f969fed --- /dev/null +++ b/src/libs/vtools/tools/vpieceitem.cpp @@ -0,0 +1,108 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "vpieceitem.h" +#include "../vmisc/vmath.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +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); + } +} + diff --git a/src/libs/vtools/tools/vpieceitem.h b/src/libs/vtools/tools/vpieceitem.h new file mode 100644 index 000000000..7b3306044 --- /dev/null +++ b/src/libs/vtools/tools/vpieceitem.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VPIECEITEM_H +#define VPIECEITEM_H + +#include +#include + +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 diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 63d1f834c..c423a04b8 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -56,32 +55,85 @@ const qreal rotateCircle = (2./*mm*/ / 25.4) * PrintDPI; #define ROTATE_ARC 50 const qreal minW = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare; const qreal minH = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare; -#define INACTIVE_Z 2 #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 * @param pParent pointer to the parent item */ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) - : QGraphicsObject(pParent), - m_eMode(VTextGraphicsItem::mNormal), - m_bReleased(false), + : VPieceItem(pParent), m_ptStartPos(), m_ptStart(), - m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), m_rectResize(), - m_rectBoundingBox(), m_tm() { - m_rectBoundingBox.setTopLeft(QPointF(0, 0)); + m_inactiveZ = 2; SetSize(minW, minH); - setZValue(INACTIVE_Z); - setAcceptHoverEvents(true); + setZValue(m_inactiveZ); } //--------------------------------------------------------------------------------------------------------------------- @@ -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. @@ -374,16 +400,6 @@ int VTextGraphicsItem::GetFontSize() const 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 @@ -617,82 +633,3 @@ void VTextGraphicsItem::CorrectLabel() m_tm.FitFontSize(m_rectBoundingBox.width(), m_rectBoundingBox.height()); 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; -} diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 923b91ac2..1748ddc9c 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -40,6 +40,7 @@ #include #include +#include "vpieceitem.h" #include "../vlayout/vtextmanager.h" class QFont; @@ -59,70 +60,50 @@ class VPatternPieceData; * 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. */ -class VTextGraphicsItem : public QGraphicsObject +class VTextGraphicsItem : public VPieceItem { Q_OBJECT - - enum Mode { - mNormal, - mMove, - mResize, - mRotate - }; - public: explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr); 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, QWidget *widget) Q_DECL_OVERRIDE; + virtual void Update() Q_DECL_OVERRIDE; - void Reset(); - bool IsIdle() const; - - int GetFontSize() const; - virtual QRectF boundingRect() const Q_DECL_OVERRIDE; - void AddLine(const TextLine& tl); - void Clear(); - void SetSize(qreal fW, qreal fH); - void Update(); - 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; + void SetFont(const QFont& fnt); + int GetFontSize() const; + void AddLine(const TextLine& tl); + void Clear(); + void SetSize(qreal fW, qreal fH); + 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: - 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 hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE; - void UpdateBox(); - void CorrectLabel(); + 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 hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE; - double GetAngle(QPointF pt) const; + void UpdateBox(); + void CorrectLabel(); signals: - void SignalMoved(const QPointF& ptPos); - void SignalResized(qreal iTW, int iFontSize); - void SignalRotated(qreal dAng); - void SignalShrink(); + void SignalResized(qreal iTW, int iFontSize); + void SignalRotated(qreal dAng); + void SignalShrink(); private: - Mode m_eMode; - bool m_bReleased; - QPointF m_ptStartPos; - QPointF m_ptStart; - QPointF m_ptRotCenter; - QSizeF m_szStart; - double m_dRotation; - double m_dAngle; - QRectF m_rectResize; - QRectF m_rectBoundingBox; - VTextManager m_tm; - - QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const; + Q_DISABLE_COPY(VTextGraphicsItem) + QPointF m_ptStartPos; + QPointF m_ptStart; + QSizeF m_szStart; + double m_dRotation; + double m_dAngle; + QRectF m_rectResize; + VTextManager m_tm; }; #endif // VTEXTGRAPHICSITEM_H