18#include "generalpage.h"
26#include "preferencemanager.h"
28#include "ui_generalpage.h"
39 { tr(
"Arabic"), QStringLiteral(
"العربية"),
"ar" },
40 { tr(
"Bulgarian"), QStringLiteral(
"Български"),
"bg" },
41 { tr(
"Catalan"), QStringLiteral(
"Català"),
"ca" },
42 { tr(
"Czech"), QStringLiteral(
"Čeština"),
"cs" },
43 { tr(
"Danish"), QStringLiteral(
"Dansk"),
"da" },
44 { tr(
"German"), QStringLiteral(
"Deutsch"),
"de" },
45 { tr(
"Greek"), QStringLiteral(
"Ελληνικά"),
"el" },
46 { tr(
"English"), QStringLiteral(
"English"),
"en" },
47 { tr(
"Spanish"), QStringLiteral(
"Español"),
"es" },
48 { tr(
"Estonian"), QStringLiteral(
"Eesti"),
"et" },
49 { tr(
"Persian"), QStringLiteral(
"فارسی"),
"fa" },
50 { tr(
"French"), QStringLiteral(
"Français"),
"fr" },
51 { tr(
"Hebrew"), QStringLiteral(
"עברית"),
"he" },
52 { tr(
"Hungarian"), QStringLiteral(
"Magyar"),
"hu_HU" },
53 { tr(
"Indonesian"), QStringLiteral(
"Bahasa Indonesia"),
"id" },
54 { tr(
"Italian"), QStringLiteral(
"Italiano"),
"it" },
55 { tr(
"Japanese"), QStringLiteral(
"日本語"),
"ja" },
56 { tr(
"Kabyle"), QStringLiteral(
"Taqbaylit"),
"kab" },
57 { tr(
"Korean"), QStringLiteral(
"한국어"),
"ko" },
58 { tr(
"Norwegian Bokmål"), QStringLiteral(
"Norsk bokmål"),
"nb" },
59 { tr(
"Dutch \u2013 Netherlands"), QStringLiteral(
"Nederlands \u2013 Nederland"),
"nl_NL" },
60 { tr(
"Polish"), QStringLiteral(
"Polski"),
"pl" },
61 { tr(
"Portuguese \u2013 Portugal"), QStringLiteral(
"Português \u2013 Portugal"),
"pt_PT" },
62 { tr(
"Portuguese \u2013 Brazil"), QStringLiteral(
"Português \u2013 Brasil"),
"pt_BR" },
63 { tr(
"Russian"), QStringLiteral(
"Русский"),
"ru" },
64 { tr(
"Slovene"), QStringLiteral(
"Slovenščina"),
"sl" },
65 { tr(
"Swedish"), QStringLiteral(
"Svenska"),
"sv" },
66 { tr(
"Turkish"), QStringLiteral(
"Türkçe"),
"tr" },
67 { tr(
"Vietnamese"), QStringLiteral(
"Tiếng Việt"),
"vi" },
68 { tr(
"Cantonese"), QStringLiteral(
"粵语"),
"yue" },
69 { tr(
"Chinese \u2013 China"), QStringLiteral(
"简体中文"),
"zh_CN" },
70 { tr(
"Chinese \u2013 Taiwan"), QStringLiteral(
"繁體中文"),
"zh_TW" },
73 for (
auto& lang : languages)
75 const QString itemText = QStringLiteral(
"%1 (%2)").
arg(lang[0]).
arg(lang[1]);
76 const QString localeCode = lang[2];
77 ui->languageCombo->addItem(itemText, localeCode);
80 int value = settings.value(
"windowOpacity").
toInt();
81 ui->windowOpacityLevel->setValue(100 - value);
83 QPixmap previewCheckerboard(
":background/checkerboard.png");
86 QPixmap previewDots(
":background/dots.png");
87 QPixmap previewWeave(
":background/weave.jpg");
92 ui->checkerBackgroundButton->setIcon(previewCheckerboard.scaled(32, 32));
93 ui->whiteBackgroundButton->setIcon(previewWhite);
94 ui->greyBackgroundButton->setIcon(previewGrey);
95 ui->dotsBackgroundButton->setIcon(previewDots.scaled(32, 32));
96 ui->weaveBackgroundButton->setIcon(previewWeave.scaled(32, 32));
97 ui->backgroundButtons->setId(ui->checkerBackgroundButton, 1);
98 ui->backgroundButtons->setId(ui->whiteBackgroundButton, 2);
99 ui->backgroundButtons->setId(ui->greyBackgroundButton, 3);
100 ui->backgroundButtons->setId(ui->dotsBackgroundButton, 4);
101 ui->backgroundButtons->setId(ui->weaveBackgroundButton, 5);
103 ui->undoRedoGroupApplyButton->setDisabled(
true);
104 ui->undoRedoGroupCancelButton->setDisabled(
true);
109 connect(ui->languageCombo, curIndexChanged,
this, &GeneralPage::languageChanged);
111 connect(ui->backgroundButtons, buttonClicked,
this, &GeneralPage::backgroundChanged);
118 connect(ui->gridSizeInputW, spinValueChanged,
this, &GeneralPage::gridWidthChanged);
119 connect(ui->gridSizeInputH, spinValueChanged,
this, &GeneralPage::gridHeightChanged);
121 connect(ui->actionSafeInput, spinValueChanged,
this, &GeneralPage::actionSafeAreaChanged);
123 connect(ui->titleSafeInput, spinValueChanged,
this, &GeneralPage::titleSafeAreaChanged);
124 connect(ui->safeHelperTextCheckbox, &
QCheckBox::stateChanged,
this, &GeneralPage::SafeAreaHelperTextCheckBoxStateChanged);
126 connect(ui->framePoolSizeSpin, spinValueChanged,
this, &GeneralPage::frameCacheNumberChanged);
127 connect(ui->invertScrollDirectionBox, &
QCheckBox::stateChanged,
this, &GeneralPage::invertScrollDirectionBoxStateChanged);
128 connect(ui->newUndoRedoCheckBox, &
QCheckBox::stateChanged,
this, &GeneralPage::newUndoRedoCheckBoxStateChanged);
129 connect(ui->undoStepsBox, spinValueChanged,
this, &GeneralPage::undoRedoMaxStepsChanged);
130 connect(ui->undoRedoGroupApplyButton, &
QPushButton::clicked,
this, &GeneralPage::undoRedoApplyButtonPressed);
131 connect(ui->undoRedoGroupCancelButton, &
QPushButton::clicked,
this, &GeneralPage::undoRedoCancelButtonPressed);
134GeneralPage::~GeneralPage()
139void GeneralPage::updateValues()
141 int index = ui->languageCombo->findData(mManager->getString(SETTING::LANGUAGE));
146 ui->languageCombo->setCurrentIndex(index);
150 ui->curveSmoothingLevel->setValue(mManager->getInt(SETTING::CURVE_SMOOTHING));
152 ui->windowOpacityLevel->setValue(100 - mManager->getInt(SETTING::WINDOW_OPACITY));
154 ui->shadowsBox->setChecked(mManager->isOn(SETTING::SHADOW));
156 ui->toolCursorsBox->setChecked(mManager->isOn(SETTING::TOOL_CURSOR));
158 ui->antialiasingBox->setChecked(mManager->isOn(SETTING::ANTIALIAS));
160 ui->canvasCursorBox->setChecked(mManager->isOn(SETTING::CANVAS_CURSOR));
162 ui->gridSizeInputW->setValue(mManager->getInt(SETTING::GRID_SIZE_W));
164 ui->gridSizeInputH->setValue(mManager->getInt(SETTING::GRID_SIZE_H));
166 ui->gridCheckBox->setChecked(mManager->isOn(SETTING::GRID));
169 bool actionSafeOn = mManager->isOn(SETTING::ACTION_SAFE_ON);
170 ui->actionSafeCheckBox->setChecked(actionSafeOn);
172 ui->actionSafeInput->setValue(mManager->getInt(SETTING::ACTION_SAFE));
174 bool titleSafeOn = mManager->isOn(SETTING::TITLE_SAFE_ON);
175 ui->titleSafeCheckBox->setChecked(titleSafeOn);
177 ui->titleSafeInput->setValue(mManager->getInt(SETTING::TITLE_SAFE));
180 ui->safeHelperTextCheckbox->setChecked(mManager->isOn(SETTING::OVERLAY_SAFE_HELPER_TEXT_ON));
183 ui->highResBox->setChecked(mManager->isOn(SETTING::HIGH_RESOLUTION));
186 QString bgName = mManager->getString(SETTING::BACKGROUND_STYLE);
189 ui->framePoolSizeSpin->setValue(mManager->getInt(SETTING::FRAME_POOL_SIZE));
192 ui->newUndoRedoCheckBox->setChecked(mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON));
195 ui->undoStepsBox->setValue(mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS));
198 if (bgName ==
"checkerboard") buttonIdx = 1;
199 else if (bgName ==
"white") buttonIdx = 2;
200 else if (bgName ==
"grey") buttonIdx = 3;
201 else if (bgName ==
"dots") buttonIdx = 4;
202 else if (bgName ==
"weave") buttonIdx = 5;
203 else Q_ASSERT(
false);
205 ui->backgroundButtons->button(buttonIdx)->setChecked(
true);
207 ui->invertScrollDirectionBox->setChecked(mManager->isOn(SETTING::INVERT_SCROLL_ZOOM_DIRECTION));
210void GeneralPage::languageChanged(
int i)
212 QString strLocale = ui->languageCombo->itemData(i).toString();
213 mManager->set(SETTING::LANGUAGE, strLocale);
216 std::unique_ptr<QTranslator> newlangTr(
new QTranslator(
this));
217 if (newlangTr->load(
locale,
"pencil",
"_",
":/i18n/"))
220 newlangTr->translate(staticMetaObject.className(),
"Restart Required"),
221 newlangTr->translate(staticMetaObject.className(),
"The language change will take effect after a restart of Pencil2D"));
225 tr(
"Restart Required"),
226 tr(
"The language change will take effect after a restart of Pencil2D"));
233 if (button == ui->checkerBackgroundButton) brushName =
"checkerboard";
234 else if (button == ui->whiteBackgroundButton) brushName =
"white";
235 else if (button == ui->greyBackgroundButton) brushName =
"grey";
236 else if (button == ui->dotsBackgroundButton) brushName =
"dots";
237 else if (button == ui->weaveBackgroundButton) brushName =
"weave";
238 else Q_UNREACHABLE();
239 mManager->set(SETTING::BACKGROUND_STYLE, brushName);
242void GeneralPage::curveSmoothingChanged(
int value)
244 mManager->set(SETTING::CURVE_SMOOTHING, value);
247void GeneralPage::highResCheckboxStateChanged(
int b)
252void GeneralPage::shadowsCheckboxStateChanged(
int b)
257void GeneralPage::antiAliasCheckboxStateChanged(
int b)
262void GeneralPage::toolCursorsCheckboxStateChanged(
int b)
267void GeneralPage::canvasCursorCheckboxStateChanged(
int b)
272void GeneralPage::gridWidthChanged(
int value)
274 mManager->set(SETTING::GRID_SIZE_W, value);
277void GeneralPage::gridHeightChanged(
int value)
279 mManager->set(SETTING::GRID_SIZE_H, value);
282void GeneralPage::actionSafeCheckBoxStateChanged(
int b)
285 updateSafeHelperTextEnabledState();
288void GeneralPage::actionSafeAreaChanged(
int value)
290 mManager->set(SETTING::ACTION_SAFE, value);
293void GeneralPage::titleSafeCheckBoxStateChanged(
int b)
296 updateSafeHelperTextEnabledState();
299void GeneralPage::updateSafeHelperTextEnabledState()
301 if (!ui->actionSafeCheckBox->isChecked() && !ui->titleSafeCheckBox->isChecked()) {
302 ui->safeHelperTextCheckbox->setEnabled(
false);
303 ui->labSafeHelperText->setEnabled(
false);
305 ui->safeHelperTextCheckbox->setEnabled(
true);
306 ui->labSafeHelperText->setEnabled(
true);
310void GeneralPage::SafeAreaHelperTextCheckBoxStateChanged(
int b)
312 mManager->set(SETTING::OVERLAY_SAFE_HELPER_TEXT_ON, b !=
Qt::Unchecked);
315void GeneralPage::titleSafeAreaChanged(
int value)
317 mManager->set(SETTING::TITLE_SAFE, value);
320void GeneralPage::gridCheckBoxStateChanged(
int b)
325void GeneralPage::frameCacheNumberChanged(
int value)
327 mManager->set(SETTING::FRAME_POOL_SIZE, value);
330void GeneralPage::invertScrollDirectionBoxStateChanged(
int b)
332 mManager->set(SETTING::INVERT_SCROLL_ZOOM_DIRECTION, b !=
Qt::Unchecked);
335void GeneralPage::newUndoRedoCheckBoxStateChanged()
337 ui->undoRedoGroupApplyButton->setEnabled(canApplyOrCancelUndoRedoChanges());
338 ui->undoRedoGroupCancelButton->setEnabled(canApplyOrCancelUndoRedoChanges());
341void GeneralPage::undoRedoMaxStepsChanged()
343 ui->undoRedoGroupApplyButton->setEnabled(canApplyOrCancelUndoRedoChanges());
344 ui->undoRedoGroupCancelButton->setEnabled(canApplyOrCancelUndoRedoChanges());
347bool GeneralPage::canApplyOrCancelUndoRedoChanges()
const
349 const bool newSystemIsOnCurrent = mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON);
350 const int maxUndoRedoStepNumCurrent = mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS);
352 if (newSystemIsOnCurrent != ui->newUndoRedoCheckBox->isChecked()
353 || maxUndoRedoStepNumCurrent != ui->undoStepsBox->value()) {
360void GeneralPage::undoRedoApplyButtonPressed()
362 if (ui->undoStepsBox->value() != mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS)) {
365 messageBox.setText(
tr(
"Resets your current undo history"));
366 messageBox.setInformativeText(
tr(
"Changing the maximum number of undo/redo steps resets your current undo/redo history. \n\nAre you sure you want to proceed?"));
370 mManager->set(SETTING::UNDO_REDO_MAX_STEPS, ui->undoStepsBox->value());
372 ui->undoStepsBox->setValue(mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS));
376 const bool systemIsOn = mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON);
377 if (ui->newUndoRedoCheckBox->isChecked() != systemIsOn) {
378 if (ui->newUndoRedoCheckBox->isChecked()) {
381 messageBox.setText(
tr(
"Experimental feature!"));
382 messageBox.setInformativeText(
tr(
"This feature is work in progress and may not currently allow for the same features as the current undo/redo system. Once enabled, you'll need to restart the application to start using it. \n\nDo you still want to try?"));
386 mManager->set(SETTING::NEW_UNDO_REDO_SYSTEM_ON,
true);
389 mManager->set(SETTING::NEW_UNDO_REDO_SYSTEM_ON,
false);
394 messageBox.setText(
tr(
"The undo/redo system will be changed on the next launch of the application"));
396 mManager->set(SETTING::NEW_UNDO_REDO_SYSTEM_ON,
false);
400 ui->undoRedoGroupCancelButton->setDisabled(
true);
401 ui->undoRedoGroupApplyButton->setDisabled(
true);
404void GeneralPage::undoRedoCancelButtonPressed()
406 ui->undoStepsBox->setValue(mManager->getInt(SETTING::UNDO_REDO_MAX_STEPS));
407 ui->newUndoRedoCheckBox->setCheckState(mManager->isOn(SETTING::NEW_UNDO_REDO_SYSTEM_ON) ?
Qt::Checked :
Qt::Unchecked);
408 ui->undoRedoGroupCancelButton->setDisabled(
true);
409 ui->undoRedoGroupApplyButton->setDisabled(
true);
void valueChanged(int value)
void stateChanged(int state)
void currentIndexChanged(int index)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
int toInt(bool *ok, int base) const const