Seamly2D
Code documentation
vpieceitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 18 1, 2017
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2017 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VPIECEITEM_H
53 #define VPIECEITEM_H
54 
55 #include <QtCore/qglobal.h>
56 #include <QGraphicsObject>
57 
58 #include "../vmisc/def.h"
59 
60 class VPieceItem : public QGraphicsObject
61 {
62  Q_OBJECT
63 public:
64  enum MoveType
65  {
66  NotMovable = 0x0,
67  IsRotatable = 0x1, // 0001
68  IsResizable = 0x2, // 0010
69  IsMovable = 0x4, // 0100
71  Error = 0x8 // 1000
72  };
73  Q_DECLARE_FLAGS(MoveTypes, MoveType)
74 
75  explicit VPieceItem(QGraphicsItem* pParent = nullptr);
76  virtual ~VPieceItem();
77 
78  virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
79 
80  virtual void Update() =0;
81 
82  void Reset();
83  bool IsIdle() const;
84 
85  VPieceItem::MoveTypes GetMoveType() const;
86  void SetMoveType(const VPieceItem::MoveTypes &moveType);
87 
88  virtual int type() const Q_DECL_OVERRIDE {return Type;}
89  enum { Type = UserType + static_cast<int>(Vis::PieceItem)};
90 
91 signals:
92  void itemMoved(const QPointF &ptPos);
93 
94 protected:
95  enum Mode
96  {
100  mRotate
101  };
105  QPointF m_ptRotCenter;
106  VPieceItem::MoveTypes m_moveType;
107 
108  qreal m_inactiveZ;
109 
110  virtual double GetAngle(const QPointF &pt) const;
111 
112 private:
113  Q_DISABLE_COPY(VPieceItem)
114 };
115 
116 Q_DECLARE_OPERATORS_FOR_FLAGS(VPieceItem::MoveTypes)
117 
118 #endif // VPIECEITEM_H
@ AllModifications
Definition: vpieceitem.h:70
QRectF m_rectBoundingBox
Definition: vpieceitem.h:102
VPieceItem::MoveTypes m_moveType
Definition: vpieceitem.h:106
virtual int type() const Q_DECL_OVERRIDE
Definition: vpieceitem.h:88
virtual void Update()=0
bool IsIdle() const
IsIdle returns the idle flag.
Definition: vpieceitem.cpp:107
qreal m_inactiveZ
Definition: vpieceitem.h:108
bool m_bReleased
Definition: vpieceitem.h:104
virtual QRectF boundingRect() const Q_DECL_OVERRIDE
boundingRect returns the item bounding box
Definition: vpieceitem.cpp:81
VPieceItem(QGraphicsItem *pParent=nullptr)
Definition: vpieceitem.cpp:58
virtual double GetAngle(const QPointF &pt) const
GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis.
Definition: vpieceitem.cpp:118
void itemMoved(const QPointF &ptPos)
virtual ~VPieceItem()
Definition: vpieceitem.cpp:72
VPieceItem::MoveTypes GetMoveType() const
Definition: vpieceitem.cpp:134
void Reset()
Reset resets the item, putting the mode and z coordinate to normal and redraws it.
Definition: vpieceitem.cpp:90
QPointF m_ptRotCenter
Definition: vpieceitem.h:105
void SetMoveType(const VPieceItem::MoveTypes &moveType)
Definition: vpieceitem.cpp:140
Mode m_eMode
Definition: vpieceitem.h:103
@ PieceItem