Add autosave options to startup popup (#1265)

* add autosave options to startup popup
This commit is contained in:
Jeremy Bullock 2017-11-14 18:32:45 -07:00 committed by shun-iwasawa
parent f9b89b9c75
commit 4c62241cb1
6 changed files with 67 additions and 5 deletions

View file

@ -516,6 +516,7 @@ Q_SIGNALS:
void stopAutoSave();
void startAutoSave();
void autoSavePeriodChanged();
private:
std::unique_ptr<QSettings> m_settings;

View file

@ -383,6 +383,7 @@ void PreferencesPopup::onScanLevelTypeChanged(const QString &text) {
//-----------------------------------------------------------------------------
void PreferencesPopup::onMinuteChanged() {
if (m_minuteFld->getValue() != m_pref->getAutosavePeriod())
m_pref->setAutosavePeriod(m_minuteFld->getValue());
}
@ -599,6 +600,7 @@ void PreferencesPopup::onDefaultViewerChanged(int index) {
//-----------------------------------------------------------------------------
void PreferencesPopup::onAutoSaveChanged(bool on) {
if (m_autoSaveGroup->isChecked() != m_pref->isAutosaveEnabled())
m_pref->enableAutosave(on);
if (on && !m_autoSaveSceneCB->isChecked() &&
!m_autoSaveOtherFilesCB->isChecked()) {
@ -609,6 +611,18 @@ void PreferencesPopup::onAutoSaveChanged(bool on) {
//-----------------------------------------------------------------------------
void PreferencesPopup::onAutoSaveExternallyChanged() {
m_autoSaveGroup->setChecked(Preferences::instance()->isAutosaveEnabled());
}
//-----------------------------------------------------------------------------
void PreferencesPopup::onAutoSavePeriodExternallyChanged() {
m_minuteFld->setValue(m_pref->getAutosavePeriod());
}
//-----------------------------------------------------------------------------
void PreferencesPopup::onAutoSaveSceneChanged(int index) {
m_pref->enableAutosaveScene(index == Qt::Checked);
if (!m_autoSaveOtherFilesCB->isChecked() && index == Qt::Unchecked) {
@ -2347,6 +2361,12 @@ PreferencesPopup::PreferencesPopup()
SLOT(onRasterOptimizedMemoryChanged(int)));
ret = ret && connect(m_autoSaveGroup, SIGNAL(toggled(bool)),
SLOT(onAutoSaveChanged(bool)));
ret = ret && connect(m_pref, SIGNAL(stopAutoSave()), this,
SLOT(onAutoSaveExternallyChanged()));
ret = ret && connect(m_pref, SIGNAL(startAutoSave()), this,
SLOT(onAutoSaveExternallyChanged()));
ret = ret && connect(m_pref, SIGNAL(autoSavePeriodChanged()), this,
SLOT(onAutoSavePeriodExternallyChanged()));
ret = ret && connect(m_autoSaveSceneCB, SIGNAL(stateChanged(int)),
SLOT(onAutoSaveSceneChanged(int)));
ret = ret && connect(m_autoSaveOtherFilesCB, SIGNAL(stateChanged(int)),

View file

@ -94,6 +94,8 @@ private slots:
void onProjectRootChanged();
void onCustomProjectRootChanged();
void onPixelUnitExternallySelected(bool on);
void onAutoSaveExternallyChanged();
void onAutoSavePeriodExternallyChanged();
void onUnitChanged(int index);
void onCameraUnitChanged(int index);
void onRoomChoiceChanged(int index);

View file

@ -120,6 +120,8 @@ StartupPopup::StartupPopup()
m_addPresetBtn = new QPushButton(tr("Add"), this);
m_removePresetBtn = new QPushButton(tr("Remove"), this);
m_showAtStartCB = new QCheckBox(tr("Show this at startup"), this);
m_autoSaveOnCB = new QCheckBox(tr("Automatically Save Every "));
m_autoSaveTimeFld = new IntLineEdit(this, 10);
QPushButton *createButton = new QPushButton(tr("Create Scene"), this);
QPushButton *newProjectButton = new QPushButton(tr("New Project..."), this);
QPushButton *loadOtherSceneButton =
@ -143,6 +145,11 @@ StartupPopup::StartupPopup()
m_dpiFld->setRange(1.0, (std::numeric_limits<double>::max)());
m_resXFld->setRange(0.1, (std::numeric_limits<double>::max)());
m_resYFld->setRange(0.1, (std::numeric_limits<double>::max)());
m_autoSaveTimeFld->setRange(1, (std::numeric_limits<int>::max)());
m_autoSaveOnCB->setChecked(Preferences::instance()->isAutosaveEnabled());
m_autoSaveOnCB->setStyleSheet("QCheckBox{ background-color: none; }");
m_autoSaveTimeFld->setEnabled(m_autoSaveOnCB->isChecked());
m_autoSaveTimeFld->setValue(Preferences::instance()->getAutosavePeriod());
m_showAtStartCB->setChecked(Preferences::instance()->isStartupPopupEnabled());
m_showAtStartCB->setStyleSheet("QCheckBox{ background-color: none; }");
m_addPresetBtn->setStyleSheet(
@ -248,7 +255,15 @@ StartupPopup::StartupPopup()
m_buttonLayout->setMargin(0);
m_buttonLayout->setSpacing(10);
{ m_buttonLayout->addWidget(m_showAtStartCB, Qt::AlignLeft); }
{
m_buttonLayout->addWidget(m_showAtStartCB, Qt::AlignLeft);
m_buttonLayout->addStretch();
m_buttonLayout->addWidget(m_autoSaveOnCB);
m_buttonLayout->addWidget(m_autoSaveTimeFld);
QLabel *minutesLabel = new QLabel(tr("Minutes"), this);
minutesLabel->setStyleSheet("QLabel{ background-color: none; }");
m_buttonLayout->addWidget(minutesLabel);
}
TApp *app = TApp::instance();
TSceneHandle *sceneHandle = app->getCurrentScene();
@ -288,6 +303,10 @@ StartupPopup::StartupPopup()
connect(m_removePresetBtn, SIGNAL(clicked()), SLOT(removePreset()));
ret = ret && connect(m_nameFld, SIGNAL(returnPressedNow()), createButton,
SLOT(animateClick()));
ret = ret && connect(m_autoSaveOnCB, SIGNAL(stateChanged(int)), this,
SLOT(onAutoSaveOnChanged(int)));
ret = ret && connect(m_autoSaveTimeFld, SIGNAL(editingFinished()), this,
SLOT(onAutoSaveTimeChanged()));
assert(ret);
}
@ -357,7 +376,9 @@ void StartupPopup::showEvent(QShowEvent *) {
m_sceneBox->setFixedWidth(boxWidth);
m_projectBox->setFixedWidth(boxWidth);
m_recentBox->setMinimumHeight(boxHeight);
m_autoSaveOnCB->setChecked(Preferences::instance()->isAutosaveEnabled());
m_autoSaveTimeFld->setEnabled(m_autoSaveOnCB->isChecked());
m_autoSaveTimeFld->setValue(Preferences::instance()->getAutosavePeriod());
// update recent scenes
// clear items if they exist first
refreshRecentScenes();
@ -894,6 +915,19 @@ void StartupPopup::onShowAtStartChanged(int index) {
//-----------------------------------------------------------------------------
void StartupPopup::onAutoSaveOnChanged(int index) {
Preferences::instance()->enableAutosave(index);
m_autoSaveTimeFld->setEnabled(index);
}
//-----------------------------------------------------------------------------
void StartupPopup::onAutoSaveTimeChanged() {
Preferences::instance()->setAutosavePeriod(m_autoSaveTimeFld->getValue());
}
//-----------------------------------------------------------------------------
void StartupPopup::updateResolution() {
if (Preferences::instance()->getPixelsOnly()) {
if (m_dpiFld->getValue() != Stage::standardDpi) {

View file

@ -40,9 +40,11 @@ class StartupPopup final : public DVGui::Dialog {
DVGui::DoubleLineEdit *m_fpsFld;
DVGui::DoubleLineEdit *m_resXFld;
DVGui::DoubleLineEdit *m_resYFld;
DVGui::IntLineEdit *m_autoSaveTimeFld;
QList<QString> m_sceneNames;
QList<TFilePath> m_projectPaths;
QCheckBox *m_showAtStartCB;
QCheckBox *m_autoSaveOnCB;
QComboBox *m_projectsCB;
QComboBox *m_unitsCB;
QPushButton *m_loadOtherSceneButton;
@ -91,6 +93,8 @@ public slots:
void removePreset();
void onPresetSelected(const QString &str);
void onCameraUnitChanged(int index);
void onAutoSaveOnChanged(int index);
void onAutoSaveTimeChanged();
};
class StartupLabel : public QLabel {

View file

@ -819,6 +819,7 @@ void Preferences::setAutosavePeriod(int minutes) {
m_settings->setValue("autosavePeriod", QString::number(minutes));
emit stopAutoSave();
emit startAutoSave();
emit autoSavePeriodChanged();
}
//-----------------------------------------------------------------