Seamly2D
Code documentation
preferencesconfigurationpage.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 preferencesconfigurationpage.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 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 
53 #include "ui_preferencesconfigurationpage.h"
54 #include "../../core/vapplication.h"
55 #include "../vpatterndb/pmsystems.h"
56 #include "../vwidgets/export_format_combobox.h"
57 
58 #include <QDir>
59 #include <QDirIterator>
60 #include <QMessageBox>
61 #include <QSound>
62 #include <QTimer>
63 
64 //---------------------------------------------------------------------------------------------------------------------
66  : QWidget(parent)
68  , m_langChanged(false)
69  , m_systemChanged()
70  , m_unitChanged(false)
71  , m_labelLangChanged(false)
72  , m_selectionSoundChanged(false)
73  , m_moveSuffixChanged(false)
74  , m_rotateSuffixChanged(false)
75  , m_mirrorByAxisSuffixChanged(false)
76  , m_mirrorByLineSuffixChanged(false)
77  , m_defaultExportFormatChanged(false)
78 {
79  ui->setupUi(this);
80  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
81 
82  //Editing
83  // Undo
84  ui->undoCount_SpinBox->setValue(qApp->Seamly2DSettings()->GetUndoCount());
85 
86  //Selection sound
87  int index = ui->selectionSound_ComboBox->findText(qApp->Seamly2DSettings()->getSound());
88  if (index != -1)
89  {
90  ui->selectionSound_ComboBox->setCurrentIndex(index);
91  }
92  connect(ui->selectionSound_ComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
93  {
94  m_selectionSoundChanged = true;
95  QSound::play("qrc:/sounds/" + ui->selectionSound_ComboBox->currentText() + ".wav");
96  });
97 
98  // Warnings
99  ui->confirmItemDelete_CheckBox->setChecked(qApp->Seamly2DSettings()->getConfirmItemDelete());
100  ui->confirmFormatRewriting_CheckBox->setChecked(qApp->Seamly2DSettings()->getConfirmFormatRewriting());
101  // Send crash reports
102  //ui->sendReportCheck->setChecked(qApp->Seamly2DSettings()->GetSendReportState());
103  //ui->description = new QLabel(tr("After each crash Seamly2D collects information that may help us fix the "
104  // "problem. We do not collect any personal information. Find more about what %1"
105  // "kind of information%2 we collect.")
106  // .arg("<a href=\"https://wiki.seamly.net/wiki/UserManual:Crash_reports\">")
107  // .arg("</a>"));
108 
109  // Pattern Making System
110  InitPMSystems(ui->systemCombo);
111  ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing());
112  connect(ui->systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
113  {
114  m_systemChanged = true;
115  QString text = qApp->TrVars()->PMSystemAuthor(ui->systemCombo->currentData().toString());
116  ui->systemAuthorValueLabel->setText(text);
117  ui->systemAuthorValueLabel->setToolTip(text);
118 
119  text = qApp->TrVars()->PMSystemBook(ui->systemCombo->currentData().toString());
120  ui->systemBookValueLabel->setPlainText(text);
121  });
122 
123  // set default pattern making system
124  index = ui->systemCombo->findData(qApp->Seamly2DSettings()->GetPMSystemCode());
125  if (index != -1)
126  {
127  ui->systemCombo->setCurrentIndex(index);
128  }
129 
130  // Default operations suffixes
131  ui->moveSuffix_ComboBox->addItem(tr("None"), "");
132  ui->moveSuffix_ComboBox->addItem(tr("_M"), "_M");
133  ui->moveSuffix_ComboBox->addItem(tr("_MOV"), "_MOV");
134  index = ui->moveSuffix_ComboBox->findData(qApp->Seamly2DSettings()->getMoveSuffix());
135  if (index != -1)
136  {
137  ui->moveSuffix_ComboBox->setCurrentIndex(index);
138  }
139  connect(ui->moveSuffix_ComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
140  {
141  m_moveSuffixChanged = true;
142  });
143  ui->rotateSuffix_ComboBox->addItem(tr("None"), "");
144  ui->rotateSuffix_ComboBox->addItem(tr("_R"), "_R");
145  ui->rotateSuffix_ComboBox->addItem(tr("_ROT"), "_ROT");
146  index = ui->rotateSuffix_ComboBox->findData(qApp->Seamly2DSettings()->getRotateSuffix());
147  if (index != -1)
148  {
149  ui->rotateSuffix_ComboBox->setCurrentIndex(index);
150  }
151  connect(ui->rotateSuffix_ComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
152  {
153  m_rotateSuffixChanged = true;
154  });
155 
156  ui->mirrorByAxisSuffix_ComboBox->addItem(tr("None"), "");
157  ui->mirrorByAxisSuffix_ComboBox->addItem(tr("_MA"), "_MA");
158  ui->mirrorByAxisSuffix_ComboBox->addItem(tr("_MBA"), "_MBA");
159  index = ui->mirrorByAxisSuffix_ComboBox->findData(qApp->Seamly2DSettings()->getMirrorByAxisSuffix());
160  if (index != -1)
161  {
162  ui->mirrorByAxisSuffix_ComboBox->setCurrentIndex(index);
163  }
164  connect(ui->mirrorByAxisSuffix_ComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
165  {
166  m_mirrorByAxisSuffixChanged = true;
167  });
168 
169  ui->mirrorByLineSuffix_ComboBox->addItem(tr("None"), "");
170  ui->mirrorByLineSuffix_ComboBox->addItem(tr("_MB"), "_MB");
171  ui->mirrorByLineSuffix_ComboBox->addItem(tr("_MBL"), "_MBL");
172  index = ui->mirrorByLineSuffix_ComboBox->findData(qApp->Seamly2DSettings()->getMirrorByLineSuffix());
173  if (index != -1)
174  {
175  ui->mirrorByLineSuffix_ComboBox->setCurrentIndex(index);
176  }
177  connect(ui->mirrorByLineSuffix_ComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
178  {
179  m_mirrorByLineSuffixChanged = true;
180  });
181 
182  // File handling
183  // Autosave
184  ui->autoSave_CheckBox->setChecked(qApp->Seamly2DSettings()->GetAutosaveState());
185  ui->autoInterval_Spinbox->setValue(qApp->Seamly2DSettings()->getAutosaveInterval());
186 
187  // Export Format
188  ui->useModeType_CheckBox->setChecked(qApp->Seamly2DSettings()->useModeType());
189  ui->uselastExportFormat_CheckBox->setChecked(qApp->Seamly2DSettings()->useLastExportFormat());
190  index = ui->defaultExportFormat_ComboBox->findText(qApp->Seamly2DSettings()->getExportFormat());
191  if (index != -1)
192  {
193  ui->defaultExportFormat_ComboBox->setCurrentIndex(index);
194  }
195  connect(ui->defaultExportFormat_ComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
196  {
197  m_defaultExportFormatChanged = true;
198  });
199 
200  // Language
201  InitLanguages(ui->langCombo);
202  connect(ui->langCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
203  {
204  m_langChanged = true;
205  });
206 
207  // Decimal separator setup
208  ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint()));
209  ui->osOptionCheck->setChecked(qApp->Seamly2DSettings()->GetOsSeparator());
210 
211  // Unit setup
212  InitUnits();
213  connect(ui->unitCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
214  {
215  m_unitChanged = true;
216  });
218 
219  index = ui->labelCombo->findData(qApp->Seamly2DSettings()->GetLabelLanguage());
220  if (index != -1)
221  {
222  ui->labelCombo->setCurrentIndex(index);
223  }
224  connect(ui->labelCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
225  {
226  m_labelLangChanged = true;
227  });
228 }
229 
230 //---------------------------------------------------------------------------------------------------------------------
232 {
233  delete ui;
234 }
235 
236 //---------------------------------------------------------------------------------------------------------------------
238 {
239  VSettings *settings = qApp->Seamly2DSettings();
240  /* Maximum number of commands in undo stack may only be set when the undo stack is empty, since setting it on a
241  * non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack
242  * prints a warning and does nothing.*/
243  settings->SetUndoCount(ui->undoCount_SpinBox->value());
245  {
246  const QString locale = qvariant_cast<QString>(ui->selectionSound_ComboBox->currentText());
247  settings->setSelectionSound(locale);
248  m_selectionSoundChanged = false;
249  }
250  settings->setConfirmItemDelete(ui->confirmItemDelete_CheckBox->isChecked());
251  settings->setConfirmFormatRewriting(ui->confirmFormatRewriting_CheckBox->isChecked());
252 
253  settings->SetAutosaveState(ui->autoSave_CheckBox->isChecked());
254  settings->setAutosaveInterval(ui->autoInterval_Spinbox->value());
255 
256  QTimer *autoSaveTimer = qApp->getAutoSaveTimer();
257  SCASSERT(autoSaveTimer)
258 
259  ui->autoSave_CheckBox->isChecked() ? autoSaveTimer->start(ui->autoInterval_Spinbox->value()*60000) : autoSaveTimer->stop();
260 
261  settings->setUseModeType(ui->useModeType_CheckBox->isChecked());
262  settings->setUseLastExportFormat(ui->uselastExportFormat_CheckBox->isChecked());
264  {
265  const QString format = qvariant_cast<QString>(ui->defaultExportFormat_ComboBox->currentText());
266  settings->setExportFormat(format);
268  }
269 
270  settings->SetOsSeparator(ui->osOptionCheck->isChecked());
271  //settings->SetSendReportState(ui->sendReportCheck->isChecked());
272 
274  {
275  const QString locale = qvariant_cast<QString>(ui->langCombo->currentData());
276  settings->SetLocale(locale);
277  m_langChanged = false;
278 
279  const QString code = qvariant_cast<QString>(ui->systemCombo->currentData());
280  settings->SetPMSystemCode(code);
281  m_systemChanged = false;
282 
283  qApp->loadTranslations(locale);
284  }
285  if (m_unitChanged)
286  {
287  const QString unit = qvariant_cast<QString>(ui->unitCombo->currentData());
288  settings->SetUnit(unit);
289  m_unitChanged = false;
290  const QString text = tr("The Default unit has been updated and will be used as the default for the next "
291  "pattern you create.");
292  QMessageBox::information(this, QCoreApplication::applicationName(), text);
293  }
294  if (m_labelLangChanged)
295  {
296  const QString locale = qvariant_cast<QString>(ui->labelCombo->currentData());
297  settings->SetLabelLanguage(locale);
298  m_labelLangChanged = false;
299  }
301  {
302  const QString locale = qvariant_cast<QString>(ui->moveSuffix_ComboBox->currentData());
303  settings->setMoveSuffix(locale);
304  m_moveSuffixChanged = false;
305  }
307  {
308  const QString locale = qvariant_cast<QString>(ui->rotateSuffix_ComboBox->currentData());
309  settings->setRotateSuffix(locale);
310  m_rotateSuffixChanged = false;
311  }
313  {
314  const QString locale = qvariant_cast<QString>(ui->mirrorByAxisSuffix_ComboBox->currentData());
315  settings->setMirrorByAxisSuffix(locale);
317  }
319  {
320  const QString locale = qvariant_cast<QString>(ui->mirrorByLineSuffix_ComboBox->currentData());
321  settings->setMirrorByLineSuffix(locale);
323  }
324 }
325 
326 //---------------------------------------------------------------------------------------------------------------------
328 {
329  if (event->type() == QEvent::LanguageChange)
330  {
331  // retranslate designer form (single inheritance approach)
332  RetranslateUi();
333  }
334  // remember to call base class implementation
335  QWidget::changeEvent(event);
336 }
337 
338 //---------------------------------------------------------------------------------------------------------------------
340 {
341  for (int i = 0; i < list.size(); ++i)
342  {
343  QLocale loc = QLocale(list.at(i));
344  QString country = QLocale::countryToString(loc.country());
345  QIcon ico(QString("%1/%2.png").arg(":/flags").arg(country));
346  ui->labelCombo->addItem(ico, loc.nativeLanguageName(), list.at(i));
347  }
348 }
349 
350 //---------------------------------------------------------------------------------------------------------------------
352 {
353  ui->unitCombo->addItem(tr("Centimeters"), unitCM);
354  ui->unitCombo->addItem(tr("Millimeters"), unitMM);
355  ui->unitCombo->addItem(tr("Inches"), unitINCH);
356 
357  // set default unit
358  const qint32 indexUnit = ui->unitCombo->findData(qApp->Seamly2DSettings()->GetUnit());
359  if (indexUnit != -1)
360  {
361  ui->unitCombo->setCurrentIndex(indexUnit);
362  }
363 }
364 
365 //---------------------------------------------------------------------------------------------------------------------
367 {
368  ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint()));
369  //ui->description->setText(tr("After each crash Seamly2D collects information that may help us fix the "
370  // "problem. We do not collect any personal information. Find more about what %1"
371  // "kind of information%2 we collect.")
372  // .arg("<a href=\"https://wiki.seamly.net/wiki/UserManual:Crash_reports\">")
373  // .arg("</a>"));
374 }
PreferencesConfigurationPage(QWidget *parent=nullptr)
void SetLabelComboBox(const QStringList &list)
Ui::PreferencesConfigurationPage * ui
virtual void changeEvent(QEvent *event) Q_DECL_OVERRIDE
static QStringList LabelLanguages()
void setRotateSuffix(const QString &value)
void SetUndoCount(const int &value)
void setMirrorByAxisSuffix(const QString &value)
void SetPMSystemCode(const QString &value)
void setUseLastExportFormat(const bool &value)
void setAutosaveInterval(const int &value)
void setConfirmFormatRewriting(const bool &value)
void setExportFormat(const QString &value)
void setConfirmItemDelete(const bool &value)
void SetUnit(const QString &value)
void SetOsSeparator(const bool &value)
void setMirrorByLineSuffix(const QString &value)
void setMoveSuffix(const QString &value)
void setSelectionSound(const QString &value)
void setUseModeType(const bool &value)
void SetAutosaveState(const bool &value)
void SetLocale(const QString &value)
void SetLabelLanguage(const QString &value)
Definition: vsettings.cpp:128
const QString unitMM
Definition: def.cpp:200
const QString unitCM
Definition: def.cpp:201
void InitLanguages(QComboBox *combobox)
Definition: def.cpp:725
const QString unitINCH
Definition: def.cpp:202
#define SCASSERT(cond)
Definition: def.h:317
void InitPMSystems(QComboBox *systemCombo)
Definition: pmsystems.cpp:181
#define qApp
Definition: vapplication.h:67