1 /************************************************************************
2  **
3  **  @file   vcontrolpointspline.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   November 15, 2013
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2013-2015 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina 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  **  Valentina 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 Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef VCONTROLPOINTSPLINE_H
30 #define VCONTROLPOINTSPLINE_H
31 
32 #include <qcompilerdetection.h>
33 #include <QGraphicsItem>
34 #include <QMetaObject>
35 #include <QObject>
36 #include <QPointF>
37 #include <QString>
38 #include <QVariant>
39 #include <QtGlobal>
40 
41 #include "../vgeometry/vgeometrydef.h"
42 #include "../vgeometry/vsplinepath.h"
43 #include "../vmisc/def.h"
44 #include "vscenepoint.h"
45 
46 /**
47  * @brief The VControlPointSpline class control spline point.
48  */
49 class VControlPointSpline : public QObject, public VScenePoint
50 {
51     Q_OBJECT
52 public:
53     VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem * parent = nullptr);
54     VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint,
55                         bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr);
56     virtual ~VControlPointSpline() =default;
57 
type()58     virtual int  type() const override {return Type;}
59     enum { Type = UserType + static_cast<int>(Vis::ControlPointSpline)};
60 
61     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
62                        QWidget *widget = nullptr) override;
63 signals:
64     /**
65      * @brief ControlPointChangePosition emit when control point change position.
66      * @param indexSpline index spline in list.
67      * @param position position point in spline.
68      * @param pos new posotion.
69      */
70     void              ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position,
71                                                  const QPointF &pos);
72     /**
73      * @brief ShowContextMenu emit when need show tool's context menu.
74      * @param event context menu event.
75      */
76     void              ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
77     void              Released();
78     void              Selected(bool selected);
79 public slots:
80     void              RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
81                                        const QPointF &splinePoint, bool freeAngle = true, bool freeLength = true);
82     void              setEnabledPoint(bool enable);
83 protected:
84     /** @brief controlLine pointer to line control point. */
85     VScaledLine      *controlLine;
86 
87     virtual void      hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) override;
88     QVariant          itemChange ( GraphicsItemChange change, const QVariant &value ) override;
89     virtual void      mousePressEvent( QGraphicsSceneMouseEvent * event ) override;
90     virtual void      mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) override;
91     virtual void      contextMenuEvent ( QGraphicsSceneContextMenuEvent *event ) override;
92 private:
93     Q_DISABLE_COPY(VControlPointSpline)
94     /** @brief indexSpline index spline in list.. */
95     qint32            indexSpline;
96 
97     /** @brief position position point in spline. */
98     SplinePointPosition position;
99 
100     bool freeAngle;
101     bool freeLength;
102 
103     void  Init();
104     void  SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint);
105 };
106 
107 #endif // VCONTROLPOINTSPLINE_H
108