Seamly2D
Code documentation
vistoolendline.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 vistoolendline.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 21 7, 2014
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 #include "vistoolendline.h"
53 
54 #include <QColor>
55 #include <QGuiApplication>
56 #include <QLineF>
57 #include <QPointF>
58 #include <QSharedPointer>
59 #include <Qt>
60 #include <new>
61 
62 #include "../ifc/xml/vdomdocument.h"
63 #include "../vgeometry/vgobject.h"
64 #include "../vgeometry/vpointf.h"
65 #include "../vmisc/vabstractapplication.h"
66 #include "../vmisc/vcommonsettings.h"
67 #include "../vpatterndb/vcontainer.h"
68 #include "../visualization.h"
69 #include "visline.h"
70 #include "vtranslatevars.h"
71 
72 //---------------------------------------------------------------------------------------------------------------------
73 VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
74  : VisLine(data, parent), length(0), angle(0), point(nullptr)
75 {
76  this->mainColor = Qt::red;
77 
78  point = InitPoint(mainColor, this);
79 }
80 
81 //---------------------------------------------------------------------------------------------------------------------
83 {
85  QLineF line;
86  if (qFuzzyIsNull(length))
87  {
88  if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
89  {
90  line = QLineF(static_cast<QPointF>(*first), Visualization::scenePos);
91  line.setAngle(CorrectAngle(line.angle()));
92  }
93  else
94  {
95  line = QLineF(static_cast<QPointF>(*first), Visualization::scenePos);
96  }
97  }
98  else
99  {
100  line = VGObject::BuildLine(static_cast<QPointF>(*first), length, angle);
101  DrawPoint(point, line.p2(), mainColor);
102  }
103  DrawLine(this, line, mainColor, lineWeight, lineStyle);
104  static const QString prefix = UnitsToStr(qApp->patternUnit(), true);
105  Visualization::toolTip = tr("<b>Point Length and Angle</b>: angle = %1°, length = %2%3; "
106  "Hold <b>SHIFT</b> to constrain angle, Press <b>ENTER</b> to finish tool creation")
107  .arg(this->line().angle())
108  .arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(this->line().length())),
109  qApp->Settings()->GetOsSeparator()))
110  .arg(prefix);
111 }
112 
113 //---------------------------------------------------------------------------------------------------------------------
114 QString VisToolEndLine::Angle() const
115 {
116  return QString("%1").arg(this->line().angle());
117 }
118 
119 //---------------------------------------------------------------------------------------------------------------------
120 void VisToolEndLine::SetAngle(const QString &expression)
121 {
122  angle = FindVal(expression, Visualization::data->DataVariables());
123 }
124 
125 //---------------------------------------------------------------------------------------------------------------------
126 QString VisToolEndLine::Length() const
127 {
128  return QString::number(qApp->fromPixel(this->line().length()));
129 }
130 
131 //---------------------------------------------------------------------------------------------------------------------
132 void VisToolEndLine::setLength(const QString &expression)
133 {
134  length = FindLength(expression, Visualization::data->DataVariables());
135 }
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
static QLineF BuildLine(const QPointF &p1, const qreal &length, const qreal &angle)
Definition: vgobject.cpp:241
The VPointF class keep data of point.
Definition: vpointf.h:75
static qreal CorrectAngle(const qreal &angle)
Definition: visline.cpp:54
void SetAngle(const QString &expression)
QString Angle() const
QString Length() const
VisToolEndLine(const VContainer *data, QGraphicsItem *parent=nullptr)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setLength(const QString &expression)
VScaledEllipse * point
QColor mainColor
Definition: visualization.h:99
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
static qreal FindLength(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
const VContainer * data
Definition: visualization.h:97
QPointF scenePos
Definition: visualization.h:98
virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, const qreal &lineWeight, Qt::PenStyle style=Qt::SolidLine)
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
static qreal FindVal(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
Qt::PenStyle lineStyle
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define qApp
Definition: vapplication.h:67