Seamly2D
Code documentation
dialognewmeasurements.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 dialognewmeasurements.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 7, 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 
52 #include "dialognewmeasurements.h"
53 #include "ui_dialognewmeasurements.h"
54 
55 #include "../vpatterndb/variables/vmeasurement.h"
56 #include "../vmisc/vseamlymesettings.h"
57 #include "../mapplication.h"
58 
59 #include <QShowEvent>
60 
61 //---------------------------------------------------------------------------------------------------------------------
63  :QDialog(parent),
64  ui(new Ui::DialogNewMeasurements),
65  isInitialized(false)
66 {
67  ui->setupUi(this);
68 
69  InitMTypes();
72  InitSizesList();
73 
74  const VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
75 
76  const int height = static_cast<int>(UnitConvertor(settings->GetDefHeight(), Unit::Cm, MUnit()));
77  int index = ui->comboBoxBaseHeight->findText(QString().setNum(height));
78  if (index != -1)
79  {
80  ui->comboBoxBaseHeight->setCurrentIndex(index);
81  }
82 
83  const int size = static_cast<int>(UnitConvertor(settings->GetDefSize(), Unit::Cm, MUnit()));
84  index = ui->comboBoxBaseSize->findText(QString().setNum(size));
85  if (index != -1)
86  {
87  ui->comboBoxBaseSize->setCurrentIndex(index);
88  }
89 
90  connect(ui->comboBoxMType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
92 
93  connect(ui->comboBoxUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
95 }
96 
97 //---------------------------------------------------------------------------------------------------------------------
99 {
100  delete ui;
101 }
102 
103 //---------------------------------------------------------------------------------------------------------------------
105 {
106  return static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt());
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {
112  return static_cast<Unit>(ui->comboBoxUnit->currentData().toInt());
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
117 {
118  return ui->comboBoxBaseSize->currentText().toInt();
119 }
120 
121 //---------------------------------------------------------------------------------------------------------------------
123 {
124  return ui->comboBoxBaseHeight->currentText().toInt();
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
129 {
130  if (event->type() == QEvent::LanguageChange)
131  {
132  // retranslate designer form (single inheritance approach)
133  ui->retranslateUi(this);
134  InitMTypes();
135  InitUnits(static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt()));
136  }
137 
138  // remember to call base class implementation
139  QDialog::changeEvent(event);
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
143 void DialogNewMeasurements::showEvent(QShowEvent *event)
144 {
145  QDialog::showEvent( event );
146  if ( event->spontaneous() )
147  {
148  return;
149  }
150 
151  if (isInitialized)
152  {
153  return;
154  }
155  // do your init stuff here
156 
157  setMaximumSize(size());
158  setMinimumSize(size());
159 
160  isInitialized = true;//first show windows are held
161 }
162 
163 //---------------------------------------------------------------------------------------------------------------------
165 {
166  const MeasurementsType type = static_cast<MeasurementsType>(ui->comboBoxMType->itemData(index).toInt());
167  if (type == MeasurementsType::Multisize)
168  {
169  ui->comboBoxBaseSize->setEnabled(true);
170  ui->comboBoxBaseHeight->setEnabled(true);
171  }
172  else
173  {
174  ui->comboBoxBaseSize->setEnabled(false);
175  ui->comboBoxBaseHeight->setEnabled(false);
176  }
177  InitUnits(type);
178 }
179 
180 //---------------------------------------------------------------------------------------------------------------------
182 {
183  Q_UNUSED(index)
184 
185  if (MUnit() != Unit::Inch)
186  {
187  int i = ui->comboBoxBaseHeight->currentIndex();
188  InitHeightsList();
189  ui->comboBoxBaseHeight->setCurrentIndex(i);
190 
191  i = ui->comboBoxBaseSize->currentIndex();
192  InitSizesList();
193  ui->comboBoxBaseSize->setCurrentIndex(i);
194  }
195 }
196 
197 //---------------------------------------------------------------------------------------------------------------------
199 {
200  int val = static_cast<int>(MeasurementsType::Unknown);
201  if (ui->comboBoxMType->currentIndex() != -1)
202  {
203  val = ui->comboBoxMType->currentData().toInt();
204  }
205 
206  ui->comboBoxMType->blockSignals(true);
207  ui->comboBoxMType->clear();
208  ui->comboBoxMType->addItem(tr("Individual"), static_cast<int>(MeasurementsType::Individual));
209  ui->comboBoxMType->addItem(tr("Multisize"), static_cast<int>(MeasurementsType::Multisize));
210  ui->comboBoxMType->blockSignals(false);
211 
212  int index = ui->comboBoxMType->findData(val);
213  if (index != -1)
214  {
215  ui->comboBoxMType->setCurrentIndex(index);
216  }
217 }
218 
219 //---------------------------------------------------------------------------------------------------------------------
221 {
222  const QStringList list = VMeasurement::WholeListHeights(MUnit());
223  ui->comboBoxBaseHeight->clear();
224  ui->comboBoxBaseHeight->addItems(list);
225 }
226 
227 //---------------------------------------------------------------------------------------------------------------------
229 {
230  const QStringList list = VMeasurement::WholeListSizes(MUnit());
231  ui->comboBoxBaseSize->clear();
232  ui->comboBoxBaseSize->addItems(list);
233 }
234 
235 //---------------------------------------------------------------------------------------------------------------------
237 {
238  int val = static_cast<int>(Unit::Cm);
239  if (ui->comboBoxUnit->currentIndex() != -1)
240  {
241  val = ui->comboBoxUnit->currentData().toInt();
242  }
243 
244  ui->comboBoxUnit->blockSignals(true);
245  ui->comboBoxUnit->clear();
246  ui->comboBoxUnit->addItem(tr("Centimeters"), static_cast<int>(Unit::Cm));
247  ui->comboBoxUnit->addItem(tr("Millimeters"), static_cast<int>(Unit::Mm));
248  if (type == MeasurementsType::Individual)
249  {
250  ui->comboBoxUnit->addItem(tr("Inches"), static_cast<int>(Unit::Inch));
251  }
252  ui->comboBoxUnit->setCurrentIndex(-1);
253  ui->comboBoxUnit->blockSignals(false);
254 
255  int index = ui->comboBoxUnit->findData(val);
256  if (index != -1)
257  {
258  ui->comboBoxUnit->setCurrentIndex(index);
259  }
260  else
261  {
262  index = ui->comboBoxUnit->findData(static_cast<int>(Unit::Cm));
263  ui->comboBoxUnit->setCurrentIndex(index);
264  }
265 }
Ui::DialogNewMeasurements * ui
MeasurementsType Type() const
virtual void changeEvent(QEvent *event) Q_DECL_OVERRIDE
DialogNewMeasurements(QWidget *parent=nullptr)
void InitUnits(const MeasurementsType &type)
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
static QStringList WholeListSizes(Unit patternUnit)
static QStringList WholeListHeights(Unit patternUnit)
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
Definition: def.cpp:269
MeasurementsType
Definition: def.h:104
Unit
Definition: def.h:105
#define qApp
Definition: vapplication.h:67