From 64879c03e4a6935c18cad45fefb04e23efce1e56 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sat, 6 May 2017 20:18:31 +1200 Subject: [PATCH 01/18] Add option to reset settings to default --- apps/opencs/model/prefs/state.cpp | 26 +++++++++++++++++++++++ apps/opencs/model/prefs/state.hpp | 2 ++ apps/opencs/view/prefs/keybindingpage.cpp | 6 ++++++ apps/opencs/view/prefs/page.cpp | 6 ++++++ apps/opencs/view/prefs/pagebase.cpp | 6 ++++++ apps/opencs/view/prefs/pagebase.hpp | 4 ++++ 6 files changed, 50 insertions(+) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 3921e32f2..7a1889407 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "intsetting.hpp" #include "doublesetting.hpp" #include "boolsetting.hpp" @@ -587,6 +589,30 @@ CSMPrefs::State& CSMPrefs::State::get() return *sThis; } +void CSMPrefs::State::resetCategory(const std::string& category) +{ + { + 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) + { + // 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]; + } + } + } + + Collection::iterator iter = mCategories.find(category); + if (iter != mCategories.end()) + { + (*iter).second.update(); + } +} + CSMPrefs::State& CSMPrefs::get() { diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index 1e46c68ee..1e0ac8c11 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -106,6 +106,8 @@ namespace CSMPrefs static State& get(); + void resetCategory(const std::string& category); + signals: void settingChanged (const CSMPrefs::Setting *setting); diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index 143665f4a..c70461874 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -6,9 +6,11 @@ #include #include #include +#include #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" namespace CSVPrefs { @@ -22,6 +24,10 @@ namespace CSVPrefs 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); diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index c23e9f64f..7d8644621 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -2,9 +2,11 @@ #include "page.hpp" #include +#include #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) @@ -12,6 +14,10 @@ CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *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); diff --git a/apps/opencs/view/prefs/pagebase.cpp b/apps/opencs/view/prefs/pagebase.cpp index 16684a69d..344360607 100644 --- a/apps/opencs/view/prefs/pagebase.cpp +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -2,6 +2,7 @@ #include "pagebase.hpp" #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent) : QScrollArea (parent), mCategory (category) @@ -11,3 +12,8 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory() { return mCategory; } + +void CSVPrefs::PageBase::resetCategory() +{ + CSMPrefs::get().resetCategory(getCategory().getKey()); +} diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index affe49f4a..1d83d64d2 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -21,6 +21,10 @@ namespace CSVPrefs PageBase (CSMPrefs::Category& category, QWidget *parent); CSMPrefs::Category& getCategory(); + + public slots: + + void resetCategory(); }; } From dff3828710a94b803ae4e7f615e9b934d1d5d52b Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sun, 7 May 2017 16:51:11 +1200 Subject: [PATCH 02/18] Keep the settings page in sync with the real settings --- apps/opencs/model/prefs/shortcutsetting.cpp | 2 + apps/opencs/model/prefs/state.cpp | 18 +++--- apps/opencs/view/prefs/keybindingpage.cpp | 64 +++++++++++++-------- apps/opencs/view/prefs/keybindingpage.hpp | 6 ++ apps/opencs/view/prefs/page.cpp | 36 ++++++++---- apps/opencs/view/prefs/page.hpp | 9 +++ apps/opencs/view/prefs/pagebase.cpp | 1 + apps/opencs/view/prefs/pagebase.hpp | 5 ++ 8 files changed, 95 insertions(+), 46 deletions(-) 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() {}; }; } From 5fca37d0c8d18b7bd440fb9b3e968f614883cd00 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sun, 7 May 2017 16:54:38 +1200 Subject: [PATCH 03/18] Forgot to remove debugging code --- apps/opencs/model/prefs/shortcutsetting.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index e1978ba5a..c56119deb 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -10,8 +10,6 @@ #include "state.hpp" #include "shortcutmanager.hpp" -#include - namespace CSMPrefs { const int ShortcutSetting::MaxKeys; From 418aeb65f16e0b2dfc26d26a2813f24c60642978 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sun, 7 May 2017 16:58:15 +1200 Subject: [PATCH 04/18] Remove unneeded dependencies --- apps/opencs/model/prefs/state.cpp | 2 -- apps/opencs/view/prefs/keybindingpage.cpp | 1 - apps/opencs/view/prefs/page.cpp | 1 - 3 files changed, 4 deletions(-) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 8657044b0..9ce368aa0 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -5,8 +5,6 @@ #include #include -#include - #include "intsetting.hpp" #include "doublesetting.hpp" #include "boolsetting.hpp" diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index 81e6a4a52..8b2694fb0 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -10,7 +10,6 @@ #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" -#include "../../model/prefs/state.hpp" namespace CSVPrefs { diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index 281d0d08b..77d4f60f3 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -6,7 +6,6 @@ #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" -#include "../../model/prefs/state.hpp" CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) From 477af73ad6f46f46ae85ab42e557b2f1b175940c Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sun, 7 May 2017 17:00:26 +1200 Subject: [PATCH 05/18] Missed another one --- apps/opencs/view/prefs/pagebase.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index ac291c4b5..9632890fa 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -2,7 +2,6 @@ #define CSV_PREFS_PAGEBASE_H #include -#include namespace CSMPrefs { From d8a711f89f044872cf0a8086ea6bb2c6a15cb5fb Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sun, 7 May 2017 17:05:50 +1200 Subject: [PATCH 06/18] Fix tabs --- apps/opencs/view/prefs/pagebase.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index 9632890fa..c85fd3e11 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -21,10 +21,10 @@ namespace CSVPrefs PageBase (CSMPrefs::Category& category, QWidget *parent); CSMPrefs::Category& getCategory(); - - public slots: - - void resetCategory(); + + public slots: + + void resetCategory(); private: From a9760ec80566533cbaf1607577a206580c093403 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Sun, 7 May 2017 17:07:58 +1200 Subject: [PATCH 07/18] Fix indenting --- apps/opencs/view/prefs/pagebase.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index c85fd3e11..43dfd42fa 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -22,7 +22,7 @@ namespace CSVPrefs CSMPrefs::Category& getCategory(); - public slots: + public slots: void resetCategory(); From f30d1a30753140ef1763d54087aa7a30c3932182 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Mon, 8 May 2017 17:24:28 +1200 Subject: [PATCH 08/18] Revert everything --- apps/opencs/model/prefs/state.cpp | 22 -------- apps/opencs/model/prefs/state.hpp | 2 - apps/opencs/view/prefs/keybindingpage.cpp | 61 ++++++++--------------- apps/opencs/view/prefs/keybindingpage.hpp | 6 --- apps/opencs/view/prefs/page.cpp | 33 +++--------- apps/opencs/view/prefs/page.hpp | 9 ---- apps/opencs/view/prefs/pagebase.cpp | 7 --- apps/opencs/view/prefs/pagebase.hpp | 8 --- 8 files changed, 28 insertions(+), 120 deletions(-) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 9ce368aa0..3921e32f2 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -587,28 +587,6 @@ CSMPrefs::State& CSMPrefs::State::get() return *sThis; } -void CSMPrefs::State::resetCategory(const std::string& category) -{ - for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin(); - i != mSettings.mUserSettings.end(); ++i) - { - // 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]; - } - } - - Collection::iterator iter = mCategories.find(category); - if (iter != mCategories.end()) - { - (*iter).second.update(); - } -} - CSMPrefs::State& CSMPrefs::get() { diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index 1e0ac8c11..1e46c68ee 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -106,8 +106,6 @@ namespace CSMPrefs static State& get(); - void resetCategory(const std::string& category); - signals: void settingChanged (const CSMPrefs::Setting *setting); diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index 8b2694fb0..143665f4a 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" @@ -15,12 +14,31 @@ namespace CSVPrefs { KeyBindingPage::KeyBindingPage(CSMPrefs::Category& category, QWidget* parent) : PageBase(category, parent) - , mTopWidget(0) , mStackedLayout(0) , mPageLayout(0) , mPageSelector(0) { - init(); + // Need one widget for scroll area + QWidget* topWidget = new QWidget(); + QVBoxLayout* topLayout = new QVBoxLayout(topWidget); + + // 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); } void KeyBindingPage::addSetting(CSMPrefs::Setting *setting) @@ -67,41 +85,4 @@ 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 e00e460b3..8a0cb2952 100644 --- a/apps/opencs/view/prefs/keybindingpage.hpp +++ b/apps/opencs/view/prefs/keybindingpage.hpp @@ -3,7 +3,6 @@ #include "pagebase.hpp" -class QWidget; class QComboBox; class QGridLayout; class QStackedLayout; @@ -27,11 +26,6 @@ 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 77d4f60f3..c23e9f64f 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -2,16 +2,20 @@ #include "page.hpp" #include -#include #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) -, mParent (parent) { - init(); + QWidget *widget = new QWidget (parent); + mGrid = new QGridLayout (widget); + + for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) + addSetting (*iter); + + setWidget (widget); } void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting) @@ -34,26 +38,3 @@ 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 58688bccd..ce13e5d9b 100644 --- a/apps/opencs/view/prefs/page.hpp +++ b/apps/opencs/view/prefs/page.hpp @@ -4,7 +4,6 @@ #include "pagebase.hpp" class QGridLayout; -class QWidget; namespace CSMPrefs { @@ -18,20 +17,12 @@ 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 38fcc2a70..16684a69d 100644 --- a/apps/opencs/view/prefs/pagebase.cpp +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -2,7 +2,6 @@ #include "pagebase.hpp" #include "../../model/prefs/category.hpp" -#include "../../model/prefs/state.hpp" CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent) : QScrollArea (parent), mCategory (category) @@ -12,9 +11,3 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory() { return mCategory; } - -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 43dfd42fa..affe49f4a 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -21,14 +21,6 @@ namespace CSVPrefs PageBase (CSMPrefs::Category& category, QWidget *parent); CSMPrefs::Category& getCategory(); - - public slots: - - void resetCategory(); - - private: - - virtual void refresh() {}; }; } From 3545cfa00aacb4c487bc1c6a5c0ed48c9c6a99f6 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Tue, 9 May 2017 19:50:16 +1200 Subject: [PATCH 09/18] Rewrite feature to reset options to default --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/prefs/boolsetting.cpp | 22 ++++++++---- apps/opencs/model/prefs/boolsetting.hpp | 5 +++ apps/opencs/model/prefs/coloursetting.cpp | 20 ++++++++--- apps/opencs/model/prefs/coloursetting.hpp | 8 +++++ apps/opencs/model/prefs/doublesetting.cpp | 24 ++++++++----- apps/opencs/model/prefs/doublesetting.hpp | 5 +++ apps/opencs/model/prefs/enumsetting.cpp | 26 ++++++++++---- apps/opencs/model/prefs/enumsetting.hpp | 5 +++ apps/opencs/model/prefs/intsetting.cpp | 22 ++++++++---- apps/opencs/model/prefs/intsetting.hpp | 5 +++ apps/opencs/model/prefs/modifiersetting.cpp | 13 +++++++ apps/opencs/model/prefs/modifiersetting.hpp | 2 ++ apps/opencs/model/prefs/setting.cpp | 4 +++ apps/opencs/model/prefs/setting.hpp | 5 +++ apps/opencs/model/prefs/shortcutsetting.cpp | 14 ++++++++ apps/opencs/model/prefs/shortcutsetting.hpp | 2 ++ apps/opencs/model/prefs/state.cpp | 35 +++++++++++++++++++ apps/opencs/model/prefs/state.hpp | 4 +++ apps/opencs/view/prefs/contextmenulist.cpp | 32 +++++++++++++++++ apps/opencs/view/prefs/contextmenulist.hpp | 30 ++++++++++++++++ apps/opencs/view/prefs/contextmenuwidget.cpp | 33 ++++++++++++++++++ apps/opencs/view/prefs/contextmenuwidget.hpp | 36 ++++++++++++++++++++ apps/opencs/view/prefs/dialogue.cpp | 17 ++++----- apps/opencs/view/prefs/dialogue.hpp | 1 - apps/opencs/view/prefs/page.cpp | 3 +- 26 files changed, 331 insertions(+), 44 deletions(-) create mode 100644 apps/opencs/view/prefs/contextmenulist.cpp create mode 100644 apps/opencs/view/prefs/contextmenulist.hpp create mode 100644 apps/opencs/view/prefs/contextmenuwidget.cpp create mode 100644 apps/opencs/view/prefs/contextmenuwidget.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 8a3d3c1c8..d04259b38 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -110,7 +110,7 @@ opencs_units_noqt (view/tools ) opencs_units (view/prefs - dialogue pagebase page keybindingpage + dialogue pagebase page keybindingpage contextmenulist contextmenuwidget ) opencs_units (model/prefs diff --git a/apps/opencs/model/prefs/boolsetting.cpp b/apps/opencs/model/prefs/boolsetting.cpp index 6c0babaf7..6431dc6af 100644 --- a/apps/opencs/model/prefs/boolsetting.cpp +++ b/apps/opencs/model/prefs/boolsetting.cpp @@ -11,7 +11,7 @@ CSMPrefs::BoolSetting::BoolSetting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label, bool default_) -: Setting (parent, values, mutex, key, label), mDefault (default_) +: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(0) {} CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& tooltip) @@ -22,18 +22,28 @@ CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& too std::pair CSMPrefs::BoolSetting::makeWidgets (QWidget *parent) { - QCheckBox *widget = new QCheckBox (QString::fromUtf8 (getLabel().c_str()), parent); - widget->setCheckState (mDefault ? Qt::Checked : Qt::Unchecked); + mWidget = new QCheckBox (QString::fromUtf8 (getLabel().c_str()), parent); + mWidget->setCheckState (mDefault ? Qt::Checked : Qt::Unchecked); if (!mTooltip.empty()) { QString tooltip = QString::fromUtf8 (mTooltip.c_str()); - widget->setToolTip (tooltip); + mWidget->setToolTip (tooltip); } - connect (widget, SIGNAL (stateChanged (int)), this, SLOT (valueChanged (int))); + connect (mWidget, SIGNAL (stateChanged (int)), this, SLOT (valueChanged (int))); - return std::make_pair (static_cast (0), widget); + return std::make_pair (static_cast (0), mWidget); +} + +void CSMPrefs::BoolSetting::updateWidget() +{ + if (mWidget) + { + mWidget->setCheckState(getValues().getBool(getKey(), getParent()->getKey()) + ? Qt::Checked + : Qt::Unchecked); + } } void CSMPrefs::BoolSetting::valueChanged (int value) diff --git a/apps/opencs/model/prefs/boolsetting.hpp b/apps/opencs/model/prefs/boolsetting.hpp index f8a321859..37c018d14 100644 --- a/apps/opencs/model/prefs/boolsetting.hpp +++ b/apps/opencs/model/prefs/boolsetting.hpp @@ -3,6 +3,8 @@ #include "setting.hpp" +class QCheckBox; + namespace CSMPrefs { class BoolSetting : public Setting @@ -11,6 +13,7 @@ namespace CSMPrefs std::string mTooltip; bool mDefault; + QCheckBox* mWidget; public: @@ -22,6 +25,8 @@ namespace CSMPrefs /// Return label, input widget. virtual std::pair makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (int value); diff --git a/apps/opencs/model/prefs/coloursetting.cpp b/apps/opencs/model/prefs/coloursetting.cpp index d51bfad56..1a41621da 100644 --- a/apps/opencs/model/prefs/coloursetting.cpp +++ b/apps/opencs/model/prefs/coloursetting.cpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -13,7 +14,7 @@ CSMPrefs::ColourSetting::ColourSetting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label, QColor default_) -: Setting (parent, values, mutex, key, label), mDefault (default_) +: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(0) {} CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip (const std::string& tooltip) @@ -26,18 +27,27 @@ std::pair CSMPrefs::ColourSetting::makeWidgets (QWidget *p { QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent); - CSVWidget::ColorEditor *widget = new CSVWidget::ColorEditor (mDefault, parent); + mWidget = new CSVWidget::ColorEditor (mDefault, parent); if (!mTooltip.empty()) { QString tooltip = QString::fromUtf8 (mTooltip.c_str()); label->setToolTip (tooltip); - widget->setToolTip (tooltip); + mWidget->setToolTip (tooltip); } - connect (widget, SIGNAL (pickingFinished()), this, SLOT (valueChanged())); + connect (mWidget, SIGNAL (pickingFinished()), this, SLOT (valueChanged())); - return std::make_pair (label, widget); + return std::make_pair (label, mWidget); +} + +void CSMPrefs::ColourSetting::updateWidget() +{ + if (mWidget) + { + mWidget->setColor(QString::fromStdString + (getValues().getString(getKey(), getParent()->getKey()))); + } } void CSMPrefs::ColourSetting::valueChanged() diff --git a/apps/opencs/model/prefs/coloursetting.hpp b/apps/opencs/model/prefs/coloursetting.hpp index be58426f2..e892b21d6 100644 --- a/apps/opencs/model/prefs/coloursetting.hpp +++ b/apps/opencs/model/prefs/coloursetting.hpp @@ -5,6 +5,11 @@ #include +namespace CSVWidget +{ + class ColorEditor; +} + namespace CSMPrefs { class ColourSetting : public Setting @@ -13,6 +18,7 @@ namespace CSMPrefs std::string mTooltip; QColor mDefault; + CSVWidget::ColorEditor* mWidget; public: @@ -25,6 +31,8 @@ namespace CSMPrefs /// Return label, input widget. virtual std::pair makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged(); diff --git a/apps/opencs/model/prefs/doublesetting.cpp b/apps/opencs/model/prefs/doublesetting.cpp index 531196174..8ae6f4818 100644 --- a/apps/opencs/model/prefs/doublesetting.cpp +++ b/apps/opencs/model/prefs/doublesetting.cpp @@ -16,7 +16,7 @@ CSMPrefs::DoubleSetting::DoubleSetting (Category *parent, Settings::Manager *val QMutex *mutex, const std::string& key, const std::string& label, double default_) : Setting (parent, values, mutex, key, label), mPrecision(2), mMin (0), mMax (std::numeric_limits::max()), - mDefault (default_) + mDefault (default_), mWidget(0) {} CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setPrecision(int precision) @@ -54,21 +54,29 @@ std::pair CSMPrefs::DoubleSetting::makeWidgets (QWidget *p { QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent); - QDoubleSpinBox *widget = new QDoubleSpinBox (parent); - widget->setDecimals(mPrecision); - widget->setRange (mMin, mMax); - widget->setValue (mDefault); + mWidget = new QDoubleSpinBox (parent); + mWidget->setDecimals(mPrecision); + mWidget->setRange (mMin, mMax); + mWidget->setValue (mDefault); if (!mTooltip.empty()) { QString tooltip = QString::fromUtf8 (mTooltip.c_str()); label->setToolTip (tooltip); - widget->setToolTip (tooltip); + mWidget->setToolTip (tooltip); } - connect (widget, SIGNAL (valueChanged (double)), this, SLOT (valueChanged (double))); + connect (mWidget, SIGNAL (valueChanged (double)), this, SLOT (valueChanged (double))); - return std::make_pair (label, widget); + return std::make_pair (label, mWidget); +} + +void CSMPrefs::DoubleSetting::updateWidget() +{ + if (mWidget) + { + mWidget->setValue(getValues().getFloat(getKey(), getParent()->getKey())); + } } void CSMPrefs::DoubleSetting::valueChanged (double value) diff --git a/apps/opencs/model/prefs/doublesetting.hpp b/apps/opencs/model/prefs/doublesetting.hpp index 8fd345f4d..4d297409b 100644 --- a/apps/opencs/model/prefs/doublesetting.hpp +++ b/apps/opencs/model/prefs/doublesetting.hpp @@ -3,6 +3,8 @@ #include "setting.hpp" +class QDoubleSpinBox; + namespace CSMPrefs { class DoubleSetting : public Setting @@ -14,6 +16,7 @@ namespace CSMPrefs double mMax; std::string mTooltip; double mDefault; + QDoubleSpinBox* mWidget; public: @@ -35,6 +38,8 @@ namespace CSMPrefs /// Return label, input widget. virtual std::pair makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (double value); diff --git a/apps/opencs/model/prefs/enumsetting.cpp b/apps/opencs/model/prefs/enumsetting.cpp index e69f717ea..901bbf8e4 100644 --- a/apps/opencs/model/prefs/enumsetting.cpp +++ b/apps/opencs/model/prefs/enumsetting.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -41,7 +42,7 @@ CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const std::string& value, const CSMPrefs::EnumSetting::EnumSetting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label, const EnumValue& default_) -: Setting (parent, values, mutex, key, label), mDefault (default_) +: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget() {} CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip) @@ -72,7 +73,7 @@ std::pair CSMPrefs::EnumSetting::makeWidgets (QWidget *par { QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent); - QComboBox *widget = new QComboBox (parent); + mWidget = new QComboBox (parent); int index = 0; @@ -81,14 +82,14 @@ std::pair CSMPrefs::EnumSetting::makeWidgets (QWidget *par if (mDefault.mValue==mValues.mValues[i].mValue) index = i; - widget->addItem (QString::fromUtf8 (mValues.mValues[i].mValue.c_str())); + mWidget->addItem (QString::fromUtf8 (mValues.mValues[i].mValue.c_str())); if (!mValues.mValues[i].mTooltip.empty()) - widget->setItemData (i, QString::fromUtf8 (mValues.mValues[i].mTooltip.c_str()), + mWidget->setItemData (i, QString::fromUtf8 (mValues.mValues[i].mTooltip.c_str()), Qt::ToolTipRole); } - widget->setCurrentIndex (index); + mWidget->setCurrentIndex (index); if (!mTooltip.empty()) { @@ -96,9 +97,20 @@ std::pair CSMPrefs::EnumSetting::makeWidgets (QWidget *par label->setToolTip (tooltip); } - connect (widget, SIGNAL (currentIndexChanged (int)), this, SLOT (valueChanged (int))); + connect (mWidget, SIGNAL (currentIndexChanged (int)), this, SLOT (valueChanged (int))); - return std::make_pair (label, widget); + return std::make_pair (label, mWidget); +} + +void CSMPrefs::EnumSetting::updateWidget() +{ + if (mWidget) + { + int index = mWidget->findText(QString::fromStdString + (getValues().getString(getKey(), getParent()->getKey()))); + + mWidget->setCurrentIndex(index); + } } void CSMPrefs::EnumSetting::valueChanged (int value) diff --git a/apps/opencs/model/prefs/enumsetting.hpp b/apps/opencs/model/prefs/enumsetting.hpp index 728de3acd..b01635cdf 100644 --- a/apps/opencs/model/prefs/enumsetting.hpp +++ b/apps/opencs/model/prefs/enumsetting.hpp @@ -5,6 +5,8 @@ #include "setting.hpp" +class QComboBox; + namespace CSMPrefs { struct EnumValue @@ -35,6 +37,7 @@ namespace CSMPrefs std::string mTooltip; EnumValue mDefault; EnumValues mValues; + QComboBox* mWidget; public: @@ -53,6 +56,8 @@ namespace CSMPrefs /// Return label, input widget. virtual std::pair makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (int value); diff --git a/apps/opencs/model/prefs/intsetting.cpp b/apps/opencs/model/prefs/intsetting.cpp index 269a63af4..25dbf78c2 100644 --- a/apps/opencs/model/prefs/intsetting.cpp +++ b/apps/opencs/model/prefs/intsetting.cpp @@ -15,7 +15,7 @@ CSMPrefs::IntSetting::IntSetting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label, int default_) : Setting (parent, values, mutex, key, label), mMin (0), mMax (std::numeric_limits::max()), - mDefault (default_) + mDefault (default_), mWidget(0) {} CSMPrefs::IntSetting& CSMPrefs::IntSetting::setRange (int min, int max) @@ -47,20 +47,28 @@ std::pair CSMPrefs::IntSetting::makeWidgets (QWidget *pare { QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent); - QSpinBox *widget = new QSpinBox (parent); - widget->setRange (mMin, mMax); - widget->setValue (mDefault); + mWidget = new QSpinBox (parent); + mWidget->setRange (mMin, mMax); + mWidget->setValue (mDefault); if (!mTooltip.empty()) { QString tooltip = QString::fromUtf8 (mTooltip.c_str()); label->setToolTip (tooltip); - widget->setToolTip (tooltip); + mWidget->setToolTip (tooltip); } - connect (widget, SIGNAL (valueChanged (int)), this, SLOT (valueChanged (int))); + connect (mWidget, SIGNAL (valueChanged (int)), this, SLOT (valueChanged (int))); - return std::make_pair (label, widget); + return std::make_pair (label, mWidget); +} + +void CSMPrefs::IntSetting::updateWidget() +{ + if (mWidget) + { + mWidget->setValue(getValues().getInt(getKey(), getParent()->getKey())); + } } void CSMPrefs::IntSetting::valueChanged (int value) diff --git a/apps/opencs/model/prefs/intsetting.hpp b/apps/opencs/model/prefs/intsetting.hpp index 0ee6cf9e3..ee0989d83 100644 --- a/apps/opencs/model/prefs/intsetting.hpp +++ b/apps/opencs/model/prefs/intsetting.hpp @@ -3,6 +3,8 @@ #include "setting.hpp" +class QSpinBox; + namespace CSMPrefs { class IntSetting : public Setting @@ -13,6 +15,7 @@ namespace CSMPrefs int mMax; std::string mTooltip; int mDefault; + QSpinBox* mWidget; public: @@ -31,6 +34,8 @@ namespace CSMPrefs /// Return label, input widget. virtual std::pair makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (int value); diff --git a/apps/opencs/model/prefs/modifiersetting.cpp b/apps/opencs/model/prefs/modifiersetting.cpp index 4f4fac248..b70d39714 100644 --- a/apps/opencs/model/prefs/modifiersetting.cpp +++ b/apps/opencs/model/prefs/modifiersetting.cpp @@ -39,6 +39,19 @@ namespace CSMPrefs return std::make_pair(label, widget); } + void ModifierSetting::updateWidget() + { + if (mButton) + { + std::string shortcut = getValues().getString(getKey(), getParent()->getKey()); + + int modifier; + State::get().getShortcutManager().convertFromString(shortcut, modifier); + State::get().getShortcutManager().setModifier(getKey(), modifier); + resetState(); + } + } + bool ModifierSetting::eventFilter(QObject* target, QEvent* event) { if (event->type() == QEvent::KeyPress) diff --git a/apps/opencs/model/prefs/modifiersetting.hpp b/apps/opencs/model/prefs/modifiersetting.hpp index 95983f66d..2c6a45b5a 100644 --- a/apps/opencs/model/prefs/modifiersetting.hpp +++ b/apps/opencs/model/prefs/modifiersetting.hpp @@ -21,6 +21,8 @@ namespace CSMPrefs virtual std::pair makeWidgets(QWidget* parent); + virtual void updateWidget(); + protected: bool eventFilter(QObject* target, QEvent* event); diff --git a/apps/opencs/model/prefs/setting.cpp b/apps/opencs/model/prefs/setting.cpp index 75b58322d..165062232 100644 --- a/apps/opencs/model/prefs/setting.cpp +++ b/apps/opencs/model/prefs/setting.cpp @@ -30,6 +30,10 @@ std::pair CSMPrefs::Setting::makeWidgets (QWidget *parent) return std::pair (0, 0); } +void CSMPrefs::Setting::updateWidget() +{ +} + const CSMPrefs::Category *CSMPrefs::Setting::getParent() const { return mParent; diff --git a/apps/opencs/model/prefs/setting.hpp b/apps/opencs/model/prefs/setting.hpp index 00bcc638b..7cb2d7acf 100644 --- a/apps/opencs/model/prefs/setting.hpp +++ b/apps/opencs/model/prefs/setting.hpp @@ -47,6 +47,11 @@ namespace CSMPrefs /// widget. virtual std::pair makeWidgets (QWidget *parent); + /// Updates the widget returned by makeWidgets() to the current setting. + /// + /// \note If make_widgets() has not been called yet then nothing happens. + virtual void updateWidget(); + const Category *getParent() const; const std::string& getKey() const; diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index c56119deb..418559475 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "state.hpp" #include "shortcutmanager.hpp" @@ -46,6 +47,19 @@ namespace CSMPrefs return std::make_pair(label, widget); } + void ShortcutSetting::updateWidget() + { + if (mButton) + { + std::string shortcut = getValues().getString(getKey(), getParent()->getKey()); + + QKeySequence sequence; + State::get().getShortcutManager().convertFromString(shortcut, sequence); + State::get().getShortcutManager().setSequence(getKey(), sequence); + resetState(); + } + } + bool ShortcutSetting::eventFilter(QObject* target, QEvent* event) { if (event->type() == QEvent::KeyPress) diff --git a/apps/opencs/model/prefs/shortcutsetting.hpp b/apps/opencs/model/prefs/shortcutsetting.hpp index bb38b580a..c388305a6 100644 --- a/apps/opencs/model/prefs/shortcutsetting.hpp +++ b/apps/opencs/model/prefs/shortcutsetting.hpp @@ -21,6 +21,8 @@ namespace CSMPrefs virtual std::pair makeWidgets(QWidget* parent); + virtual void updateWidget(); + protected: bool eventFilter(QObject* target, QEvent* event); diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 3921e32f2..618a4bfc9 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -587,6 +587,41 @@ CSMPrefs::State& CSMPrefs::State::get() return *sThis; } +void CSMPrefs::State::resetCategory(const std::string& category) +{ + for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin(); + i != mSettings.mUserSettings.end(); ++i) + { + // 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]; + } + } + + Collection::iterator container = mCategories.find(category); + if (container != mCategories.end()) + { + Category settings = container->second; + for (Category::Iterator i = settings.begin(); i != settings.end(); ++i) + { + (*i)->updateWidget(); + update(**i); + } + } +} + +void CSMPrefs::State::resetAll() +{ + for (Collection::iterator iter = mCategories.begin(); iter != mCategories.end(); ++iter) + { + resetCategory(iter->first); + } +} + CSMPrefs::State& CSMPrefs::get() { diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index 1e46c68ee..a32583dc5 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -106,6 +106,10 @@ namespace CSMPrefs static State& get(); + void resetCategory(const std::string& category); + + void resetAll(); + signals: void settingChanged (const CSMPrefs::Setting *setting); diff --git a/apps/opencs/view/prefs/contextmenulist.cpp b/apps/opencs/view/prefs/contextmenulist.cpp new file mode 100644 index 000000000..71527d8c6 --- /dev/null +++ b/apps/opencs/view/prefs/contextmenulist.cpp @@ -0,0 +1,32 @@ +#include "contextmenulist.hpp" + +#include +#include + +#include "../../model/prefs/state.hpp" + +CSVPrefs::ContextMenuList::ContextMenuList(QWidget* parent) + :QListWidget(parent) +{ +} + +void CSVPrefs::ContextMenuList::contextMenuEvent(QContextMenuEvent* e) +{ + QMenu* menu = new QMenu(); + + menu->addAction("Reset category to default", this, SLOT(resetCategory())); + menu->addAction("Reset all to default", this, SLOT(resetAll())); + + menu->exec(e->globalPos()); + delete menu; +} + +void CSVPrefs::ContextMenuList::resetCategory() +{ + CSMPrefs::State::get().resetCategory(currentItem()->text().toStdString()); +} + +void CSVPrefs::ContextMenuList::resetAll() +{ + CSMPrefs::State::get().resetAll(); +} diff --git a/apps/opencs/view/prefs/contextmenulist.hpp b/apps/opencs/view/prefs/contextmenulist.hpp new file mode 100644 index 000000000..222cfea6b --- /dev/null +++ b/apps/opencs/view/prefs/contextmenulist.hpp @@ -0,0 +1,30 @@ +#ifndef CSV_PREFS_CONTEXTMENULIST_H +#define CSV_PREFS_CONTEXTMENULIST_H + +#include + +class QContextMenuEvent; + +namespace CSVPrefs +{ + class ContextMenuList : public QListWidget + { + Q_OBJECT + + public: + + ContextMenuList(QWidget* parent = 0); + + protected: + + void contextMenuEvent(QContextMenuEvent* e); + + private slots: + + void resetCategory(); + + void resetAll(); + }; +} + +#endif diff --git a/apps/opencs/view/prefs/contextmenuwidget.cpp b/apps/opencs/view/prefs/contextmenuwidget.cpp new file mode 100644 index 000000000..abf3d6edc --- /dev/null +++ b/apps/opencs/view/prefs/contextmenuwidget.cpp @@ -0,0 +1,33 @@ +#include "contextmenuwidget.hpp" + +#include +#include + +#include "../../model/prefs/state.hpp" + +CSVPrefs::ContextMenuWidget::ContextMenuWidget(QWidget* parent, const std::string& category) + :QWidget(parent) + ,mCategory(category) +{ +} + +void CSVPrefs::ContextMenuWidget::contextMenuEvent(QContextMenuEvent* e) +{ + QMenu* menu = new QMenu(); + + menu->addAction("Reset category to default", this, SLOT(resetCategory())); + menu->addAction("Reset all to default", this, SLOT(resetAll())); + + menu->exec(e->globalPos()); + delete menu; +} + +void CSVPrefs::ContextMenuWidget::resetCategory() +{ + CSMPrefs::State::get().resetCategory(mCategory); +} + +void CSVPrefs::ContextMenuWidget::resetAll() +{ + CSMPrefs::State::get().resetAll(); +} diff --git a/apps/opencs/view/prefs/contextmenuwidget.hpp b/apps/opencs/view/prefs/contextmenuwidget.hpp new file mode 100644 index 000000000..0d8d5006c --- /dev/null +++ b/apps/opencs/view/prefs/contextmenuwidget.hpp @@ -0,0 +1,36 @@ +#ifndef CSV_PREFS_CONTEXTMENUWIDGET_H +#define CSV_PREFS_CONTEXTMENUWIDGET_H + +#include + +#include + +class QContextMenuEvent; + +namespace CSVPrefs +{ + class ContextMenuWidget : public QWidget + { + Q_OBJECT + + public: + + ContextMenuWidget(QWidget* parent, const std::string& category); + + protected: + + void contextMenuEvent(QContextMenuEvent* e); + + private slots: + + void resetCategory(); + + void resetAll(); + + private: + + std::string mCategory; + }; +} + +#endif diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index 6848bcaba..7f901c470 100644 --- a/apps/opencs/view/prefs/dialogue.cpp +++ b/apps/opencs/view/prefs/dialogue.cpp @@ -12,16 +12,17 @@ #include "page.hpp" #include "keybindingpage.hpp" +#include "contextmenulist.hpp" void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) { - mList = new QListWidget (main); - mList->setMinimumWidth (50); - mList->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); + CSVPrefs::ContextMenuList* list = new CSVPrefs::ContextMenuList (main); + list->setMinimumWidth (50); + list->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); - mList->setSelectionBehavior (QAbstractItemView::SelectItems); + list->setSelectionBehavior (QAbstractItemView::SelectItems); - main->addWidget (mList); + main->addWidget (list); QFontMetrics metrics (QApplication::font()); @@ -33,12 +34,12 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) QString label = QString::fromUtf8 (iter->second.getKey().c_str()); maxWidth = std::max (maxWidth, metrics.width (label)); - mList->addItem (label); + list->addItem (label); } - mList->setMaximumWidth (maxWidth + 10); + list->setMaximumWidth (maxWidth + 10); - connect (mList, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)), + connect (list, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)), this, SLOT (selectionChanged (QListWidgetItem *, QListWidgetItem *))); } diff --git a/apps/opencs/view/prefs/dialogue.hpp b/apps/opencs/view/prefs/dialogue.hpp index fc66892c8..ce017209a 100644 --- a/apps/opencs/view/prefs/dialogue.hpp +++ b/apps/opencs/view/prefs/dialogue.hpp @@ -16,7 +16,6 @@ namespace CSVPrefs { Q_OBJECT - QListWidget *mList; QStackedWidget *mContent; private: diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index c23e9f64f..c2098af44 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -5,11 +5,12 @@ #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" +#include "../../view/prefs/contextmenuwidget.hpp" CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) { - QWidget *widget = new QWidget (parent); + CSVPrefs::ContextMenuWidget *widget = new CSVPrefs::ContextMenuWidget (parent, category.getKey()); mGrid = new QGridLayout (widget); for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) From 487940509734f015065ee044f020bbfb810470a4 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Tue, 9 May 2017 19:58:34 +1200 Subject: [PATCH 10/18] Add reset context menu for key binding pages --- apps/opencs/view/prefs/contextmenuwidget.cpp | 2 +- apps/opencs/view/prefs/contextmenuwidget.hpp | 2 +- apps/opencs/view/prefs/keybindingpage.cpp | 3 ++- apps/opencs/view/prefs/page.cpp | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/prefs/contextmenuwidget.cpp b/apps/opencs/view/prefs/contextmenuwidget.cpp index abf3d6edc..bb1984e9a 100644 --- a/apps/opencs/view/prefs/contextmenuwidget.cpp +++ b/apps/opencs/view/prefs/contextmenuwidget.cpp @@ -5,7 +5,7 @@ #include "../../model/prefs/state.hpp" -CSVPrefs::ContextMenuWidget::ContextMenuWidget(QWidget* parent, const std::string& category) +CSVPrefs::ContextMenuWidget::ContextMenuWidget(const std::string& category, QWidget* parent) :QWidget(parent) ,mCategory(category) { diff --git a/apps/opencs/view/prefs/contextmenuwidget.hpp b/apps/opencs/view/prefs/contextmenuwidget.hpp index 0d8d5006c..57c231fb6 100644 --- a/apps/opencs/view/prefs/contextmenuwidget.hpp +++ b/apps/opencs/view/prefs/contextmenuwidget.hpp @@ -15,7 +15,7 @@ namespace CSVPrefs public: - ContextMenuWidget(QWidget* parent, const std::string& category); + ContextMenuWidget(const std::string& category, QWidget* parent = 0); protected: diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index 143665f4a..d7756f7c8 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -9,6 +9,7 @@ #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" +#include "../../view/prefs/contextmenuwidget.hpp" namespace CSVPrefs { @@ -19,7 +20,7 @@ namespace CSVPrefs , mPageSelector(0) { // Need one widget for scroll area - QWidget* topWidget = new QWidget(); + CSVPrefs::ContextMenuWidget* topWidget = new CSVPrefs::ContextMenuWidget(category.getKey()); QVBoxLayout* topLayout = new QVBoxLayout(topWidget); // Allows switching between "pages" diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index c2098af44..cc9b94a04 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -10,7 +10,7 @@ CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) { - CSVPrefs::ContextMenuWidget *widget = new CSVPrefs::ContextMenuWidget (parent, category.getKey()); + CSVPrefs::ContextMenuWidget *widget = new CSVPrefs::ContextMenuWidget (category.getKey(), parent); mGrid = new QGridLayout (widget); for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) From 30af92f575486d194bab73b1c5491affb462fe61 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Tue, 9 May 2017 20:58:32 +1200 Subject: [PATCH 11/18] Fix pointer initialisation bug --- apps/opencs/model/prefs/enumsetting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/prefs/enumsetting.cpp b/apps/opencs/model/prefs/enumsetting.cpp index 901bbf8e4..226b17173 100644 --- a/apps/opencs/model/prefs/enumsetting.cpp +++ b/apps/opencs/model/prefs/enumsetting.cpp @@ -42,7 +42,7 @@ CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const std::string& value, const CSMPrefs::EnumSetting::EnumSetting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label, const EnumValue& default_) -: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget() +: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(0) {} CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip) From bd9f657603ea50c565ff250e4fc12ba5f269cce5 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Wed, 10 May 2017 19:51:43 +1200 Subject: [PATCH 12/18] Show context menu when user clicks on empty space --- apps/opencs/view/prefs/page.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index cc9b94a04..418f07ac8 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -16,6 +16,15 @@ CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) addSetting (*iter); + // HACK to get widget to consume all available page space so context menu clicks + // will trigger, but so that setting widgets still only take up the left hand side + QWidget* emptyColumn = new QWidget(); + mGrid->addWidget(emptyColumn, 0, 2, -1, 1); + QWidget* emptyRow = new QWidget(); + emptyRow->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding); + mGrid->addWidget(emptyRow, mGrid->rowCount(), 0, 1, -1); + + setWidgetResizable(true); setWidget (widget); } From 646ff72cdcc3ea5512e22ce979de5e0366e5075e Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Wed, 10 May 2017 20:27:50 +1200 Subject: [PATCH 13/18] Add a more elegant way of showing the context menu --- apps/opencs/view/prefs/page.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index 418f07ac8..09191a436 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -10,22 +10,20 @@ CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) { - CSVPrefs::ContextMenuWidget *widget = new CSVPrefs::ContextMenuWidget (category.getKey(), parent); + // topWidget can expand while widget stays the same size + // This is so the context menu triggers over the entire page + // but the user interface looks the same + CSVPrefs::ContextMenuWidget *topWidget = new CSVPrefs::ContextMenuWidget (category.getKey(), parent); + topWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QWidget* widget = new QWidget(topWidget); mGrid = new QGridLayout (widget); for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) addSetting (*iter); - // HACK to get widget to consume all available page space so context menu clicks - // will trigger, but so that setting widgets still only take up the left hand side - QWidget* emptyColumn = new QWidget(); - mGrid->addWidget(emptyColumn, 0, 2, -1, 1); - QWidget* emptyRow = new QWidget(); - emptyRow->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding); - mGrid->addWidget(emptyRow, mGrid->rowCount(), 0, 1, -1); - setWidgetResizable(true); - setWidget (widget); + setWidget (topWidget); } void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting) From c2f427f48d64721b74a36210d757f9af687fc934 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Wed, 10 May 2017 20:43:52 +1200 Subject: [PATCH 14/18] Prevent context menu appearing when right-clicking shortcut setting --- apps/opencs/model/prefs/shortcutsetting.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index 418559475..4c3931e99 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -40,6 +40,10 @@ namespace CSMPrefs widget->setCheckable(true); widget->installEventFilter(this); + + // right clicking on button sets shortcut to RMB, so context menu should not appear + widget->setContextMenuPolicy(Qt::ContextMenuPolicy::PreventContextMenu); + mButton = widget; connect(widget, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool))); From 16f8341de385521821717857cdcfd03a4276ecd8 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Wed, 10 May 2017 21:24:12 +1200 Subject: [PATCH 15/18] Prevent context menu appearing for modifier settings --- apps/opencs/model/prefs/modifiersetting.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/opencs/model/prefs/modifiersetting.cpp b/apps/opencs/model/prefs/modifiersetting.cpp index b70d39714..6273575e9 100644 --- a/apps/opencs/model/prefs/modifiersetting.cpp +++ b/apps/opencs/model/prefs/modifiersetting.cpp @@ -32,6 +32,10 @@ namespace CSMPrefs widget->setCheckable(true); widget->installEventFilter(this); + + // right clicking on button sets shortcut to RMB, so context menu should not appear + widget->setContextMenuPolicy(Qt::ContextMenuPolicy::PreventContextMenu); + mButton = widget; connect(widget, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool))); From cd75c5618c1158c71cfdadb4d2485550833eb94e Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Thu, 11 May 2017 19:46:51 +1200 Subject: [PATCH 16/18] Move context menu code to PageBase --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/prefs/contextmenuwidget.cpp | 33 ------------------ apps/opencs/view/prefs/contextmenuwidget.hpp | 36 -------------------- apps/opencs/view/prefs/keybindingpage.cpp | 3 +- apps/opencs/view/prefs/page.cpp | 12 ++----- apps/opencs/view/prefs/pagebase.cpp | 25 ++++++++++++++ apps/opencs/view/prefs/pagebase.hpp | 12 +++++++ 7 files changed, 41 insertions(+), 82 deletions(-) delete mode 100644 apps/opencs/view/prefs/contextmenuwidget.cpp delete mode 100644 apps/opencs/view/prefs/contextmenuwidget.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index d04259b38..0a146dc06 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -110,7 +110,7 @@ opencs_units_noqt (view/tools ) opencs_units (view/prefs - dialogue pagebase page keybindingpage contextmenulist contextmenuwidget + dialogue pagebase page keybindingpage contextmenulist ) opencs_units (model/prefs diff --git a/apps/opencs/view/prefs/contextmenuwidget.cpp b/apps/opencs/view/prefs/contextmenuwidget.cpp deleted file mode 100644 index bb1984e9a..000000000 --- a/apps/opencs/view/prefs/contextmenuwidget.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "contextmenuwidget.hpp" - -#include -#include - -#include "../../model/prefs/state.hpp" - -CSVPrefs::ContextMenuWidget::ContextMenuWidget(const std::string& category, QWidget* parent) - :QWidget(parent) - ,mCategory(category) -{ -} - -void CSVPrefs::ContextMenuWidget::contextMenuEvent(QContextMenuEvent* e) -{ - QMenu* menu = new QMenu(); - - menu->addAction("Reset category to default", this, SLOT(resetCategory())); - menu->addAction("Reset all to default", this, SLOT(resetAll())); - - menu->exec(e->globalPos()); - delete menu; -} - -void CSVPrefs::ContextMenuWidget::resetCategory() -{ - CSMPrefs::State::get().resetCategory(mCategory); -} - -void CSVPrefs::ContextMenuWidget::resetAll() -{ - CSMPrefs::State::get().resetAll(); -} diff --git a/apps/opencs/view/prefs/contextmenuwidget.hpp b/apps/opencs/view/prefs/contextmenuwidget.hpp deleted file mode 100644 index 57c231fb6..000000000 --- a/apps/opencs/view/prefs/contextmenuwidget.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CSV_PREFS_CONTEXTMENUWIDGET_H -#define CSV_PREFS_CONTEXTMENUWIDGET_H - -#include - -#include - -class QContextMenuEvent; - -namespace CSVPrefs -{ - class ContextMenuWidget : public QWidget - { - Q_OBJECT - - public: - - ContextMenuWidget(const std::string& category, QWidget* parent = 0); - - protected: - - void contextMenuEvent(QContextMenuEvent* e); - - private slots: - - void resetCategory(); - - void resetAll(); - - private: - - std::string mCategory; - }; -} - -#endif diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index d7756f7c8..143665f4a 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -9,7 +9,6 @@ #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" -#include "../../view/prefs/contextmenuwidget.hpp" namespace CSVPrefs { @@ -20,7 +19,7 @@ namespace CSVPrefs , mPageSelector(0) { // Need one widget for scroll area - CSVPrefs::ContextMenuWidget* topWidget = new CSVPrefs::ContextMenuWidget(category.getKey()); + QWidget* topWidget = new QWidget(); QVBoxLayout* topLayout = new QVBoxLayout(topWidget); // Allows switching between "pages" diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index 09191a436..c23e9f64f 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -5,25 +5,17 @@ #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" -#include "../../view/prefs/contextmenuwidget.hpp" CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) { - // topWidget can expand while widget stays the same size - // This is so the context menu triggers over the entire page - // but the user interface looks the same - CSVPrefs::ContextMenuWidget *topWidget = new CSVPrefs::ContextMenuWidget (category.getKey(), parent); - topWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QWidget* widget = new QWidget(topWidget); + QWidget *widget = new QWidget (parent); mGrid = new QGridLayout (widget); for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) addSetting (*iter); - setWidgetResizable(true); - setWidget (topWidget); + setWidget (widget); } void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting) diff --git a/apps/opencs/view/prefs/pagebase.cpp b/apps/opencs/view/prefs/pagebase.cpp index 16684a69d..15535b785 100644 --- a/apps/opencs/view/prefs/pagebase.cpp +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -1,7 +1,11 @@ #include "pagebase.hpp" +#include +#include + #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent) : QScrollArea (parent), mCategory (category) @@ -11,3 +15,24 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory() { return mCategory; } + +void CSVPrefs::PageBase::contextMenuEvent(QContextMenuEvent* e) +{ + QMenu* menu = new QMenu(); + + menu->addAction("Reset category to default", this, SLOT(resetCategory())); + menu->addAction("Reset all to default", this, SLOT(resetAll())); + + menu->exec(e->globalPos()); + delete menu; +} + +void CSVPrefs::PageBase::resetCategory() +{ + CSMPrefs::State::get().resetCategory(getCategory().getKey()); +} + +void CSVPrefs::PageBase::resetAll() +{ + CSMPrefs::State::get().resetAll(); +} diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index affe49f4a..91a4dee5b 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -3,6 +3,8 @@ #include +class QContextMenuEvent; + namespace CSMPrefs { class Category; @@ -21,6 +23,16 @@ namespace CSVPrefs PageBase (CSMPrefs::Category& category, QWidget *parent); CSMPrefs::Category& getCategory(); + + protected: + + void contextMenuEvent(QContextMenuEvent*); + + private slots: + + void resetCategory(); + + void resetAll(); }; } From 7281e8b888848432f279c88499ce9fc25e0cac57 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Fri, 12 May 2017 12:48:25 +1200 Subject: [PATCH 17/18] Remove C++11 features --- apps/opencs/model/prefs/modifiersetting.cpp | 2 +- apps/opencs/model/prefs/shortcutsetting.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/prefs/modifiersetting.cpp b/apps/opencs/model/prefs/modifiersetting.cpp index 6273575e9..da6b2ccdd 100644 --- a/apps/opencs/model/prefs/modifiersetting.cpp +++ b/apps/opencs/model/prefs/modifiersetting.cpp @@ -34,7 +34,7 @@ namespace CSMPrefs widget->installEventFilter(this); // right clicking on button sets shortcut to RMB, so context menu should not appear - widget->setContextMenuPolicy(Qt::ContextMenuPolicy::PreventContextMenu); + widget->setContextMenuPolicy(Qt::PreventContextMenu); mButton = widget; diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index 4c3931e99..de495b9fc 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -42,7 +42,7 @@ namespace CSMPrefs widget->installEventFilter(this); // right clicking on button sets shortcut to RMB, so context menu should not appear - widget->setContextMenuPolicy(Qt::ContextMenuPolicy::PreventContextMenu); + widget->setContextMenuPolicy(Qt::PreventContextMenu); mButton = widget; From 5ec97811d88f21a191ff09a57e029aeee3991b7f Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Fri, 12 May 2017 20:22:18 +1200 Subject: [PATCH 18/18] Don't switch pages when right-clicking on list --- apps/opencs/view/prefs/contextmenulist.cpp | 12 ++++++++++++ apps/opencs/view/prefs/contextmenulist.hpp | 3 +++ 2 files changed, 15 insertions(+) diff --git a/apps/opencs/view/prefs/contextmenulist.cpp b/apps/opencs/view/prefs/contextmenulist.cpp index 71527d8c6..8115c3ecc 100644 --- a/apps/opencs/view/prefs/contextmenulist.cpp +++ b/apps/opencs/view/prefs/contextmenulist.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "../../model/prefs/state.hpp" @@ -21,6 +22,17 @@ void CSVPrefs::ContextMenuList::contextMenuEvent(QContextMenuEvent* e) delete menu; } +void CSVPrefs::ContextMenuList::mousePressEvent(QMouseEvent* e) +{ + // enable all buttons except right click + // This means that when right-clicking to enable the + // context menu, the page doesn't switch at the same time. + if (!(e->buttons() & Qt::RightButton)) + { + QListWidget::mousePressEvent(e); + } +} + void CSVPrefs::ContextMenuList::resetCategory() { CSMPrefs::State::get().resetCategory(currentItem()->text().toStdString()); diff --git a/apps/opencs/view/prefs/contextmenulist.hpp b/apps/opencs/view/prefs/contextmenulist.hpp index 222cfea6b..6aa187ca4 100644 --- a/apps/opencs/view/prefs/contextmenulist.hpp +++ b/apps/opencs/view/prefs/contextmenulist.hpp @@ -4,6 +4,7 @@ #include class QContextMenuEvent; +class QMouseEvent; namespace CSVPrefs { @@ -18,6 +19,8 @@ namespace CSVPrefs protected: void contextMenuEvent(QContextMenuEvent* e); + + void mousePressEvent(QMouseEvent* e); private slots: