Seamly2D
Code documentation
dialogpointofintersectioncurves.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 dialogpointofintersectioncurves.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 23 1, 2016
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) 2016 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 
53 
54 #include <QColor>
55 #include <QComboBox>
56 #include <QLabel>
57 #include <QLineEdit>
58 #include <QPointer>
59 #include <QPushButton>
60 
61 #include "../../visualization/path/vistoolpointofintersectioncurves.h"
62 #include "../../visualization/visualization.h"
63 #include "../vmisc/vabstractapplication.h"
64 #include "dialogtool.h"
65 #include "ui_dialogpointofintersectioncurves.h"
66 
67 //---------------------------------------------------------------------------------------------------------------------
69  QWidget *parent)
70  : DialogTool(data, toolId, parent)
72 {
73  ui->setupUi(this);
74  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
75  setWindowIcon(QIcon(":/toolicon/32x32/intersection_curves.png"));
76 
77  ui->lineEditNamePoint->setClearButtonEnabled(true);
78 
79  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
80  labelEditNamePoint = ui->labelEditNamePoint;
81 
83  CheckState();
84 
85  FillComboBoxCurves(ui->comboBoxCurve1);
86  FillComboBoxCurves(ui->comboBoxCurve2);
87  FillComboBoxVCrossCurvesPoint(ui->verticalTake_ComboBox);
88  FillComboBoxHCrossCurvesPoint(ui->horizontalTake_ComboBox);
89 
90  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersectionCurves::NamePointChanged);
91  connect(ui->comboBoxCurve1, &QComboBox::currentTextChanged, this, &DialogPointOfIntersectionCurves::CurveChanged);
92  connect(ui->comboBoxCurve2, &QComboBox::currentTextChanged, this, &DialogPointOfIntersectionCurves::CurveChanged);
93 
95 }
96 
97 //---------------------------------------------------------------------------------------------------------------------
99 {
100  delete ui;
101 }
102 
103 //---------------------------------------------------------------------------------------------------------------------
105 {
106  pointName = value;
107  ui->lineEditNamePoint->setText(pointName);
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
112 {
113  return getCurrentObjectId(ui->comboBoxCurve1);
114 }
115 
116 //---------------------------------------------------------------------------------------------------------------------
118 {
119  setCurrentCurveId(ui->comboBoxCurve1, value);
120 
121  auto point = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
122  SCASSERT(point != nullptr)
123  point->setObject1Id(value);
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
128 {
129  return getCurrentObjectId(ui->comboBoxCurve2);
130 }
131 
132 //---------------------------------------------------------------------------------------------------------------------
134 {
135  setCurrentCurveId(ui->comboBoxCurve2, value);
136 
137  auto point = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
138  SCASSERT(point != nullptr)
139  point->setObject2Id(value);
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
144 {
145  return getCurrentCrossPoint<VCrossCurvesPoint>(ui->verticalTake_ComboBox);
146 }
147 
148 //---------------------------------------------------------------------------------------------------------------------
150 {
151  auto index = ui->verticalTake_ComboBox->findData(static_cast<int>(vP));
152  if (index != -1)
153  {
154  ui->verticalTake_ComboBox->setCurrentIndex(index);
155 
156  auto point = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
157  SCASSERT(point != nullptr)
158  point->setVCrossPoint(vP);
159  }
160 }
161 
162 //---------------------------------------------------------------------------------------------------------------------
164 {
165  return getCurrentCrossPoint<HCrossCurvesPoint>(ui->horizontalTake_ComboBox);
166 }
167 
168 //---------------------------------------------------------------------------------------------------------------------
170 {
171  auto index = ui->horizontalTake_ComboBox->findData(static_cast<int>(hP));
172  if (index != -1)
173  {
174  ui->horizontalTake_ComboBox->setCurrentIndex(index);
175 
176  auto point = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
177  SCASSERT(point != nullptr)
178  point->setHCrossPoint(hP);
179  }
180 }
181 
182 //---------------------------------------------------------------------------------------------------------------------
184 {
185  if (prepare == false)// After first choose we ignore all objects
186  {
187  if (type == SceneObject::Spline
188  || type == SceneObject::Arc
189  || type == SceneObject::ElArc
190  || type == SceneObject::SplinePath)
191  {
192  auto point = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
193  SCASSERT(point != nullptr)
194 
195  switch (number)
196  {
197  case 0:
198  if (SetObject(id, ui->comboBoxCurve1, tr("Select second curve")))
199  {
200  number++;
201  point->VisualMode(id);
202  }
203  break;
204  case 1:
205  if (getCurrentObjectId(ui->comboBoxCurve1) != id)
206  {
207  if (SetObject(id, ui->comboBoxCurve2, ""))
208  {
209  number = 0;
210  point->setObject2Id(id);
211  point->RefreshGeometry();
212  prepare = true;
213  DialogAccepted();
214  }
215  }
216  break;
217  default:
218  break;
219  }
220  }
221  }
222 }
223 
224 //---------------------------------------------------------------------------------------------------------------------
226 {
227  AddVisualization<VisToolPointOfIntersectionCurves>();
228 }
229 
230 //---------------------------------------------------------------------------------------------------------------------
232 {
233  pointName = ui->lineEditNamePoint->text();
234 
235  auto point = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
236  SCASSERT(point != nullptr)
237 
238  point->setObject1Id(GetFirstCurveId());
239  point->setObject2Id(GetSecondCurveId());
240  point->setVCrossPoint(GetVCrossPoint());
241  point->setHCrossPoint(GetHCrossPoint());
242  point->RefreshGeometry();
243 }
244 
245 //---------------------------------------------------------------------------------------------------------------------
247 {
248  SCASSERT(ok_Button != nullptr)
249  ok_Button->setEnabled(flagName && flagError);
250  // In case dialog hasn't apply button
251  if (apply_Button != nullptr)
252  {
253  apply_Button->setEnabled(ok_Button->isEnabled());
254  }
255 }
256 
257 //---------------------------------------------------------------------------------------------------------------------
259 {
260  QColor color = okColor;
261  if (getCurrentObjectId(ui->comboBoxCurve1) == getCurrentObjectId(ui->comboBoxCurve2))
262  {
263  flagError = false;
264  color = errorColor;
265  }
266  else
267  {
268  flagError = true;
269  color = okColor;
270  }
271  ChangeColor(ui->labelCurve1, color);
272  ChangeColor(ui->labelCurve2, color);
273  CheckState();
274 }
void SetVCrossPoint(const VCrossCurvesPoint &vP)
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
virtual ~DialogPointOfIntersectionCurves() Q_DECL_OVERRIDE
void SetHCrossPoint(const HCrossCurvesPoint &hP)
virtual void CheckState() Q_DECL_FINAL
CheckState enable, when all is correct, or disable, when something wrong, button ok.
DialogPointOfIntersectionCurves(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
Ui::DialogPointOfIntersectionCurves * ui
virtual void ShowVisualization() Q_DECL_OVERRIDE
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
const QColor okColor
Definition: dialogtool.h:219
void NamePointChanged()
NamePointChanged check name of point.
bool flagName
flagName true if name is correct
Definition: dialogtool.h:183
QPushButton * ok_Button
ok_Button button ok
Definition: dialogtool.h:199
QString pointName
pointName name of point
Definition: dialogtool.h:231
const QColor errorColor
Definition: dialogtool.h:220
qint32 number
number number of handled objects
Definition: dialogtool.h:234
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
virtual void DialogAccepted()
DialogAccepted save data and emit signal about closed dialog.
QPushButton * apply_Button
apply_Button button apply
Definition: dialogtool.h:202
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
void FillComboBoxCurves(QComboBox *box) const
Definition: dialogtool.cpp:302
void initializeOkCancelApply(T *ui)
initializeOkCancelApply initialize OK / Cancel and Apply buttons
Definition: dialogtool.h:365
void FillComboBoxVCrossCurvesPoint(QComboBox *box) const
Definition: dialogtool.cpp:382
bool flagError
flagError use this flag if for you do not enought
Definition: dialogtool.h:193
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 FillComboBoxHCrossCurvesPoint(QComboBox *box) const
Definition: dialogtool.cpp:391
void setCurrentCurveId(QComboBox *box, const quint32 &value) const
Definition: dialogtool.cpp:946
QPointer< Visualization > vis
Definition: dialogtool.h:236
void ChangeColor(QWidget *widget, const QColor &color)
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
The VContainer class container of all variables.
Definition: vcontainer.h:141
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
HCrossCurvesPoint
VCrossCurvesPoint
#define qApp
Definition: vapplication.h:67