All Classes Namespaces Functions Variables Enumerations Properties Pages
generalpage.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "generalpage.h"
19 
20 #include <QMessageBox>
21 #include <QSettings>
22 
23 #include "pencildef.h"
24 #include "preferencemanager.h"
25 
26 #include "ui_generalpage.h"
27 
28 GeneralPage::GeneralPage() : ui(new Ui::GeneralPage)
29 {
30  ui->setupUi(this);
31 
32  QSettings settings(PENCIL2D, PENCIL2D);
33 
34  QString languages [][3]
35  {
36  // translatable string, endonym, locale code
37  { tr("Arabic"), QStringLiteral("العربية"), "ar" },
38  { tr("Catalan"), QStringLiteral("Català"), "ca" },
39  { tr("Czech"), QStringLiteral("Čeština"), "cs" },
40  { tr("Danish"), QStringLiteral("Dansk"), "da" },
41  { tr("German"), QStringLiteral("Deutsch"), "de" },
42  { tr("Greek"), QStringLiteral("Ελληνικά"), "el" },
43  { tr("English"), QStringLiteral("English"), "en" },
44  { tr("Spanish"), QStringLiteral("Español"), "es" },
45  { tr("Estonian"), QStringLiteral("Eesti"), "et" },
46  { tr("French"), QStringLiteral("Français"), "fr" },
47  { tr("Hebrew"), QStringLiteral("עברית"), "he" },
48  { tr("Hungarian"), QStringLiteral("Magyar"), "hu_HU" },
49  { tr("Indonesian"), QStringLiteral("Bahasa Indonesia"), "id" },
50  { tr("Italian"), QStringLiteral("Italiano"), "it" },
51  { tr("Japanese"), QStringLiteral("日本語"), "ja" },
52  { tr("Kabyle"), QStringLiteral("Taqbaylit"), "kab" },
53  { tr("Polish"), QStringLiteral("Polski"), "pl" },
54  { tr("Portuguese \u2013 Portugal"), QStringLiteral("Português \u2013 Portugal"), "pt_PT" },
55  { tr("Portuguese \u2013 Brazil"), QStringLiteral("Português \u2013 Brasil"), "pt_BR" },
56  { tr("Russian"), QStringLiteral("Русский"), "ru" },
57  { tr("Slovene"), QStringLiteral("Slovenščina"), "sl" },
58  { tr("Swedish"), QStringLiteral("Svenska"), "sv" },
59  { tr("Turkish"), QStringLiteral("Türkçe"), "tr" },
60  { tr("Vietnamese"), QStringLiteral("Tiếng Việt"), "vi" },
61  { tr("Chinese \u2013 China"), QStringLiteral("简体中文"), "zh_CN" },
62  { tr("Chinese \u2013 Taiwan"), QStringLiteral("繁體中文"), "zh_TW" },
63  };
64 
65  for (auto& lang : languages)
66  {
67  const QString itemText = QStringLiteral("%1 (%2)").arg(lang[0]).arg(lang[1]);
68  const QString localeCode = lang[2];
69  ui->languageCombo->addItem(itemText, localeCode);
70  }
71 
72  int value = settings.value("windowOpacity").toInt();
73  ui->windowOpacityLevel->setValue(100 - value);
74 
75  QPixmap previewCheckerboard(":background/checkerboard.png");
76  QPixmap previewWhite(32, 32);
77  QPixmap previewGrey(32, 32);
78  QPixmap previewDots(":background/dots.png");
79  QPixmap previewWeave(":background/weave.jpg");
80 
81  previewWhite.fill(Qt::white);
82  previewGrey.fill(Qt::lightGray);
83 
84  ui->checkerBackgroundButton->setIcon(previewCheckerboard.scaled(32, 32));
85  ui->whiteBackgroundButton->setIcon(previewWhite);
86  ui->greyBackgroundButton->setIcon(previewGrey);
87  ui->dotsBackgroundButton->setIcon(previewDots.scaled(32, 32));
88  ui->weaveBackgroundButton->setIcon(previewWeave.scaled(32, 32));
89  ui->backgroundButtons->setId(ui->checkerBackgroundButton, 1);
90  ui->backgroundButtons->setId(ui->whiteBackgroundButton, 2);
91  ui->backgroundButtons->setId(ui->greyBackgroundButton, 3);
92  ui->backgroundButtons->setId(ui->dotsBackgroundButton, 4);
93  ui->backgroundButtons->setId(ui->weaveBackgroundButton, 5);
94 
95  auto buttonClicked = static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked);
96  auto curIndexChanged = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
97  auto spinValueChanged = static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged);
98  connect(ui->languageCombo, curIndexChanged, this, &GeneralPage::languageChanged);
99  connect(ui->windowOpacityLevel, &QSlider::valueChanged, this, &GeneralPage::windowOpacityChange);
100  connect(ui->backgroundButtons, buttonClicked, this, &GeneralPage::backgroundChanged);
101  connect(ui->shadowsBox, &QCheckBox::stateChanged, this, &GeneralPage::shadowsCheckboxStateChanged);
102  connect(ui->toolCursorsBox, &QCheckBox::stateChanged, this, &GeneralPage::toolCursorsCheckboxStateChanged);
103  connect(ui->antialiasingBox, &QCheckBox::stateChanged, this, &GeneralPage::antiAliasCheckboxStateChanged);
104  connect(ui->curveSmoothingLevel, &QSlider::valueChanged, this, &GeneralPage::curveSmoothingChanged);
105  connect(ui->highResBox, &QCheckBox::stateChanged, this, &GeneralPage::highResCheckboxStateChanged);
106  connect(ui->dottedCursorBox, &QCheckBox::stateChanged, this, &GeneralPage::dottedCursorCheckboxStateChanged);
107  connect(ui->gridSizeInputW, spinValueChanged, this, &GeneralPage::gridWidthChanged);
108  connect(ui->gridSizeInputH, spinValueChanged, this, &GeneralPage::gridHeightChanged);
109  connect(ui->actionSafeCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::actionSafeCheckBoxStateChanged);
110  connect(ui->actionSafeInput, spinValueChanged, this, &GeneralPage::actionSafeAreaChanged);
111  connect(ui->titleSafeCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::titleSafeCheckBoxStateChanged);
112  connect(ui->titleSafeInput, spinValueChanged, this, &GeneralPage::titleSafeAreaChanged);
113  connect(ui->safeHelperTextCheckbox, &QCheckBox::stateChanged, this, &GeneralPage::SafeAreaHelperTextCheckBoxStateChanged);
114  connect(ui->gridCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::gridCheckBoxStateChanged);
115  connect(ui->framePoolSizeSpin, spinValueChanged, this, &GeneralPage::frameCacheNumberChanged);
116 }
117 
118 GeneralPage::~GeneralPage()
119 {
120  delete ui;
121 }
122 
123 void GeneralPage::updateValues()
124 {
125  int index = ui->languageCombo->findData(mManager->getString(SETTING::LANGUAGE));
126 
127  if (index >= 0)
128  {
129  QSignalBlocker b(ui->languageCombo);
130  ui->languageCombo->setCurrentIndex(index);
131  }
132 
133  QSignalBlocker b1(ui->curveSmoothingLevel);
134  ui->curveSmoothingLevel->setValue(mManager->getInt(SETTING::CURVE_SMOOTHING));
135  QSignalBlocker b2(ui->windowOpacityLevel);
136  ui->windowOpacityLevel->setValue(100 - mManager->getInt(SETTING::WINDOW_OPACITY));
137  QSignalBlocker b3(ui->shadowsBox);
138  ui->shadowsBox->setChecked(mManager->isOn(SETTING::SHADOW));
139  QSignalBlocker b4(ui->toolCursorsBox);
140  ui->toolCursorsBox->setChecked(mManager->isOn(SETTING::TOOL_CURSOR));
141  QSignalBlocker b5(ui->antialiasingBox);
142  ui->antialiasingBox->setChecked(mManager->isOn(SETTING::ANTIALIAS));
143  QSignalBlocker b6(ui->dottedCursorBox);
144  ui->dottedCursorBox->setChecked(mManager->isOn(SETTING::DOTTED_CURSOR));
145  QSignalBlocker b7(ui->gridSizeInputW);
146  ui->gridSizeInputW->setValue(mManager->getInt(SETTING::GRID_SIZE_W));
147  QSignalBlocker b11(ui->gridSizeInputH);
148  ui->gridSizeInputH->setValue(mManager->getInt(SETTING::GRID_SIZE_H));
149  QSignalBlocker b8(ui->gridCheckBox);
150  ui->gridCheckBox->setChecked(mManager->isOn(SETTING::GRID));
151  QSignalBlocker b16(ui->actionSafeCheckBox);
152 
153  bool actionSafeOn = mManager->isOn(SETTING::ACTION_SAFE_ON);
154  ui->actionSafeCheckBox->setChecked(actionSafeOn);
155  QSignalBlocker b14(ui->actionSafeInput);
156  ui->actionSafeInput->setValue(mManager->getInt(SETTING::ACTION_SAFE));
157  QSignalBlocker b17(ui->titleSafeCheckBox);
158  bool titleSafeOn = mManager->isOn(SETTING::TITLE_SAFE_ON);
159  ui->titleSafeCheckBox->setChecked(titleSafeOn);
160  QSignalBlocker b15(ui->titleSafeInput);
161  ui->titleSafeInput->setValue(mManager->getInt(SETTING::TITLE_SAFE));
162 
163  QSignalBlocker b18(ui->safeHelperTextCheckbox);
164  ui->safeHelperTextCheckbox->setChecked(mManager->isOn(SETTING::OVERLAY_SAFE_HELPER_TEXT_ON));
165 
166  QSignalBlocker b9(ui->highResBox);
167  ui->highResBox->setChecked(mManager->isOn(SETTING::HIGH_RESOLUTION));
168 
169  QSignalBlocker b10(ui->backgroundButtons);
170  QString bgName = mManager->getString(SETTING::BACKGROUND_STYLE);
171 
172  QSignalBlocker b12(ui->framePoolSizeSpin);
173  ui->framePoolSizeSpin->setValue(mManager->getInt(SETTING::FRAME_POOL_SIZE));
174 
175  int buttonIdx = 1;
176  if (bgName == "checkerboard") buttonIdx = 1;
177  else if (bgName == "white") buttonIdx = 2;
178  else if (bgName == "grey") buttonIdx = 3;
179  else if (bgName == "dots") buttonIdx = 4;
180  else if (bgName == "weave") buttonIdx = 5;
181  else Q_ASSERT(false);
182 
183  ui->backgroundButtons->button(buttonIdx)->setChecked(true);
184 }
185 
186 void GeneralPage::languageChanged(int i)
187 {
188  QString strLocale = ui->languageCombo->itemData(i).toString();
189  mManager->set(SETTING::LANGUAGE, strLocale);
190 
192  tr("Restart Required"),
193  tr("The language change will take effect after a restart of Pencil2D"));
194 }
195 
196 void GeneralPage::backgroundChanged(int value)
197 {
198  QString brushName = "white";
199  switch (value)
200  {
201  case 1: brushName = "checkerboard"; break;
202  case 2: brushName = "white"; break;
203  case 3: brushName = "grey"; break;
204  case 4: brushName = "dots"; break;
205  case 5: brushName = "weave"; break;
206  default:
207  break;
208  }
209  mManager->set(SETTING::BACKGROUND_STYLE, brushName);
210 }
211 
212 void GeneralPage::curveSmoothingChanged(int value)
213 {
214  mManager->set(SETTING::CURVE_SMOOTHING, value);
215 }
216 
217 void GeneralPage::highResCheckboxStateChanged(int b)
218 {
219  mManager->set(SETTING::HIGH_RESOLUTION, b != Qt::Unchecked);
220 }
221 
222 void GeneralPage::shadowsCheckboxStateChanged(int b)
223 {
224  mManager->set(SETTING::SHADOW, b != Qt::Unchecked);
225 }
226 
227 void GeneralPage::antiAliasCheckboxStateChanged(int b)
228 {
229  mManager->set(SETTING::ANTIALIAS, b != Qt::Unchecked);
230 }
231 
232 void GeneralPage::toolCursorsCheckboxStateChanged(int b)
233 {
234  mManager->set(SETTING::TOOL_CURSOR, b != Qt::Unchecked);
235 }
236 
237 void GeneralPage::dottedCursorCheckboxStateChanged(int b)
238 {
239  mManager->set(SETTING::DOTTED_CURSOR, b != Qt::Unchecked);
240 }
241 
242 void GeneralPage::gridWidthChanged(int value)
243 {
244  mManager->set(SETTING::GRID_SIZE_W, value);
245 }
246 
247 void GeneralPage::gridHeightChanged(int value)
248 {
249  mManager->set(SETTING::GRID_SIZE_H, value);
250 }
251 
252 void GeneralPage::actionSafeCheckBoxStateChanged(int b)
253 {
254  mManager->set(SETTING::ACTION_SAFE_ON, b != Qt::Unchecked);
255  updateSafeHelperTextEnabledState();
256 }
257 
258 void GeneralPage::actionSafeAreaChanged(int value)
259 {
260  mManager->set(SETTING::ACTION_SAFE, value);
261 }
262 
263 void GeneralPage::titleSafeCheckBoxStateChanged(int b)
264 {
265  mManager->set(SETTING::TITLE_SAFE_ON, b != Qt::Unchecked);
266  updateSafeHelperTextEnabledState();
267 }
268 
269 void GeneralPage::updateSafeHelperTextEnabledState()
270 {
271  if (!ui->actionSafeCheckBox->isChecked() && !ui->titleSafeCheckBox->isChecked()) {
272  ui->safeHelperTextCheckbox->setEnabled(false);
273  ui->labSafeHelperText->setEnabled(false);
274  } else {
275  ui->safeHelperTextCheckbox->setEnabled(true);
276  ui->labSafeHelperText->setEnabled(true);
277  }
278 }
279 
280 void GeneralPage::SafeAreaHelperTextCheckBoxStateChanged(int b)
281 {
282  mManager->set(SETTING::OVERLAY_SAFE_HELPER_TEXT_ON, b != Qt::Unchecked);
283 }
284 
285 void GeneralPage::titleSafeAreaChanged(int value)
286 {
287  mManager->set(SETTING::TITLE_SAFE, value);
288 }
289 
290 void GeneralPage::gridCheckBoxStateChanged(int b)
291 {
292  mManager->set(SETTING::GRID, b != Qt::Unchecked);
293 }
294 
295 void GeneralPage::frameCacheNumberChanged(int value)
296 {
297  mManager->set(SETTING::FRAME_POOL_SIZE, value);
298 }
void buttonClicked(QAbstractButton *button)
QString tr(const char *sourceText, const char *disambiguation, int n)
void valueChanged(int i)
void stateChanged(int state)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void valueChanged(int value)
Unchecked
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void currentIndexChanged(int index)