diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 628b97433..b58000b56 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -141,6 +141,10 @@ opencs_units (model/prefs state ) +opencs_units_noqt (model/prefs + category + ) + opencs_units_noqt (model/filter node unarynode narynode leafnode booleannode parser andnode ornode notnode textnode valuenode ) diff --git a/apps/opencs/model/prefs/category.cpp b/apps/opencs/model/prefs/category.cpp new file mode 100644 index 000000000..2f94c729b --- /dev/null +++ b/apps/opencs/model/prefs/category.cpp @@ -0,0 +1,16 @@ + +#include "category.hpp" + +CSMPrefs::Category::Category (State *parent, const std::string& key, const std::string& name) +: mParent (parent), mKey (key), mName (name) +{} + +const std::string& CSMPrefs::Category::getKey() const +{ + return mKey; +} + +const std::string& CSMPrefs::Category::getName() const +{ + return mName; +} diff --git a/apps/opencs/model/prefs/category.hpp b/apps/opencs/model/prefs/category.hpp new file mode 100644 index 000000000..d80d5416f --- /dev/null +++ b/apps/opencs/model/prefs/category.hpp @@ -0,0 +1,26 @@ +#ifndef CSV_PREFS_CATEGORY_H +#define CSM_PREFS_CATEGORY_H + +#include + +namespace CSMPrefs +{ + class State; + + class Category + { + State *mParent; + std::string mKey; + std::string mName; + + public: + + Category (State *parent, const std::string& key, const std::string& name); + + const std::string& getKey() const; + + const std::string& getName() const; + }; +} + +#endif diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 9b183f66a..70e4c86c5 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -2,6 +2,7 @@ #include "state.hpp" #include +#include CSMPrefs::State *CSMPrefs::State::sThis = 0; @@ -27,11 +28,45 @@ void CSMPrefs::State::load() void CSMPrefs::State::declare() { + declareCategory ("window", "Windows"); + declareCategory ("records", "Records"); + + declareCategory ("table-input", "ID Tables"); + + declareCategory ("dialogues", "ID Dialogues"); + + declareCategory ("report-input", "Reports"); + + declareCategory ("search", "Search & Replace"); + + declareCategory ("script-editor", "Scripts"); + + declareCategory ("general-input", "General Input"); + + declareCategory ("scene-input", "3D Scene Input"); + + declareCategory ("tooltips", "Tooltips"); +} + +void CSMPrefs::State::declareCategory (const std::string& key, const std::string& name) +{ + std::map::iterator iter = mCategories.find (key); + + if (iter!=mCategories.end()) + { + mCurrentCategory = iter; + } + else + { + mCurrentCategory = + mCategories.insert (std::make_pair (key, Category (this, key, name))).first; + } } CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager) -: mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager) +: mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager), + mCurrentCategory (mCategories.end()) { if (sThis) throw std::logic_error ("An instance of CSMPRefs::State already exists"); @@ -53,6 +88,19 @@ void CSMPrefs::State::save() mSettings.saveUser (user.string()); } +std::vector > CSMPrefs::State::listCategories() const +{ + std::vector > list; + + for (std::map::const_iterator iter (mCategories.begin()); + iter!=mCategories.end(); ++iter) + list.push_back (std::make_pair (iter->second.getName(), iter->first)); + + std::sort (list.begin(), list.end()); + + return list; +} + CSMPrefs::State& CSMPrefs::State::get() { if (!sThis) diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index d2ed8061e..fd49db3ef 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -1,6 +1,9 @@ #ifndef CSV_PREFS_STATE_H #define CSM_PREFS_STATE_H +#include +#include + #include #ifndef Q_MOC_RUN @@ -9,6 +12,8 @@ #include +#include "category.hpp" + namespace CSMPrefs { class State : public QObject @@ -20,6 +25,8 @@ namespace CSMPrefs const std::string mConfigFile; const Files::ConfigurationManager& mConfigurationManager; Settings::Manager mSettings; + std::map mCategories; + std::map::iterator mCurrentCategory; // not implemented State (const State&); @@ -31,6 +38,8 @@ namespace CSMPrefs void declare(); + void declareCategory (const std::string& key, const std::string& name); + public: State (const Files::ConfigurationManager& configurationManager); @@ -39,6 +48,9 @@ namespace CSMPrefs void save(); + /// \return collection of name, key pairs (sorted) + std::vector > listCategories() const; + static State& get(); }; diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index 5f5ceaada..cc794c286 100644 --- a/apps/opencs/view/prefs/dialogue.cpp +++ b/apps/opencs/view/prefs/dialogue.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "../../model/prefs/state.hpp" @@ -19,6 +20,21 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) main->addWidget (mList); + QFontMetrics metrics (QApplication::font()); + + int maxWidth = 1; + + for (std::vector >::const_iterator iter (mCategories.begin()); + iter!=mCategories.end(); ++iter) + { + QString label = QString::fromUtf8 (iter->first.c_str()); + maxWidth = std::max (maxWidth, metrics.width (label)); + + mList->addItem (label); + } + + mList->setMaximumWidth (maxWidth + 10); + /// \todo connect to selection signal } @@ -30,7 +46,7 @@ void CSVPrefs::Dialogue::buildContentArea (QSplitter *main) main->addWidget (mContent); } -CSVPrefs::Dialogue::Dialogue() +CSVPrefs::Dialogue::Dialogue() : mCategories (CSMPrefs::get().listCategories()) { setWindowTitle ("User Settings"); diff --git a/apps/opencs/view/prefs/dialogue.hpp b/apps/opencs/view/prefs/dialogue.hpp index 78c832c9f..2773bcccc 100644 --- a/apps/opencs/view/prefs/dialogue.hpp +++ b/apps/opencs/view/prefs/dialogue.hpp @@ -15,6 +15,7 @@ namespace CSVPrefs QListWidget *mList; QStackedWidget *mContent; + std::vector > mCategories; private: