Seamly2D
Code documentation
vpieceitem.cpp
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 #include "vpieceitem.h"
53 #include "../vmisc/vmath.h"
54 
55 #include <QGraphicsScene>
56 
57 //---------------------------------------------------------------------------------------------------------------------
58 VPieceItem::VPieceItem(QGraphicsItem *pParent)
59  : QGraphicsObject(pParent),
60  m_rectBoundingBox(),
61  m_eMode(VPieceItem::mNormal),
62  m_bReleased(false),
63  m_ptRotCenter(),
64  m_moveType(AllModifications),
65  m_inactiveZ(1)
66 {
67  m_rectBoundingBox.setTopLeft(QPointF(0, 0));
68  setAcceptHoverEvents(true);
69 }
70 
71 //---------------------------------------------------------------------------------------------------------------------
73 {
74 }
75 
76 //---------------------------------------------------------------------------------------------------------------------
77 /**
78  * @brief boundingRect returns the item bounding box
79  * @return item bounding box
80  */
82 {
83  return m_rectBoundingBox;
84 }
85 
86 //---------------------------------------------------------------------------------------------------------------------
87 /**
88  * @brief Reset resets the item, putting the mode and z coordinate to normal and redraws it
89  */
91 {
92  if (QGraphicsScene *toolScene = scene())
93  {
94  toolScene->clearSelection();
95  }
96  m_eMode = mNormal;
97  m_bReleased = false;
98  Update();
99  setZValue(m_inactiveZ);
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
103 /**
104  * @brief IsIdle returns the idle flag.
105  * @return true, if item mode is normal and false otherwise.
106  */
107 bool VPieceItem::IsIdle() const
108 {
109  return m_eMode == mNormal;
110 }
111 
112 //---------------------------------------------------------------------------------------------------------------------
113 /**
114  * @brief GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis
115  * @param pt point of interest
116  * @return the angle between line from rotation center and point of interest and x axis
117  */
118 double VPieceItem::GetAngle(const QPointF &pt) const
119 {
120  const double dX = pt.x() - m_ptRotCenter.x();
121  const double dY = pt.y() - m_ptRotCenter.y();
122 
123  if (fabs(dX) < 1 && fabs(dY) < 1)
124  {
125  return 0;
126  }
127  else
128  {
129  return qAtan2(dY, dX);
130  }
131 }
132 
133 //---------------------------------------------------------------------------------------------------------------------
134 VPieceItem::MoveTypes VPieceItem::GetMoveType() const
135 {
136  return m_moveType;
137 }
138 
139 //---------------------------------------------------------------------------------------------------------------------
140 void VPieceItem::SetMoveType(const VPieceItem::MoveTypes &moveType)
141 {
142  m_moveType = moveType;
143  setAcceptHoverEvents(m_moveType != NotMovable);
144 }
QRectF m_rectBoundingBox
Definition: vpieceitem.h:102
VPieceItem::MoveTypes m_moveType
Definition: vpieceitem.h:106
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
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