Seamly2D
Code documentation
dialogpointofintersectionarcs.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 dialogpointofintersectionarcs.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 25 5, 2015
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) 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 
53 
54 #include <QColor>
55 #include <QComboBox>
56 #include <QLabel>
57 #include <QLineEdit>
58 #include <QPointer>
59 
60 #include "../../visualization/visualization.h"
61 #include "../../visualization/line/vistoolpointofintersectionarcs.h"
62 #include "../vmisc/vabstractapplication.h"
64 #include "ui_dialogpointofintersectionarcs.h"
65 
66 //---------------------------------------------------------------------------------------------------------------------
68  QWidget *parent)
69  : DialogTool(data, toolId, parent)
71 {
72  ui->setupUi(this);
73  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
74  setWindowIcon(QIcon(":/toolicon/32x32/point_of_intersection_arcs.png"));
75 
76  ui->lineEditNamePoint->setClearButtonEnabled(true);
77 
78  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
79  labelEditNamePoint = ui->labelEditNamePoint;
80 
83 
84  FillComboBoxArcs(ui->comboBoxArc1);
85  FillComboBoxArcs(ui->comboBoxArc2);
86  FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
87 
88  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersectionArcs::NamePointChanged);
89  connect(ui->comboBoxArc1, &QComboBox::currentTextChanged, this, &DialogPointOfIntersectionArcs::ArcChanged);
90  connect(ui->comboBoxArc1, &QComboBox::currentTextChanged, this, &DialogPointOfIntersectionArcs::ArcChanged);
91 
93 }
94 
95 //---------------------------------------------------------------------------------------------------------------------
97 {
98  delete ui;
99 }
100 
101 //---------------------------------------------------------------------------------------------------------------------
103 {
104  pointName = value;
105  ui->lineEditNamePoint->setText(pointName);
106 }
107 
108 //---------------------------------------------------------------------------------------------------------------------
110 {
111  return getCurrentObjectId(ui->comboBoxArc1);
112 }
113 
114 //---------------------------------------------------------------------------------------------------------------------
116 {
117  setCurrentArcId(ui->comboBoxArc1, value);
118 
119  VisToolPointOfIntersectionArcs *point = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
120  SCASSERT(point != nullptr)
121  point->setArc1Id(value);
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
126 {
127  return getCurrentObjectId(ui->comboBoxArc2);
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
132 {
133  setCurrentArcId(ui->comboBoxArc2, value);
134 
135  VisToolPointOfIntersectionArcs *point = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
136  SCASSERT(point != nullptr)
137  point->setArc2Id(value);
138 }
139 
140 //---------------------------------------------------------------------------------------------------------------------
142 {
143  return getCurrentCrossPoint<CrossCirclesPoint>(ui->comboBoxResult);
144 }
145 
146 //---------------------------------------------------------------------------------------------------------------------
148 {
149  const qint32 index = ui->comboBoxResult->findData(static_cast<int>(p));
150  if (index != -1)
151  {
152  ui->comboBoxResult->setCurrentIndex(index);
153 
154  VisToolPointOfIntersectionArcs *point = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
155  SCASSERT(point != nullptr)
156  point->setCrossPoint(p);
157  }
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
162 {
163  if (prepare == false)// After first choose we ignore all objects
164  {
165  if (type == SceneObject::Arc)
166  {
167  VisToolPointOfIntersectionArcs *point = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
168  SCASSERT(point != nullptr)
169 
170  switch (number)
171  {
172  case 0:
173  if (SetObject(id, ui->comboBoxArc1, tr("Select second an arc")))
174  {
175  number++;
176  point->VisualMode(id);
177  }
178  break;
179  case 1:
180  if (getCurrentObjectId(ui->comboBoxArc1) != id)
181  {
182  if (SetObject(id, ui->comboBoxArc2, ""))
183  {
184  number = 0;
185  point->setArc2Id(id);
186  point->RefreshGeometry();
187  prepare = true;
188  DialogAccepted();
189  }
190  }
191  break;
192  default:
193  break;
194  }
195  }
196  }
197 }
198 
199 //---------------------------------------------------------------------------------------------------------------------
201 {
202  QColor color = okColor;
203  if (getCurrentObjectId(ui->comboBoxArc1) == getCurrentObjectId(ui->comboBoxArc2))
204  {
205  flagError = false;
206  color = errorColor;
207  }
208  else
209  {
210  flagError = true;
211  color = okColor;
212  }
213  ChangeColor(ui->labelArc1, color);
214  ChangeColor(ui->labelArc2, color);
215  CheckState();
216 }
217 
218 //---------------------------------------------------------------------------------------------------------------------
220 {
221  AddVisualization<VisToolPointOfIntersectionArcs>();
222 }
223 
224 //---------------------------------------------------------------------------------------------------------------------
226 {
227  pointName = ui->lineEditNamePoint->text();
228 
229  VisToolPointOfIntersectionArcs *point = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
230  SCASSERT(point != nullptr)
231 
232  point->setArc1Id(GetFirstArcId());
233  point->setArc2Id(GetSecondArcId());
235  point->RefreshGeometry();
236 }
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
Ui::DialogPointOfIntersectionArcs * ui
virtual ~DialogPointOfIntersectionArcs() Q_DECL_OVERRIDE
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
DialogPointOfIntersectionArcs(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
void SetCrossArcPoint(const CrossCirclesPoint &p)
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 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 FillComboBoxCrossCirclesPoints(QComboBox *box) const
Definition: dialogtool.cpp:373
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.
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
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
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
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
virtual void VisualMode(const quint32 &id) Q_DECL_OVERRIDE
void setCrossPoint(const CrossCirclesPoint &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
CrossCirclesPoint
#define qApp
Definition: vapplication.h:67