From bc9dd643fc141c671c11d4a815aa1940a9440c30 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 6 Feb 2018 20:37:38 +0800 Subject: [PATCH] support reset layout --- src/dialog/vsettingsdialog.cpp | 36 ++++++++++++++++++++++++++++++++++ src/dialog/vsettingsdialog.h | 5 +++++ src/vconfigmanager.cpp | 11 +++++++++++ src/vconfigmanager.h | 3 +++ 4 files changed, 55 insertions(+) diff --git a/src/dialog/vsettingsdialog.cpp b/src/dialog/vsettingsdialog.cpp index 4827cb7d..897e23c7 100644 --- a/src/dialog/vsettingsdialog.cpp +++ b/src/dialog/vsettingsdialog.cpp @@ -25,12 +25,19 @@ VSettingsDialog::VSettingsDialog(QWidget *p_parent) connect(m_resetVNoteBtn, &QPushButton::clicked, this, &VSettingsDialog::resetVNote); + // Reset Layout. + m_resetLayoutBtn = new QPushButton(tr("Reset Layout"), this); + m_resetLayoutBtn->setToolTip(tr("Reset layout of VNote")); + connect(m_resetLayoutBtn, &QPushButton::clicked, + this, &VSettingsDialog::resetLayout); + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(m_btnBox, &QDialogButtonBox::accepted, this, &VSettingsDialog::saveConfiguration); connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); m_btnBox->button(QDialogButtonBox::Ok)->setProperty("SpecialBtn", true); m_btnBox->addButton(m_resetVNoteBtn, QDialogButtonBox::ResetRole); + m_btnBox->addButton(m_resetLayoutBtn, QDialogButtonBox::ResetRole); QHBoxLayout *tabLayout = new QHBoxLayout(); tabLayout->addWidget(m_tabList); @@ -99,6 +106,35 @@ void VSettingsDialog::resetVNote() reject(); } +void VSettingsDialog::resetLayout() +{ + int ret = VUtils::showMessage(QMessageBox::Warning, + tr("Warning"), + tr("Are you sure to reset the layout of VNote?"), + tr("The view and layout mode will be reset. " + "It is UNRECOVERABLE!"), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel, + this, + MessageBoxType::Danger); + + if (ret == QMessageBox::Cancel) { + return; + } + + g_config->resetLayoutConfigurations(); + + VUtils::showMessage(QMessageBox::Information, + tr("Information"), + tr("Please restart VNote to make it work."), + tr("Any change to VNote before restart will be lost!"), + QMessageBox::Ok, + QMessageBox::Ok, + this); + + reject(); +} + void VSettingsDialog::addTab(QWidget *p_widget, const QString &p_label) { int idx = m_tabs->addWidget(p_widget); diff --git a/src/dialog/vsettingsdialog.h b/src/dialog/vsettingsdialog.h index 8f93d0c4..1be0bd13 100644 --- a/src/dialog/vsettingsdialog.h +++ b/src/dialog/vsettingsdialog.h @@ -167,6 +167,8 @@ private slots: void resetVNote(); + void resetLayout(); + private: void loadConfiguration(); @@ -178,6 +180,9 @@ private: // Reset all the configuration of VNote. QPushButton *m_resetVNoteBtn; + + // Reset the layout. + QPushButton *m_resetLayoutBtn; }; #endif // VSETTINGSDIALOG_H diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 2b027213..4add3315 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -1396,6 +1396,17 @@ void VConfigManager::resetConfigurations() m_hasReset = true; } +void VConfigManager::resetLayoutConfigurations() +{ + resetDefaultConfig("global", "tools_dock_checked"); + resetDefaultConfig("global", "menu_bar_checked"); + resetDefaultConfig("global", "enable_compact_mode"); + + clearGroupOfSettings(m_sessionSettings, "geometry"); + + m_hasReset = true; +} + void VConfigManager::clearGroupOfSettings(QSettings *p_settings, const QString &p_group) { p_settings->beginGroup(p_group); diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index f959a79c..5aaec2d3 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -103,6 +103,9 @@ public: // Reset the configuratio files. void resetConfigurations(); + // Reset the layout. + void resetLayoutConfigurations(); + QFont getMdEditFont() const; QPalette getMdEditPalette() const;