1 /************************************************************************
2  **
3  **  @file   vistoolendline.cpp
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   21 7, 2014
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 #include "vistoolendline.h"
30 
31 #include <QColor>
32 #include <QGuiApplication>
33 #include <QLineF>
34 #include <QPointF>
35 #include <QSharedPointer>
36 #include <Qt>
37 #include <new>
38 
39 #include "../ifc/xml/vdomdocument.h"
40 #include "../vgeometry/vgobject.h"
41 #include "../vgeometry/vpointf.h"
42 #include "../vmisc/vabstractapplication.h"
43 #include "../vmisc/vcommonsettings.h"
44 #include "../vmisc/vmodifierkey.h"
45 #include "../vpatterndb/vcontainer.h"
46 #include "../visualization.h"
47 #include "visline.h"
48 #include "vtranslatevars.h"
49 
50 //---------------------------------------------------------------------------------------------------------------------
VisToolEndLine(const VContainer * data,QGraphicsItem * parent)51 VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
52     : VisLine(data, parent), length(0), angle(0), point(nullptr)
53 {
54     this->mainColor = Qt::red;
55 
56     point = InitPoint(mainColor, this);
57 }
58 
59 //---------------------------------------------------------------------------------------------------------------------
RefreshGeometry()60 void VisToolEndLine::RefreshGeometry()
61 {
62     const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
63     QLineF line;
64     if (qFuzzyIsNull(length))
65     {
66         if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
67         {
68             line = QLineF(static_cast<QPointF>(*first), Visualization::scenePos);
69             line.setAngle(CorrectAngle(line.angle()));
70         }
71         else
72         {
73             line = QLineF(static_cast<QPointF>(*first), Visualization::scenePos);
74         }
75     }
76     else
77     {
78         line = VGObject::BuildLine(static_cast<QPointF>(*first), length, angle);
79         DrawPoint(point, line.p2(), mainColor);
80     }
81     DrawLine(this, line, mainColor, lineStyle);
82     static const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
83     Visualization::toolTip = tr("<b>Point at distance and angle</b>: angle = %1°, length = %2%3; "
84                                 "<b>%4</b> - sticking angle, <b>%5</b> - finish creation")
85             .arg(this->line().angle())
86             .arg(VAbstractApplication::VApp()->TrVars()
87                  ->FormulaToUser(QString::number(VAbstractValApplication::VApp()->fromPixel(this->line().length())),
88                                  VAbstractApplication::VApp()->Settings()->GetOsSeparator()),
89                  prefix, VModifierKey::Shift(), VModifierKey::EnterKey());
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
Angle() const93 QString VisToolEndLine::Angle() const
94 {
95     return QString("%1").arg(this->line().angle());
96 }
97 
98 //---------------------------------------------------------------------------------------------------------------------
SetAngle(const QString & expression)99 void VisToolEndLine::SetAngle(const QString &expression)
100 {
101     angle = FindValFromUser(expression, Visualization::data->DataVariables());
102 }
103 
104 //---------------------------------------------------------------------------------------------------------------------
Length() const105 QString VisToolEndLine::Length() const
106 {
107     return QString::number(VAbstractValApplication::VApp()->fromPixel(this->line().length()));
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
setLength(const QString & expression)111 void VisToolEndLine::setLength(const QString &expression)
112 {
113     length = FindLengthFromUser(expression, Visualization::data->DataVariables());
114 }
115