From 95272e0f147a9bb5d3c97acd242b7dee72af2fda Mon Sep 17 00:00:00 2001 From: unelsson Date: Thu, 15 Apr 2021 00:37:00 +0300 Subject: [PATCH] String setting to CSMPrefs, part of dehardcoding animation files --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/prefs/state.cpp | 47 ++++++++++++++++++++ apps/opencs/model/prefs/state.hpp | 3 ++ apps/opencs/model/prefs/stringsetting.cpp | 54 +++++++++++++++++++++++ apps/opencs/model/prefs/stringsetting.hpp | 36 +++++++++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 apps/opencs/model/prefs/stringsetting.cpp create mode 100644 apps/opencs/model/prefs/stringsetting.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 65575580a..b73cd37b8 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -116,7 +116,7 @@ opencs_units (view/prefs opencs_units (model/prefs state setting intsetting doublesetting boolsetting enumsetting coloursetting shortcut - shortcuteventhandler shortcutmanager shortcutsetting modifiersetting + shortcuteventhandler shortcutmanager shortcutsetting modifiersetting stringsetting ) opencs_units_noqt (model/prefs diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 32b1ee33f..8b9ad2b8a 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -421,6 +421,35 @@ void CSMPrefs::State::declare() declareSubcategory ("Script Editor"); declareShortcut ("script-editor-comment", "Comment Selection", QKeySequence()); declareShortcut ("script-editor-uncomment", "Uncomment Selection", QKeySequence()); + + declareCategory ("Models"); + declareString ("baseanim", "3rd person base model with textkeys-data", "meshes/openmwdude.dae"). + setTooltip("3rd person base model with textkeys-data"); + +/*# 3rd person base model with textkeys-data +baseanim = meshes/base_anim.nif + +# 1st person base animation model that looks also for corresponding kf-file +xbaseanim1st = meshes/xbase_anim.1st.nif + +# 3rd person beast race base model with textkeys-data +baseanimkna = meshes/base_animkna.nif + +# 1st person beast race base animation model +baseanimkna1st = meshes/base_animkna.1st.nif + +# 3rd person female base model with textkeys-data +baseanimfemale = meshes/base_anim_female.nif + +# 1st person female base model with textkeys-data +baseanimfemale1st = meshes/base_anim_female.1st.nif + +# 3rd person werewolf skin +wolfskin = meshes/wolf/skin.nif + +# 1st person werewolf skin +wolfskin1st = meshes/wolf/skin.1st.nif*/ + } void CSMPrefs::State::declareCategory (const std::string& key) @@ -557,6 +586,24 @@ CSMPrefs::ShortcutSetting& CSMPrefs::State::declareShortcut (const std::string& return *setting; } +CSMPrefs::StringSetting& CSMPrefs::State::declareString (const std::string& key, const std::string& label, std::string default_) +{ + if (mCurrentCategory==mCategories.end()) + throw std::logic_error ("no category for setting"); + + setDefault (key, default_); + + default_ = mSettings.getString (key, mCurrentCategory->second.getKey()); + + CSMPrefs::StringSetting *setting = + new CSMPrefs::StringSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label, + default_); + + mCurrentCategory->second.addSetting (setting); + + return *setting; +} + CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(const std::string& key, const std::string& label, int default_) { diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index a32583dc5..aa63de595 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -16,6 +16,7 @@ #include "category.hpp" #include "setting.hpp" #include "enumsetting.hpp" +#include "stringsetting.hpp" #include "shortcutmanager.hpp" class QColor; @@ -78,6 +79,8 @@ namespace CSMPrefs ShortcutSetting& declareShortcut (const std::string& key, const std::string& label, const QKeySequence& default_); + StringSetting& declareString (const std::string& key, const std::string& label, std::string default_); + ModifierSetting& declareModifier(const std::string& key, const std::string& label, int modifier_); void declareSeparator(); diff --git a/apps/opencs/model/prefs/stringsetting.cpp b/apps/opencs/model/prefs/stringsetting.cpp new file mode 100644 index 000000000..06eeb6c4b --- /dev/null +++ b/apps/opencs/model/prefs/stringsetting.cpp @@ -0,0 +1,54 @@ + +#include "stringsetting.hpp" + +#include +#include + +#include + +#include "category.hpp" +#include "state.hpp" + +CSMPrefs::StringSetting::StringSetting (Category *parent, Settings::Manager *values, + QMutex *mutex, const std::string& key, const std::string& label, std::string default_) +: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(nullptr) +{} + +CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip (const std::string& tooltip) +{ + mTooltip = tooltip; + return *this; +} + +std::pair CSMPrefs::StringSetting::makeWidgets (QWidget *parent) +{ + mWidget = new QTextEdit (QString::fromUtf8 (mDefault.c_str()), parent); + + if (!mTooltip.empty()) + { + QString tooltip = QString::fromUtf8 (mTooltip.c_str()); + mWidget->setToolTip (tooltip); + } + + connect (mWidget, SIGNAL (textChanged (std::string)), this, SLOT (textChanged (std::string))); + + return std::make_pair (static_cast (nullptr), mWidget); +} + +void CSMPrefs::StringSetting::updateWidget() +{ + if (mWidget) + { + //mWidget->setValue(getValues().getString(getKey(), getParent()->getKey())); + } +} + +void CSMPrefs::StringSetting::textChanged (std::string text) +{ + { + QMutexLocker lock (getMutex()); + getValues().setString (getKey(), getParent()->getKey(), text); + } + + getParent()->getState()->update (*this); +} diff --git a/apps/opencs/model/prefs/stringsetting.hpp b/apps/opencs/model/prefs/stringsetting.hpp new file mode 100644 index 000000000..f0e66a2ef --- /dev/null +++ b/apps/opencs/model/prefs/stringsetting.hpp @@ -0,0 +1,36 @@ +#ifndef CSM_PREFS_StringSetting_H +#define CSM_PREFS_StringSetting_H + +#include "setting.hpp" + +class QTextEdit; + +namespace CSMPrefs +{ + class StringSetting : public Setting + { + Q_OBJECT + + std::string mTooltip; + std::string mDefault; + QTextEdit* mWidget; + + public: + + StringSetting (Category *parent, Settings::Manager *values, + QMutex *mutex, const std::string& key, const std::string& label, std::string default_); + + StringSetting& setTooltip (const std::string& tooltip); + + /// Return label, input widget. + std::pair makeWidgets (QWidget *parent) override; + + void updateWidget() override; + + private slots: + + void textChanged (std::string text); + }; +} + +#endif