diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index c56119deb..e1978ba5a 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -10,6 +10,8 @@ #include "state.hpp" #include "shortcutmanager.hpp" +#include + namespace CSMPrefs { const int ShortcutSetting::MaxKeys; diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 7a1889407..8657044b0 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -591,18 +591,16 @@ CSMPrefs::State& CSMPrefs::State::get() void CSMPrefs::State::resetCategory(const std::string& category) { + for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin(); + i != mSettings.mUserSettings.end(); ++i) { - QMutexLocker lock (&mMutex); - for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin(); i != mSettings.mUserSettings.end(); ++i) + // if the category matches + if (i->first.first == category) { - // if the category matches - if (i->first.first == category) - { - // mark the setting as changed - mSettings.mChangedSettings.insert(std::make_pair(i->first.first, i->first.second)); - // reset the value to the default - i->second = mSettings.mDefaultSettings[i->first]; - } + // mark the setting as changed + mSettings.mChangedSettings.insert(std::make_pair(i->first.first, i->first.second)); + // reset the value to the default + i->second = mSettings.mDefaultSettings[i->first]; } } diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index c70461874..81e6a4a52 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -16,35 +16,12 @@ namespace CSVPrefs { KeyBindingPage::KeyBindingPage(CSMPrefs::Category& category, QWidget* parent) : PageBase(category, parent) + , mTopWidget(0) , mStackedLayout(0) , mPageLayout(0) , mPageSelector(0) { - // Need one widget for scroll area - QWidget* topWidget = new QWidget(); - QVBoxLayout* topLayout = new QVBoxLayout(topWidget); - - QWidget* resetAll = new QPushButton("Reset all to default", this); - connect(resetAll, SIGNAL(clicked()), this, SLOT(resetCategory())); - topLayout->addWidget(resetAll); - - // Allows switching between "pages" - QWidget* stackedWidget = new QWidget(); - mStackedLayout = new QStackedLayout(stackedWidget); - - mPageSelector = new QComboBox(); - connect(mPageSelector, SIGNAL(currentIndexChanged(int)), mStackedLayout, SLOT(setCurrentIndex(int))); - - topLayout->addWidget(mPageSelector); - topLayout->addWidget(stackedWidget); - topLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); - - // Add each option - for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) - addSetting (*iter); - - setWidgetResizable(true); - setWidget(topWidget); + init(); } void KeyBindingPage::addSetting(CSMPrefs::Setting *setting) @@ -91,4 +68,41 @@ namespace CSVPrefs } } } + + void KeyBindingPage::refresh() + { + delete mTopWidget; + + // reinitialize + init(); + } + + void KeyBindingPage::init() + { + // Need one widget for scroll area + mTopWidget = new QWidget(); + QVBoxLayout* topLayout = new QVBoxLayout(mTopWidget); + + QWidget* resetAll = new QPushButton("Reset all to default", this); + connect(resetAll, SIGNAL(clicked()), this, SLOT(resetCategory())); + topLayout->addWidget(resetAll); + + // Allows switching between "pages" + QWidget* stackedWidget = new QWidget(); + mStackedLayout = new QStackedLayout(stackedWidget); + + mPageSelector = new QComboBox(); + connect(mPageSelector, SIGNAL(currentIndexChanged(int)), mStackedLayout, SLOT(setCurrentIndex(int))); + + topLayout->addWidget(mPageSelector); + topLayout->addWidget(stackedWidget); + topLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); + + // Add each option + for (CSMPrefs::Category::Iterator iter = getCategory().begin(); iter!=getCategory().end(); ++iter) + addSetting (*iter); + + setWidgetResizable(true); + setWidget(mTopWidget); + } } diff --git a/apps/opencs/view/prefs/keybindingpage.hpp b/apps/opencs/view/prefs/keybindingpage.hpp index 8a0cb2952..e00e460b3 100644 --- a/apps/opencs/view/prefs/keybindingpage.hpp +++ b/apps/opencs/view/prefs/keybindingpage.hpp @@ -3,6 +3,7 @@ #include "pagebase.hpp" +class QWidget; class QComboBox; class QGridLayout; class QStackedLayout; @@ -26,6 +27,11 @@ namespace CSVPrefs private: + void refresh(); + + void init(); + + QWidget* mTopWidget; QStackedLayout* mStackedLayout; QGridLayout* mPageLayout; QComboBox* mPageSelector; diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index 7d8644621..281d0d08b 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -10,18 +10,9 @@ CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) +, mParent (parent) { - QWidget *widget = new QWidget (parent); - mGrid = new QGridLayout (widget); - - QWidget* resetAll = new QPushButton("Reset all to default", this); - connect (resetAll, SIGNAL (clicked()), this, SLOT (resetCategory())); - mGrid->addWidget(resetAll, 0, 0, 1, 2); - - for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) - addSetting (*iter); - - setWidget (widget); + init(); } void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting) @@ -44,3 +35,26 @@ void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting) mGrid->addWidget (new QWidget (this), next, 0); } } + +void CSVPrefs::Page::refresh() +{ + delete mWidget; + + // reinitialize + init(); +} + +void CSVPrefs::Page::init() +{ + mWidget = new QWidget(mParent); + mGrid = new QGridLayout(mWidget); + + QWidget* resetAll = new QPushButton("Reset all to default", this); + connect(resetAll, SIGNAL(clicked()), this, SLOT(resetCategory())); + mGrid->addWidget(resetAll, 0, 0, 1, 2); + + for (CSMPrefs::Category::Iterator iter = getCategory().begin(); iter!=getCategory().end(); ++iter) + addSetting (*iter); + + setWidget(mWidget); +} diff --git a/apps/opencs/view/prefs/page.hpp b/apps/opencs/view/prefs/page.hpp index ce13e5d9b..58688bccd 100644 --- a/apps/opencs/view/prefs/page.hpp +++ b/apps/opencs/view/prefs/page.hpp @@ -4,6 +4,7 @@ #include "pagebase.hpp" class QGridLayout; +class QWidget; namespace CSMPrefs { @@ -17,12 +18,20 @@ namespace CSVPrefs Q_OBJECT QGridLayout *mGrid; + QWidget* mParent; + QWidget* mWidget; public: Page (CSMPrefs::Category& category, QWidget *parent); void addSetting (CSMPrefs::Setting *setting); + + private: + + void refresh(); + + void init(); }; } diff --git a/apps/opencs/view/prefs/pagebase.cpp b/apps/opencs/view/prefs/pagebase.cpp index 344360607..38fcc2a70 100644 --- a/apps/opencs/view/prefs/pagebase.cpp +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -16,4 +16,5 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory() void CSVPrefs::PageBase::resetCategory() { CSMPrefs::get().resetCategory(getCategory().getKey()); + refresh(); } diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index 1d83d64d2..ac291c4b5 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -2,6 +2,7 @@ #define CSV_PREFS_PAGEBASE_H #include +#include namespace CSMPrefs { @@ -25,6 +26,10 @@ namespace CSVPrefs public slots: void resetCategory(); + + private: + + virtual void refresh() {}; }; }