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);
50FilesPage::~FilesPage()
55void FilesPage::initPreset()
58 mPresetDir.
mkpath(
"presets");
59 mPresetDir.
cd(
"presets");
65 ui->presetListWidget->addItem(defaultItem);
70 int index = key.toInt(&ok);
71 if (!ok || index == 0 || !mPresetDir.
exists(
QString(
"%1.pclx").arg(index)))
continue;
73 mMaxPresetIndex = qMax(index, mMaxPresetIndex);
82 ui->presetListWidget->addItem(item);
86void FilesPage::addPreset()
88 int newPresetIndex = mMaxPresetIndex + 1;
92 Status st = fm.save(mManager->object(), PresetDialog::getPresetPath(newPresetIndex));
96 st.description().
append(
tr(
"<br><br>Error: your preset may not have saved successfully. "
97 "If you believe that this error is an issue with Pencil2D, please create a new issue at:"
98 "<br><a href='https://github.com/pencil2d/pencil/issues'>https://github.com/pencil2d/pencil/issues</a><br>"
99 "Please include the following details in your issue:")), st.details().html());
107 mMaxPresetIndex = newPresetIndex;
113 ui->presetListWidget->addItem(newItem);
115 ui->presetListWidget->scrollToBottom();
116 ui->presetListWidget->editItem(newItem);
119void FilesPage::removePreset()
121 if (ui->presetListWidget->count() <= 1) {
return; }
122 if (ui->presetListWidget->selectedItems().empty()) {
return; }
128 ui->presetListWidget->removeItemWidget(item);
135 QFile presetFile(PresetDialog::getPresetPath(index));
147 int prevDefaultIndex = mManager->getInt(SETTING::DEFAULT_PRESET);
151 if (index == prevDefaultIndex)
153 mManager->set(SETTING::DEFAULT_PRESET, 0);
165void FilesPage::setDefaultPreset()
169 QListWidgetItem* newDefaultPresetItem = ui->presetListWidget->currentItem();
170 if (newDefaultPresetItem)
175 mManager->set(SETTING::DEFAULT_PRESET, newDefaultIndex);
191void FilesPage::updateValues()
194 int defaultPresetIndex = mManager->getInt(SETTING::DEFAULT_PRESET);
196 for (
int i = 0; i < ui->presetListWidget->count(); i++)
201 bool isDefault = presetIndex == defaultPresetIndex;
204 font.setBold(isDefault);
210 ui->autosaveCheckBox->setChecked(mManager->isOn(SETTING::AUTO_SAVE));
211 ui->autosaveNumberBox->setValue(mManager->getInt(SETTING::AUTO_SAVE_NUMBER));
212 ui->askPresetRbtn->setChecked(mManager->isOn(SETTING::ASK_FOR_PRESET));
213 ui->loadDefaultPresetRbtn->setChecked(mManager->isOn(SETTING::LOAD_DEFAULT_PRESET));
214 ui->loadLastActiveRbtn->setChecked(mManager->isOn(SETTING::LOAD_MOST_RECENT));
217void FilesPage::askForPresetChange(
int b)
222void FilesPage::loadMostRecentChange(
int b)
224 mManager->set(SETTING::LOAD_MOST_RECENT, b !=
Qt::Unchecked);
227void FilesPage::loadDefaultPreset(
int b)
229 mManager->set(SETTING::LOAD_DEFAULT_PRESET, b !=
Qt::Unchecked);
232void FilesPage::autoSaveChange(
int b)
237void FilesPage::autoSaveNumberChange(
int number)
239 mManager->set(SETTING::AUTO_SAVE_NUMBER, 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