Seamly2D
Code documentation
vgrainlineitem.h
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vgrainlineitem.h
4  ** @author Bojan Kverh
5  ** @date September 10, 2016
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2013-2015 Seamly2D project
12  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef VGRAINLINEITEM_H
30 #define VGRAINLINEITEM_H
31 
32 #include "vpieceitem.h"
33 #include "../vpatterndb/floatItemData/vgrainlinedata.h"
34 #include "../vmisc/def.h"
35 
36 class VGrainlineItem : public VPieceItem
37 {
38  Q_OBJECT
39 public:
40  explicit VGrainlineItem(QGraphicsItem* pParent = nullptr);
41  virtual ~VGrainlineItem() Q_DECL_EQ_DEFAULT;
42 
43  virtual QPainterPath shape() const Q_DECL_OVERRIDE;
44 
45  virtual void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) Q_DECL_OVERRIDE;
46  void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, ArrowType eAT);
47 
48  virtual int type() const Q_DECL_OVERRIDE {return Type;}
49  enum { Type = UserType + static_cast<int>(Vis::GrainlineItem)};
50 
51  bool isContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const;
52 
53 signals:
54  void itemResized(qreal dLength);
55  void itemRotated(qreal dRot, const QPointF& ptNewPos);
56 
57 protected:
58  virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
59  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
60  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
61  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* pME) Q_DECL_OVERRIDE;
62  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pME) Q_DECL_OVERRIDE;
63  virtual void Update() Q_DECL_OVERRIDE;
64  void UpdateRectangle();
65 
66  virtual double GetAngle(const QPointF &pt) const Q_DECL_OVERRIDE;
67 
68  QPointF Rotate(const QPointF& pt, const QPointF& ptCenter, qreal dAng) const;
69  QPointF GetInsideCorner(int i, qreal dDist) const;
70 
71 private:
72  Q_DISABLE_COPY(VGrainlineItem)
73  qreal m_dRotation;
75  qreal m_dLength;
76  QPolygonF m_polyBound;
77  QPointF m_ptStartPos;
78  QPointF m_ptStartMove;
79  qreal m_dScale;
80  QPolygonF m_polyResize;
82  QPointF m_ptStart;
83  QPointF m_ptFinish;
84  QPointF m_ptCenter;
85  qreal m_dAngle;
87  qreal m_penWidth;
88 
89  qreal GetScale() const;
90 
91  QLineF MainLine() const;
92  QPolygonF FirstArrow(qreal dArrLen) const;
93  QPolygonF SecondArrow(qreal dArrLen) const;
94 
95  QPainterPath MainShape() const;
96 
97  void allUserModifications(const QPointF &pos);
98  void userRotateAndMove();
99  void userMoveAndResize(const QPointF &pos);
100 
101  void UpdatePolyResize();
102 };
103 
104 #endif // VGRAINLINEITEM_H
bool isContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const
VGrainlineItem::isContained checks, if both ends of the grainline, starting at pt,...
void itemResized(qreal dLength)
QPolygonF m_polyBound
void UpdateRectangle()
VGrainlineItem::UpdateRectangle updates the polygon for the box around active item and the bounding r...
QPointF m_ptStartPos
void UpdateGeometry(const QPointF &ptPos, qreal dRotation, qreal dLength, ArrowType eAT)
VGrainlineItem::UpdateGeometry updates the item with grainline parameters.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem::mouseReleaseEvent handles mouse release events and emits the proper signal if the ite...
QPolygonF m_polyResize
QLineF MainLine() const
void allUserModifications(const QPointF &pos)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem::mouseMoveEvent handles mouse move events, making sure that the item is moved properly...
virtual void paint(QPainter *pP, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget) Q_DECL_OVERRIDE
VGrainlineItem::paint paints the item content.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem::mousePressEvent handles left button mouse press events.
QPainterPath MainShape() const
QPolygonF SecondArrow(qreal dArrLen) const
void itemRotated(qreal dRot, const QPointF &ptNewPos)
void userMoveAndResize(const QPointF &pos)
virtual void Update() Q_DECL_OVERRIDE
VGrainlineItem::Update updates the item.
QPointF GetInsideCorner(int i, qreal dDist) const
VGrainlineItem::GetInsideCorner calculates a point inside the bounding polygon, dDist away of i-th po...
qreal GetScale() const
GetScale gets the scale for keeping the arrows of constant size.
virtual ~VGrainlineItem() Q_DECL_EQ_DEFAULT
qreal m_dStartRotation
virtual QPainterPath shape() const Q_DECL_OVERRIDE
QPointF m_ptFinish
virtual int type() const Q_DECL_OVERRIDE
QPointF m_ptCenter
QPolygonF FirstArrow(qreal dArrLen) const
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *pME) Q_DECL_OVERRIDE
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pME) Q_DECL_OVERRIDE
QPointF m_ptStartMove
VGrainlineItem(QGraphicsItem *pParent=nullptr)
VGrainlineItem::VGrainlineItem constructor.
QPointF Rotate(const QPointF &pt, const QPointF &ptCenter, qreal dAng) const
VGrainlineItem::Rotate rotates point pt around ptCenter by angle dAng [rad] and returns the resulting...
ArrowType m_eArrowType
virtual double GetAngle(const QPointF &pt) const Q_DECL_OVERRIDE
GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis.
@ GrainlineItem
ArrowType
Definition: floatitemdef.h:60