Seamly2D
Code documentation
dialogcutarc.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 dialogcutarc.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 7 1, 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 "dialogcutarc.h"
53 
54 #include <QDialog>
55 #include <QLineEdit>
56 #include <QPlainTextEdit>
57 #include <QPointer>
58 #include <QPushButton>
59 #include <QToolButton>
60 
61 #include "../vpatterndb/vtranslatevars.h"
62 #include "../../visualization/path/vistoolcutarc.h"
63 #include "../../visualization/visualization.h"
64 #include "../ifc/xml/vabstractpattern.h"
65 #include "../ifc/xml/vdomdocument.h"
66 #include "../support/edit_formula_dialog.h"
67 #include "../vmisc/vabstractapplication.h"
68 #include "../vmisc/vcommonsettings.h"
69 #include "ui_dialogcutarc.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 /**
73  * @brief DialogCutArc create dialog.
74  * @param data container with data
75  * @param parent parent widget
76  */
77 DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
78  : DialogTool(data, toolId, parent)
79  , ui(new Ui::DialogCutArc)
80  , formula(QString())
81  , formulaBaseHeight(0)
82 {
83  ui->setupUi(this);
84  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
85  setWindowIcon(QIcon(":/toolicon/32x32/arc_cut.png"));
86 
87  ui->lineEditNamePoint->setClearButtonEnabled(true);
88 
90  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
91  labelEditNamePoint = ui->labelEditNamePoint;
92  this->formulaBaseHeight = ui->plainTextEditFormula->height();
93  ui->plainTextEditFormula->installEventFilter(this);
94 
96  flagFormula = false;
98 
99  FillComboBoxArcs(ui->comboBoxArc);
100 
101  connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutArc::FXLength);
102  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged);
103  connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutArc::FormulaTextChanged);
104  connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutArc::DeployFormulaTextEdit);
105 
106  vis = new VisToolCutArc(data);
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {
112  this->FormulaChangedPlainText();
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
117 {
118  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
119  dialog->setWindowTitle(tr("Edit length"));
120  dialog->SetFormula(GetFormula());
121  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
122  if (dialog->exec() == QDialog::Accepted)
123  {
124  SetFormula(dialog->GetFormula());
125  }
126  delete dialog;
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
131 {
132  AddVisualization<VisToolCutArc>();
133 }
134 
135 //---------------------------------------------------------------------------------------------------------------------
137 {
138  DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
139 }
140 
141 //---------------------------------------------------------------------------------------------------------------------
143 {
144  delete ui;
145 }
146 
147 //---------------------------------------------------------------------------------------------------------------------
148 /**
149  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
150  * @param id id of point or detail
151  * @param type type of object
152  */
153 void DialogCutArc::ChosenObject(quint32 id, const SceneObject &type)
154 {
155  if (prepare == false)// After first choose we ignore all objects
156  {
157  if (type == SceneObject::Arc)
158  {
159  if (SetObject(id, ui->comboBoxArc, ""))
160  {
161  vis->VisualMode(id);
162  prepare = true;
163  this->setModal(true);
164  this->show();
165  }
166  }
167  }
168 }
169 
170 //---------------------------------------------------------------------------------------------------------------------
172 {
173  pointName = ui->lineEditNamePoint->text();
174  formula = ui->plainTextEditFormula->toPlainText();
175  formula.replace("\n", " ");
176 
177  VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
178  SCASSERT(path != nullptr)
179 
180  path->setObject1Id(getArcId());
181  path->setLength(formula);
182  path->RefreshGeometry();
183 }
184 
185 //---------------------------------------------------------------------------------------------------------------------
186 void DialogCutArc::closeEvent(QCloseEvent *event)
187 {
188  ui->plainTextEditFormula->blockSignals(true);
189  DialogTool::closeEvent(event);
190 }
191 
192 //---------------------------------------------------------------------------------------------------------------------
193 /**
194  * @brief setArcId set id of arc
195  * @param value id
196  */
197 void DialogCutArc::setArcId(const quint32 &value)
198 {
199  setCurrentArcId(ui->comboBoxArc, value);
200 
201  VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
202  SCASSERT(path != nullptr)
203  path->setObject1Id(value);
204 }
205 
206 //---------------------------------------------------------------------------------------------------------------------
207 /**
208  * @brief SetFormula set string with formula length
209  * @param value string with formula
210  */
211 void DialogCutArc::SetFormula(const QString &value)
212 {
213  formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
214  // increase height if needed.
215  if (formula.length() > 80)
216  {
217  this->DeployFormulaTextEdit();
218  }
219  ui->plainTextEditFormula->setPlainText(formula);
220 
221  VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
222  SCASSERT(path != nullptr)
223  path->setLength(formula);
224 
225  MoveCursorToEnd(ui->plainTextEditFormula);
226 }
227 
228 //---------------------------------------------------------------------------------------------------------------------
229 /**
230  * @brief SetPointName set name point on arc
231  * @param value name
232  */
233 void DialogCutArc::SetPointName(const QString &value)
234 {
235  pointName = value;
236  ui->lineEditNamePoint->setText(pointName);
237 }
238 
239 //---------------------------------------------------------------------------------------------------------------------
240 /**
241  * @brief GetFormula return string with formula length
242  * @return formula
243  */
245 {
246  return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
247 }
248 
249 //---------------------------------------------------------------------------------------------------------------------
250 /**
251  * @brief getArcId return id of arc
252  * @return id
253  */
254 quint32 DialogCutArc::getArcId() const
255 {
256  return getCurrentObjectId(ui->comboBoxArc);
257 }
The DialogCutArc class dialog for ToolCutArc.
Definition: dialogcutarc.h:73
virtual ~DialogCutArc() Q_DECL_OVERRIDE
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
void FormulaTextChanged()
FormulaTextChanged when formula text changes for validation and calc.
virtual void ShowVisualization() Q_DECL_OVERRIDE
DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogCutArc create dialog.
void DeployFormulaTextEdit()
DeployFormulaTextEdit grow or shrink formula input.
void SetFormula(const QString &value)
SetFormula set string with formula length.
void SetPointName(const QString &value)
SetPointName set name point on arc.
quint32 getArcId() const
getArcId return id of arc
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
QString formula
formula string with formula
Definition: dialogcutarc.h:111
Ui::DialogCutArc * ui
ui keeps information about user interface
Definition: dialogcutarc.h:108
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
QString GetFormula() const
GetFormula return string with formula length.
void setArcId(const quint32 &value)
setArcId set id of arc
int formulaBaseHeight
formulaBaseHeight base height defined by dialogui
Definition: dialogcutarc.h:114
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule=FillComboBox::NoChildren, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
setCurrentArcId
Definition: dialogtool.cpp:924
virtual void CheckState()
CheckState enable, when all is correct, or disable, when something wrong, button ok.
void NamePointChanged()
NamePointChanged check name of point.
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
Definition: dialogtool.cpp:432
bool flagFormula
flagFormula true if formula correct
Definition: dialogtool.h:186
QString pointName
pointName name of point
Definition: dialogtool.h:231
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
Definition: dialogtool.cpp:192
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
quint32 toolId
Definition: dialogtool.h:225
void FillComboBoxArcs(QComboBox *box, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
Definition: dialogtool.cpp:248
void initializeOkCancelApply(T *ui)
initializeOkCancelApply initialize OK / Cancel and Apply buttons
Definition: dialogtool.h:365
const VContainer * data
data container with data
Definition: dialogtool.h:177
bool prepare
prepare show if we prepare. Show dialog after finish working with visual part of tool
Definition: dialogtool.h:228
void initializeFormulaUi(T *ui)
initializeFormulaUi initialize ui object for the formula field
Definition: dialogtool.h:398
QPointer< Visualization > vis
Definition: dialogtool.h:236
void FormulaChangedPlainText()
FormulaChangedPlainText check formula (plain text editor editor)
void DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight)
Definition: dialogtool.cpp:992
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
The EditFormulaDialog class dialog for editing wrong formula.
QString GetFormula() const
void SetFormula(const QString &value)
void setPostfix(const QString &value)
The VContainer class container of all variables.
Definition: vcontainer.h:141
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setLength(const QString &expression)
void setObject1Id(const quint32 &value)
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
#define qApp
Definition: vapplication.h:67