From 4c62241cb117baf8d31a9e4e8f917020fed55a25 Mon Sep 17 00:00:00 2001 From: Jeremy Bullock Date: Nov 15 2017 01:32:45 +0000 Subject: Add autosave options to startup popup (#1265) * add autosave options to startup popup --- diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 2dcd002..f6fb980 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -516,6 +516,7 @@ Q_SIGNALS: void stopAutoSave(); void startAutoSave(); + void autoSavePeriodChanged(); private: std::unique_ptr m_settings; diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 6c03202..dcd772b 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -383,7 +383,8 @@ void PreferencesPopup::onScanLevelTypeChanged(const QString &text) { //----------------------------------------------------------------------------- void PreferencesPopup::onMinuteChanged() { - m_pref->setAutosavePeriod(m_minuteFld->getValue()); + if (m_minuteFld->getValue() != m_pref->getAutosavePeriod()) + m_pref->setAutosavePeriod(m_minuteFld->getValue()); } //----------------------------------------------------------------------------- @@ -599,7 +600,8 @@ void PreferencesPopup::onDefaultViewerChanged(int index) { //----------------------------------------------------------------------------- void PreferencesPopup::onAutoSaveChanged(bool on) { - m_pref->enableAutosave(on); + if (m_autoSaveGroup->isChecked() != m_pref->isAutosaveEnabled()) + m_pref->enableAutosave(on); if (on && !m_autoSaveSceneCB->isChecked() && !m_autoSaveOtherFilesCB->isChecked()) { m_autoSaveSceneCB->setChecked(true); @@ -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)), diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 472707a..5b93e65 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -43,7 +43,7 @@ private: private: Preferences *m_pref; - + FormatProperties *m_formatProperties; DVGui::ColorField *m_blankColor, *m_frontOnionColor, *m_backOnionColor, @@ -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); diff --git a/toonz/sources/toonz/startuppopup.cpp b/toonz/sources/toonz/startuppopup.cpp index dad84c4..b84d860 100644 --- a/toonz/sources/toonz/startuppopup.cpp +++ b/toonz/sources/toonz/startuppopup.cpp @@ -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::max)()); m_resXFld->setRange(0.1, (std::numeric_limits::max)()); m_resYFld->setRange(0.1, (std::numeric_limits::max)()); + m_autoSaveTimeFld->setRange(1, (std::numeric_limits::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) { diff --git a/toonz/sources/toonz/startuppopup.h b/toonz/sources/toonz/startuppopup.h index 6427db8..aef4eaa 100644 --- a/toonz/sources/toonz/startuppopup.h +++ b/toonz/sources/toonz/startuppopup.h @@ -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 m_sceneNames; QList 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 { diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index 65dc0b0..195e3e0 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -819,6 +819,7 @@ void Preferences::setAutosavePeriod(int minutes) { m_settings->setValue("autosavePeriod", QString::number(minutes)); emit stopAutoSave(); emit startAutoSave(); + emit autoSavePeriodChanged(); } //-----------------------------------------------------------------