21#include <QStandardPaths>
23#include "errordialog.h"
24#include "filemanager.h"
25#include "pencilerror.h"
26#include "presetdialog.h"
28#include "ui_filespage.h"
47 connect(ui->autosaveNumberBox, spinBoxValueChange,
this, &FilesPage::autoSaveNumberChange);
49 connect(ui->autosaveByTimeNumberBox, spinBoxValueChange,
this, &FilesPage::autoSaveByTimeTimerChange);
52FilesPage::~FilesPage()
57void FilesPage::initPreset()
60 mPresetDir.
mkpath(
"presets");
61 mPresetDir.
cd(
"presets");
67 ui->presetListWidget->addItem(defaultItem);
72 int index = key.toInt(&ok);
73 if (!ok || index == 0 || !mPresetDir.
exists(
QString(
"%1.pclx").arg(index)))
continue;
75 mMaxPresetIndex = qMax(index, mMaxPresetIndex);
84 ui->presetListWidget->addItem(item);
88void FilesPage::addPreset()
90 int newPresetIndex = mMaxPresetIndex + 1;
94 Status st = fm.save(mManager->object(), PresetDialog::getPresetPath(newPresetIndex));
98 st.description().
append(
tr(
"<br><br>Error: your preset may not have saved successfully. "
99 "If you believe that this error is an issue with Pencil2D, please create a new issue at:"
100 "<br><a href='https://github.com/pencil2d/pencil/issues'>https://github.com/pencil2d/pencil/issues</a><br>"
101 "Please include the following details in your issue:")), st.details().html());
109 mMaxPresetIndex = newPresetIndex;
115 ui->presetListWidget->addItem(newItem);
117 ui->presetListWidget->scrollToBottom();
118 ui->presetListWidget->editItem(newItem);
121void FilesPage::removePreset()
123 if (ui->presetListWidget->count() <= 1) {
return; }
124 if (ui->presetListWidget->selectedItems().empty()) {
return; }
130 ui->presetListWidget->removeItemWidget(item);
137 QFile presetFile(PresetDialog::getPresetPath(index));
149 int prevDefaultIndex = mManager->getInt(SETTING::DEFAULT_PRESET);
153 if (index == prevDefaultIndex)
155 mManager->set(SETTING::DEFAULT_PRESET, 0);
167void FilesPage::setDefaultPreset()
171 QListWidgetItem* newDefaultPresetItem = ui->presetListWidget->currentItem();
172 if (newDefaultPresetItem)
177 mManager->set(SETTING::DEFAULT_PRESET, newDefaultIndex);
193void FilesPage::updateValues()
196 int defaultPresetIndex = mManager->getInt(SETTING::DEFAULT_PRESET);
198 for (
int i = 0; i < ui->presetListWidget->count(); i++)
203 bool isDefault = presetIndex == defaultPresetIndex;
206 font.setBold(isDefault);
212 ui->autosaveCheckBox->setChecked(mManager->isOn(SETTING::AUTO_SAVE));
213 ui->autosaveNumberBox->setValue(mManager->getInt(SETTING::AUTO_SAVE_NUMBER));
214 ui->autosaveByTimeCheckBox->setChecked(mManager->isOn(SETTING::AUTO_SAVE_BY_TIME));
215 ui->autosaveByTimeNumberBox->setValue(mManager->getInt(SETTING::AUTO_SAVE_BY_TIME_TIMER));
216 ui->askPresetRbtn->setChecked(mManager->isOn(SETTING::ASK_FOR_PRESET));
217 ui->loadDefaultPresetRbtn->setChecked(mManager->isOn(SETTING::LOAD_DEFAULT_PRESET));
218 ui->loadLastActiveRbtn->setChecked(mManager->isOn(SETTING::LOAD_MOST_RECENT));
221void FilesPage::askForPresetChange(
int b)
226void FilesPage::loadMostRecentChange(
int b)
228 mManager->set(SETTING::LOAD_MOST_RECENT, b !=
Qt::Unchecked);
231void FilesPage::loadDefaultPreset(
int b)
233 mManager->set(SETTING::LOAD_DEFAULT_PRESET, b !=
Qt::Unchecked);
236void FilesPage::autoSaveChange(
int b)
241void FilesPage::autoSaveNumberChange(
int number)
243 mManager->set(SETTING::AUTO_SAVE_NUMBER, number);
246void FilesPage::autoSaveByTimeChange(
int b)
248 mManager->set(SETTING::AUTO_SAVE_BY_TIME, b !=
Qt::Unchecked);
251void FilesPage::autoSaveByTimeTimerChange(
int number)
253 mManager->set(SETTING::AUTO_SAVE_BY_TIME_TIMER, number);
void stateChanged(int state)
bool cd(const QString &dirName)
bool exists() const const
QString filePath(const QString &fileName) const const
bool mkpath(const QString &dirPath) const const
void setText(const QString &text)
QString text() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QStringList allKeys() const const
void remove(const QString &key)
void setValue(const QString &key, const QVariant &value)
QVariant value(const QString &key, const QVariant &defaultValue) const const
QString writableLocation(QStandardPaths::StandardLocation type)
QString & append(QChar ch)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
QString number(int n, int base)
QString & remove(int position, int n)
int toInt(bool *ok) const const
QString toString() const const