Seamly2D
Code documentation
anchorpoint_dialog.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 dialogpin.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 31 1, 2017
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) 2017 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 "anchorpoint_dialog.h"
53 #include "ui_anchorpoint_dialog.h"
55 #include "../../tools/vabstracttool.h"
56 #include "../../tools/pattern_piece_tool.h"
57 
58 //---------------------------------------------------------------------------------------------------------------------
59 AnchorPointDialog::AnchorPointDialog(const VContainer *data, quint32 toolId, QWidget *parent)
60  : DialogTool(data, toolId, parent)
61  , ui(new Ui::AnchorPointDialog)
62  , m_showMode(false)
63  , m_flagPoint(false)
64 {
65  ui->setupUi(this);
66  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
67  setWindowIcon(QIcon(":/toolicon/32x32/anchor_point.png"));
68 
70 
71  FillComboBoxPoints(ui->comboBoxPoint);
72 
73  flagError = false;
74  CheckState();
75 
76  connect(ui->comboBoxPiece, &QComboBox::currentTextChanged, this, [this](){ CheckPieces(); });
77 
78  vis = new AnchorPointVisual(data);
79 }
80 
81 //---------------------------------------------------------------------------------------------------------------------
83 {
84  delete ui;
85 }
86 
87 //---------------------------------------------------------------------------------------------------------------------
89 {
90  m_showMode = disable;
91  ui->comboBoxPiece->setDisabled(m_showMode);
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
96 {
97  return getCurrentObjectId(ui->comboBoxPiece);
98 }
99 
100 //---------------------------------------------------------------------------------------------------------------------
102 {
103  if (ui->comboBoxPiece->count() <= 0)
104  {
105  ui->comboBoxPiece->addItem(data->GetPiece(id).GetName(), id);
106  }
107  else
108  {
109  const qint32 index = ui->comboBoxPiece->findData(id);
110  if (index != -1)
111  {
112  ui->comboBoxPiece->setCurrentIndex(index);
113  }
114  else
115  {
116  ui->comboBoxPiece->setCurrentIndex(0);
117  }
118  }
119 }
120 
121 //---------------------------------------------------------------------------------------------------------------------
123 {
124  return getCurrentObjectId(ui->comboBoxPoint);
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
129 {
130  setCurrentPointId(ui->comboBoxPoint, id);
131 
132  AnchorPointVisual *point = qobject_cast<AnchorPointVisual *>(vis);
133  SCASSERT(point != nullptr)
134  point->setObject1Id(id);
135 
136  CheckPoint();
137 }
138 
139 //---------------------------------------------------------------------------------------------------------------------
141 {
142  FillComboBoxPiecesList(ui->comboBoxPiece, list);
143 }
144 
145 //---------------------------------------------------------------------------------------------------------------------
146 void AnchorPointDialog::ChosenObject(quint32 id, const SceneObject &type)
147 {
148  if (not prepare)
149  {
150  if (type == SceneObject::Point)
151  {
152  if (SetObject(id, ui->comboBoxPoint, ""))
153  {
154  vis->VisualMode(id);
155  CheckPoint();
156  prepare = true;
157  this->setModal(true);
158  this->show();
159  }
160  }
161  }
162 }
163 
164 //---------------------------------------------------------------------------------------------------------------------
166 {
167  SCASSERT(ok_Button != nullptr);
168  ok_Button->setEnabled(m_flagPoint && flagError);
169 }
170 
171 //---------------------------------------------------------------------------------------------------------------------
173 {
174  AddVisualization<AnchorPointVisual>();
175 
176  if (m_showMode)
177  {
178  PatternPieceTool *tool = qobject_cast<PatternPieceTool*>(VAbstractPattern::getTool(GetPieceId()));
179  SCASSERT(tool != nullptr);
180  auto visPoint = qobject_cast<AnchorPointVisual *>(vis);
181  SCASSERT(visPoint != nullptr);
182  visPoint->setParentItem(tool);
183  }
184 }
185 
186 //---------------------------------------------------------------------------------------------------------------------
188 {
189  if (not m_showMode)
190  {
191  QColor color = okColor;
192  if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1)
193  {
194  flagError = false;
195  color = errorColor;
196  }
197  else
198  {
199  flagError = true;
200  color = okColor;
201  }
202  ChangeColor(ui->labelPiece, color);
203  CheckState();
204  }
205 }
206 
207 //---------------------------------------------------------------------------------------------------------------------
209 {
210  QColor color = okColor;
211  if (ui->comboBoxPoint->currentIndex() != -1)
212  {
213  m_flagPoint = true;
214  color = okColor;
215  }
216  else
217  {
218  m_flagPoint = false;
219  color = errorColor;
220  }
221  ChangeColor(ui->labelPoint, color);
222  CheckState();
223 }
void SetPieceId(quint32 id)
Ui::AnchorPointDialog * ui
virtual void CheckState() Q_DECL_FINAL
CheckState enable, when all is correct, or disable, when something wrong, button ok.
virtual void SetPiecesList(const QVector< quint32 > &list) Q_DECL_OVERRIDE
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
void SetPointId(quint32 id)
quint32 GetPointId() const
void EnbleShowMode(bool disable)
quint32 GetPieceId() const
virtual void ShowVisualization() Q_DECL_OVERRIDE
AnchorPointDialog(const VContainer *data, quint32 toolId, QWidget *parent=nullptr)
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule=FillComboBox::NoChildren, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
Definition: dialogtool.cpp:896
const QColor okColor
Definition: dialogtool.h:219
void FillComboBoxPoints(QComboBox *box, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
FillComboBoxPoints fill comboBox list of points.
Definition: dialogtool.cpp:242
QPushButton * ok_Button
ok_Button button ok
Definition: dialogtool.h:199
void initializeOkCancel(T *ui)
initializeOkCancel initialize OK and Cancel buttons
Definition: dialogtool.h:379
const QColor errorColor
Definition: dialogtool.h:220
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
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 FillComboBoxPiecesList(QComboBox *box, const QVector< quint32 > &list)
Definition: dialogtool.cpp:224
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
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
QString GetName() const
The VContainer class container of all variables.
Definition: vcontainer.h:141
VPiece GetPiece(quint32 id) const
Definition: vcontainer.cpp:185
void setObject1Id(const quint32 &value)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103