-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
seamlymepreferencesconfigurationpage.cpp
193 lines (168 loc) · 7.83 KB
/
seamlymepreferencesconfigurationpage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/***************************************************************************
* *
* Copyright (C) 2017 Seamly, LLC *
* *
* https://github.com/fashionfreedom/seamly2d *
* *
***************************************************************************
**
** Seamly2D is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Seamly2D is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************
************************************************************************
**
** @file seamlymepreferencesconfigurationpage.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 4, 2017
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 Seamly2D project
** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
**
** Seamly2D is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Seamly2D is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "seamlymepreferencesconfigurationpage.h"
#include "ui_seamlymepreferencesconfigurationpage.h"
#include "../../mapplication.h"
#include "../vmisc/vseamlymesettings.h"
#include "../vpatterndb/variables/vmeasurement.h"
#include "../vpatterndb/pmsystems.h"
//---------------------------------------------------------------------------------------------------------------------
SeamlyMePreferencesConfigurationPage::SeamlyMePreferencesConfigurationPage(QWidget *parent)
: QWidget(parent),
ui(new Ui::SeamlyMePreferencesConfigurationPage),
m_langChanged(false),
m_systemChanged(false),
m_defGradationChanged(false)
{
ui->setupUi(this);
InitLanguages(ui->langCombo);
connect(ui->langCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
{
m_langChanged = true;
});
//-------------------- Decimal separator setup
ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint()));
ui->osOptionCheck->setChecked(qApp->SeamlyMeSettings()->GetOsSeparator());
//---------------------- Pattern making system
InitPMSystems(ui->systemCombo);
ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing());
connect(ui->systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this]()
{
m_systemChanged = true;
QString text = qApp->TrVars()->PMSystemAuthor(ui->systemCombo->currentData().toString());
ui->systemAuthorValueLabel->setText(text);
ui->systemAuthorValueLabel->setToolTip(text);
text = qApp->TrVars()->PMSystemBook(ui->systemCombo->currentData().toString());
ui->systemBookValueLabel->setPlainText(text);
});
// set default pattern making system
int index = ui->systemCombo->findData(qApp->SeamlyMeSettings()->GetPMSystemCode());
if (index != -1)
{
ui->systemCombo->setCurrentIndex(index);
}
//----------------------------- Measurements Editing
connect(ui->resetWarningsButton, &QPushButton::released, []()
{
VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
settings->SetConfirmFormatRewriting(true);
});
//----------------------- Toolbar
ui->toolBarStyle_CheckBox->setChecked(qApp->SeamlyMeSettings()->getToolBarStyle());
//---------------------------Default height and size
ui->defHeightCombo->addItems(VMeasurement::WholeListHeights(Unit::Cm));
index = ui->defHeightCombo->findText(QString().setNum(qApp->SeamlyMeSettings()->GetDefHeight()));
if (index != -1)
{
ui->defHeightCombo->setCurrentIndex(index);
}
auto DefGradationChanged = [this]()
{
m_defGradationChanged = true;
};
connect(ui->defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
DefGradationChanged);
ui->defSizeCombo->addItems(VMeasurement::WholeListSizes(Unit::Cm));
index = ui->defSizeCombo->findText(QString().setNum(qApp->SeamlyMeSettings()->GetDefSize()));
if (index != -1)
{
ui->defSizeCombo->setCurrentIndex(index);
}
connect(ui->defHeightCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
DefGradationChanged);
}
//---------------------------------------------------------------------------------------------------------------------
SeamlyMePreferencesConfigurationPage::~SeamlyMePreferencesConfigurationPage()
{
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
void SeamlyMePreferencesConfigurationPage::Apply()
{
VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
settings->SetOsSeparator(ui->osOptionCheck->isChecked());
settings->setToolBarStyle(ui->toolBarStyle_CheckBox->isChecked());
if (m_langChanged || m_systemChanged)
{
const QString locale = qvariant_cast<QString>(ui->langCombo->currentData());
settings->SetLocale(locale);
m_langChanged = false;
const QString code = qvariant_cast<QString>(ui->systemCombo->currentData());
settings->SetPMSystemCode(code);
m_systemChanged = false;
qApp->LoadTranslation(locale);
qApp->processEvents();// force to call changeEvent
// Part about measurments will not be updated automatically
qApp->RetranslateTables();
qApp->retranslateGroups();
}
if (m_defGradationChanged)
{
settings->SetDefHeight(ui->defHeightCombo->currentText().toInt());
settings->SetDefSize(ui->defSizeCombo->currentText().toInt());
m_defGradationChanged = false;
}
}
//---------------------------------------------------------------------------------------------------------------------
void SeamlyMePreferencesConfigurationPage::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
{
// retranslate designer form (single inheritance approach)
RetranslateUi();
}
// remember to call base class implementation
QWidget::changeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void SeamlyMePreferencesConfigurationPage::RetranslateUi()
{
ui->osOptionCheck->setText(tr("With OS options") + QString(" (%1)").arg(QLocale().decimalPoint()));
}