From cd75c5618c1158c71cfdadb4d2485550833eb94e Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Thu, 11 May 2017 19:46:51 +1200 Subject: [PATCH] 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(); }; }