Seamly2D
Code documentation
seamlymepreferencesconfigurationpage.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 seamlymepreferencesconfigurationpage.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 4, 2017
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentina project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2017 Valentina project
35  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
36  **
37  ** Valentina 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  ** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
53 #include "ui_seamlymepreferencesconfigurationpage.h"
54 #include "../../mapplication.h"
55 #include "../vmisc/vseamlymesettings.h"
56 #include "../vpatterndb/variables/vmeasurement.h"
57 #include "../vpatterndb/pmsystems.h"
58 
59 //---------------------------------------------------------------------------------------------------------------------
61  : QWidget(parent)
63  , m_langChanged(false)
64  , m_systemChanged(false)
65  , m_defGradationChanged(false)
66 {
67  ui->setupUi(this);
68 
69  InitLanguages(ui->langCombo);
70  connect(ui->langCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
71  {
72  m_langChanged = true;
73  });
74 
75  //-------------------- Decimal separator setup
76  ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint()));
77  ui->osOptionCheck->setChecked(qApp->SeamlyMeSettings()->GetOsSeparator());
78 
79  //---------------------- Pattern making system
80  InitPMSystems(ui->systemCombo);
81  ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing());
82  connect(ui->systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
83  {
84  m_systemChanged = true;
85  QString text = qApp->TrVars()->PMSystemAuthor(ui->systemCombo->currentData().toString());
86  ui->systemAuthorValueLabel->setText(text);
87  ui->systemAuthorValueLabel->setToolTip(text);
88 
89  text = qApp->TrVars()->PMSystemBook(ui->systemCombo->currentData().toString());
90  ui->systemBookValueLabel->setPlainText(text);
91  });
92 
93  // set default pattern making system
94  int index = ui->systemCombo->findData(qApp->SeamlyMeSettings()->GetPMSystemCode());
95  if (index != -1)
96  {
97  ui->systemCombo->setCurrentIndex(index);
98  }
99 
100  //----------------------------- Measurements Editing
101  connect(ui->resetWarningsButton, &QPushButton::released, []()
102  {
103  VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
104 
105  settings->setConfirmFormatRewriting(true);
106  });
107 
108  //----------------------- Toolbar
109  ui->toolBarStyle_CheckBox->setChecked(qApp->SeamlyMeSettings()->getToolBarStyle());
110 
111  //---------------------------Default height and size
112  ui->defHeightCombo->addItems(VMeasurement::WholeListHeights(Unit::Cm));
113  index = ui->defHeightCombo->findText(QString().setNum(qApp->SeamlyMeSettings()->GetDefHeight()));
114  if (index != -1)
115  {
116  ui->defHeightCombo->setCurrentIndex(index);
117  }
118 
119  auto DefGradationChanged = [this]()
120  {
121  m_defGradationChanged = true;
122  };
123 
124  connect(ui->defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
125  DefGradationChanged);
126 
127  ui->defSizeCombo->addItems(VMeasurement::WholeListSizes(Unit::Cm));
128  index = ui->defSizeCombo->findText(QString().setNum(qApp->SeamlyMeSettings()->GetDefSize()));
129  if (index != -1)
130  {
131  ui->defSizeCombo->setCurrentIndex(index);
132  }
133  connect(ui->defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
134  DefGradationChanged);
135 }
136 
137 //---------------------------------------------------------------------------------------------------------------------
139 {
140  delete ui;
141 }
142 
143 //---------------------------------------------------------------------------------------------------------------------
145 {
146  VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
147  settings->SetOsSeparator(ui->osOptionCheck->isChecked());
148 
149  settings->setToolBarStyle(ui->toolBarStyle_CheckBox->isChecked());
150 
152  {
153  const QString locale = qvariant_cast<QString>(ui->langCombo->currentData());
154  settings->SetLocale(locale);
155  m_langChanged = false;
156 
157  const QString code = qvariant_cast<QString>(ui->systemCombo->currentData());
158  settings->SetPMSystemCode(code);
159  m_systemChanged = false;
160 
161  qApp->loadTranslations(locale);
162  qApp->processEvents();// force to call changeEvent
163 
164  // Part about measurments will not be updated automatically
165  qApp->RetranslateTables();
166  qApp->retranslateGroups();
167  }
168 
170  {
171  settings->SetDefHeight(ui->defHeightCombo->currentText().toInt());
172  settings->SetDefSize(ui->defSizeCombo->currentText().toInt());
173  m_defGradationChanged = false;
174  }
175 }
176 
177 //---------------------------------------------------------------------------------------------------------------------
179 {
180  if (event->type() == QEvent::LanguageChange)
181  {
182  // retranslate designer form (single inheritance approach)
183  RetranslateUi();
184  }
185  // remember to call base class implementation
186  QWidget::changeEvent(event);
187 }
188 
189 //---------------------------------------------------------------------------------------------------------------------
191 {
192  ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint()));
193 }
Ui::SeamlyMePreferencesConfigurationPage * ui
virtual void changeEvent(QEvent *event) Q_DECL_OVERRIDE
void SetPMSystemCode(const QString &value)
void setToolBarStyle(const bool &value)
void SetOsSeparator(const bool &value)
void SetLocale(const QString &value)
static QStringList WholeListSizes(Unit patternUnit)
static QStringList WholeListHeights(Unit patternUnit)
void SetDefHeight(int value)
void SetDefSize(int value)
void InitLanguages(QComboBox *combobox)
Definition: def.cpp:725
void InitPMSystems(QComboBox *systemCombo)
Definition: pmsystems.cpp:181
#define qApp
Definition: vapplication.h:67