1 /************************************************************************
2  **
3  **  @file   vtoolline.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 VTOOLLINE_H
30 #define VTOOLLINE_H
31 
32 #include <qcompilerdetection.h>
33 #include <QDomElement>
34 #include <QMetaObject>
35 #include <QObject>
36 #include <QString>
37 #include <QVariant>
38 #include <QtGlobal>
39 
40 #include "../ifc/xml/vabstractpattern.h"
41 #include "../vmisc/def.h"
42 #include "vdrawtool.h"
43 #include "../vwidgets/scalesceneitems.h"
44 
45 template <class T> class QSharedPointer;
46 
47 struct VToolLineInitData : VDrawToolInitData
48 {
VToolLineInitDataVToolLineInitData49     VToolLineInitData()
50         : VDrawToolInitData(),
51           firstPoint(NULL_ID),
52           secondPoint(NULL_ID),
53           typeLine(TypeLineLine),
54           lineColor(ColorBlack)
55     {}
56 
57     quint32 firstPoint;
58     quint32 secondPoint;
59     QString typeLine;
60     QString lineColor;
61 };
62 
63 /**
64  * @brief The VToolLine class tool for creation line.
65  */
66 class VToolLine: public VDrawTool, public VScaledLine
67 {
68     Q_OBJECT
69 public:
70     virtual void     setDialog() override;
71     static VToolLine *Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene  *scene, VAbstractPattern *doc,
72                              VContainer *data);
73     static VToolLine *Create(VToolLineInitData initData);
74 
type()75     virtual int      type() const override {return Type;}
76     enum { Type = UserType + static_cast<int>(Tool::Line)};
77     virtual QString  getTagName() const override;
78 
79     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
80                        QWidget *widget = nullptr) override;
81 
82     QString FirstPointName() const;
83     QString SecondPointName() const;
84 
85     QString GetLineColor() const;
86     void    SetLineColor(const QString &value);
87 
88     virtual void SetNotes(const QString &notes) override;
89 
90     virtual void     ShowVisualization(bool show) override;
91 
92     virtual void     SetLineType(const QString &value) override;
93     virtual void     GroupVisibility(quint32 object, bool visible) override;
94 public slots:
95     virtual void     FullUpdateFromFile() override;
96     virtual void     ShowTool(quint32 id, bool enable) override;
97     virtual void     Disable(bool disable, const QString &namePP) override;
98     virtual void     AllowHover(bool enabled) override;
99     virtual void     AllowSelecting(bool enabled) override;
100 protected slots:
101     virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) override;
102 protected:
103     virtual void     contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) override;
104     virtual void     AddToFile() override;
105     virtual void     hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) override;
106     virtual void     hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) override;
107     virtual void     RemoveReferens() override;
108     virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) override;
109     virtual void     keyReleaseEvent(QKeyEvent * event) override;
110     virtual void     SaveDialog(QDomElement &domElement, QList<quint32> &oldDependencies,
111                                 QList<quint32> &newDependencies) override;
112     virtual void     SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) override;
113     virtual void     ReadToolAttributes(const QDomElement &domElement) override;
114     virtual void     SetVisualization() override;
115     virtual QString  MakeToolTip() const override;
116 private:
117     Q_DISABLE_COPY(VToolLine)
118 
119     /** @brief firstPoint id first line point. */
120     quint32           firstPoint;
121 
122     /** @brief secondPoint id second line point. */
123     quint32           secondPoint;
124 
125     /** @brief lineColor color of a line. */
126     QString           lineColor;
127 
128     bool m_acceptHoverEvents;
129 
130     VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent = nullptr);
131 
132     void RefreshGeometry();
133 };
134 
135 #endif // VTOOLLINE_H
136