From 5e40b4d2e83128721863e5c56c7f3b65aea0459e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 8 Dec 2015 12:04:45 +0100 Subject: [PATCH] page switching mechanism --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/prefs/state.cpp | 10 ++++++++++ apps/opencs/model/prefs/state.hpp | 2 ++ apps/opencs/view/prefs/dialogue.cpp | 27 ++++++++++++++++++++++++++- apps/opencs/view/prefs/dialogue.hpp | 5 +++++ apps/opencs/view/prefs/pagebase.cpp | 19 +++++++++++++++++++ apps/opencs/view/prefs/pagebase.hpp | 27 +++++++++++++++++++++++++++ 7 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 apps/opencs/view/prefs/pagebase.cpp create mode 100644 apps/opencs/view/prefs/pagebase.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index b58000b56..1e666c77d 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -124,7 +124,7 @@ opencs_units_noqt (view/settings ) opencs_units (view/prefs - dialogue + dialogue pagebase ) opencs_units (model/settings diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index d8a0a5614..c484a98d6 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -98,6 +98,16 @@ CSMPrefs::State::Iterator CSMPrefs::State::end() return mCategories.end(); } +CSMPrefs::Category& CSMPrefs::State::getCategory (const std::string& key) +{ + Iterator iter = mCategories.find (key); + + if (iter==mCategories.end()) + throw std::logic_error ("Invalid user settings category: " + key); + + return iter->second; +} + CSMPrefs::State& CSMPrefs::State::get() { if (!sThis) diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index d643dfa4a..a2e7aa038 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -59,6 +59,8 @@ namespace CSMPrefs Iterator end(); + Category& getCategory (const std::string& key); + static State& get(); }; diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index ec43d853d..c4480fec4 100644 --- a/apps/opencs/view/prefs/dialogue.cpp +++ b/apps/opencs/view/prefs/dialogue.cpp @@ -10,6 +10,8 @@ #include "../../model/prefs/state.hpp" +#include "pagebase.hpp" + void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) { mList = new QListWidget (main); @@ -35,7 +37,8 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) mList->setMaximumWidth (maxWidth + 10); - /// \todo connect to selection signal + connect (mList, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)), + this, SLOT (selectionChanged (QListWidgetItem *, QListWidgetItem *))); } void CSVPrefs::Dialogue::buildContentArea (QSplitter *main) @@ -86,3 +89,25 @@ void CSVPrefs::Dialogue::show() QWidget::show(); } + +void CSVPrefs::Dialogue::selectionChanged (QListWidgetItem *current, QListWidgetItem *previous) +{ + if (current) + { + std::string key = current->text().toUtf8().data(); + + for (int i=0; icount(); ++i) + { + PageBase& page = dynamic_cast (*mContent->widget (i)); + + if (page.getCategory().getKey()==key) + { + mContent->setCurrentIndex (i); + return; + } + } + + PageBase *page = new PageBase (CSMPrefs::get().getCategory (key), mContent); + mContent->setCurrentIndex (mContent->addWidget (page)); + } +} diff --git a/apps/opencs/view/prefs/dialogue.hpp b/apps/opencs/view/prefs/dialogue.hpp index 78c832c9f..6bee54eb8 100644 --- a/apps/opencs/view/prefs/dialogue.hpp +++ b/apps/opencs/view/prefs/dialogue.hpp @@ -6,6 +6,7 @@ class QSplitter; class QListWidget; class QStackedWidget; +class QListWidgetItem; namespace CSVPrefs { @@ -33,6 +34,10 @@ namespace CSVPrefs public slots: void show(); + + private slots: + + void selectionChanged (QListWidgetItem *current, QListWidgetItem *previous); }; } diff --git a/apps/opencs/view/prefs/pagebase.cpp b/apps/opencs/view/prefs/pagebase.cpp new file mode 100644 index 000000000..28c33a94a --- /dev/null +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -0,0 +1,19 @@ + +#include "pagebase.hpp" + +#include + +#include "../../model/prefs/category.hpp" + +CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent) +: QScrollArea (parent), mCategory (category) +{ +QLabel *temp = new QLabel (category.getKey().c_str(), this); +setWidget (temp); + +} + +CSMPrefs::Category& CSVPrefs::PageBase::getCategory() +{ + return mCategory; +} diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp new file mode 100644 index 000000000..affe49f4a --- /dev/null +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -0,0 +1,27 @@ +#ifndef CSV_PREFS_PAGEBASE_H +#define CSV_PREFS_PAGEBASE_H + +#include + +namespace CSMPrefs +{ + class Category; +} + +namespace CSVPrefs +{ + class PageBase : public QScrollArea + { + Q_OBJECT + + CSMPrefs::Category& mCategory; + + public: + + PageBase (CSMPrefs::Category& category, QWidget *parent); + + CSMPrefs::Category& getCategory(); + }; +} + +#endif