Seamly2D
Code documentation
vcontrolpointspline.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 vcontrolpointspline.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
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) 2013-2015 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 VCONTROLPOINTSPLINE_H
53 #define VCONTROLPOINTSPLINE_H
54 
55 #include <qcompilerdetection.h>
56 #include <QGraphicsItem>
57 #include <QMetaObject>
58 #include <QObject>
59 #include <QPointF>
60 #include <QString>
61 #include <QVariant>
62 #include <QtGlobal>
63 
64 #include "../vgeometry/vgeometrydef.h"
65 #include "../vgeometry/vsplinepath.h"
66 #include "../vmisc/def.h"
67 #include "scene_rect.h"
68 
69 /**
70  * @brief The VControlPointSpline class control spline point.
71  */
72 class VControlPointSpline : public QObject, public SceneRect
73 {
74  Q_OBJECT
75 public:
77  QGraphicsItem * parent = nullptr);
79  const QPointF &controlPoint, const QPointF &splinePoint,
80  bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr);
81  virtual ~VControlPointSpline() =default;
82 
83  virtual int type() const Q_DECL_OVERRIDE {return Type;}
84  enum { Type = UserType + static_cast<int>(Vis::ControlPointSpline)};
85 
86  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
87  QWidget *widget = nullptr) Q_DECL_OVERRIDE;
88 signals:
89  /**
90  * @brief ControlPointChangePosition emit when control point change position.
91  * @param indexSpline index spline in list.
92  * @param position position point in spline.
93  * @param pos new posotion.
94  */
96  const QPointF &pos);
97  /**
98  * @brief showContextMenu emit when need show tool's context menu.
99  * @param event context menu event.
100  */
101  void showContextMenu(QGraphicsSceneContextMenuEvent *event);
102 
103 public slots:
104  void refreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
105  const QPointF &splinePoint, bool freeAngle = true, bool freeLength = true);
106  void setEnabledPoint(bool enable);
107 
108 protected:
109  /** @brief controlLine pointer to line control point. */
111 
112  virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
113  virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
114  QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE;
115  virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
116  virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
117  virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event ) Q_DECL_OVERRIDE;
118 
119 private:
120  Q_DISABLE_COPY(VControlPointSpline)
121  /** @brief indexSpline index spline in list.. */
122  qint32 indexSpline;
123 
124  /** @brief position position point in spline. */
126 
127  bool freeAngle;
129 
130  void init();
131  void setCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint);
132 };
133 
134 #endif // VCONTROLPOINTSPLINE_H
The VControlPointSpline class control spline point.
qint32 indexSpline
indexSpline index spline in list..
QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE
itemChange handle item change.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE
void showContextMenu(QGraphicsSceneContextMenuEvent *event)
showContextMenu emit when need show tool's context menu.
void ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position, const QPointF &pos)
ControlPointChangePosition emit when control point change position.
SplinePointPosition position
position position point in spline.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverEnterEvent handle hover enter events.
virtual ~VControlPointSpline()=default
void setCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint)
virtual int type() const Q_DECL_OVERRIDE
void setEnabledPoint(bool enable)
setEnabledPoint disable or enable control point.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) Q_DECL_OVERRIDE
VScaledLine * controlLine
controlLine pointer to line control point.
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem *parent=nullptr)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
void refreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, const QPointF &splinePoint, bool freeAngle=true, bool freeLength=true)
refreshCtrlPoint refresh the control point.
@ ControlPointSpline
SplinePointPosition
Definition: vgeometrydef.h:58