From f6203cac2ab29712ab048cfa82c7e608cd44b338 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Tue, 7 May 2013 20:33:42 -0500 Subject: [PATCH 1/9] update for master --- apps/launcher/settings/settingsbase.hpp | 1 + apps/opencs/CMakeLists.txt | 23 +++ apps/opencs/model/doc/document.cpp | 1 + apps/opencs/model/doc/document.hpp | 2 +- apps/opencs/ocspropertywidget.cpp | 6 + apps/opencs/ocspropertywidget.hpp | 18 ++ apps/opencs/settings/abstractwidget.cpp | 78 +++++++++ apps/opencs/settings/abstractwidget.hpp | 64 ++++++++ apps/opencs/settings/blankpage.cpp | 58 +++++++ apps/opencs/settings/blankpage.hpp | 30 ++++ apps/opencs/settings/customblock.cpp | 120 ++++++++++++++ apps/opencs/settings/customblock.hpp | 36 ++++ apps/opencs/settings/proxyblock.cpp | 149 +++++++++++++++++ apps/opencs/settings/proxyblock.hpp | 42 +++++ apps/opencs/settings/settingcontainer.cpp | 82 ++++++++++ apps/opencs/settings/settingcontainer.hpp | 37 +++++ apps/opencs/settings/usersettings.cpp | 137 ++++++++++++++++ apps/opencs/settings/usersettings.hpp | 35 ++++ apps/opencs/settings/usersettingsdialog.cpp | 173 ++++++++++++++++++++ apps/opencs/settings/usersettingsdialog.hpp | 71 ++++++++ apps/opencs/settings/usersettingsdialog.ui | 68 ++++++++ apps/opencs/view/doc/startup.cpp | 9 +- apps/opencs/view/doc/view.cpp | 43 ++++- apps/opencs/view/doc/view.hpp | 6 + apps/opencs/view/doc/viewmanager.cpp | 9 + files/ui/datafilespage.ui | 12 +- 26 files changed, 1301 insertions(+), 9 deletions(-) create mode 100644 apps/opencs/ocspropertywidget.cpp create mode 100644 apps/opencs/ocspropertywidget.hpp create mode 100644 apps/opencs/settings/abstractwidget.cpp create mode 100644 apps/opencs/settings/abstractwidget.hpp create mode 100644 apps/opencs/settings/blankpage.cpp create mode 100644 apps/opencs/settings/blankpage.hpp create mode 100644 apps/opencs/settings/customblock.cpp create mode 100644 apps/opencs/settings/customblock.hpp create mode 100644 apps/opencs/settings/proxyblock.cpp create mode 100644 apps/opencs/settings/proxyblock.hpp create mode 100644 apps/opencs/settings/settingcontainer.cpp create mode 100644 apps/opencs/settings/settingcontainer.hpp create mode 100644 apps/opencs/settings/usersettings.cpp create mode 100644 apps/opencs/settings/usersettings.hpp create mode 100644 apps/opencs/settings/usersettingsdialog.cpp create mode 100644 apps/opencs/settings/usersettingsdialog.hpp create mode 100644 apps/opencs/settings/usersettingsdialog.ui diff --git a/apps/launcher/settings/settingsbase.hpp b/apps/launcher/settings/settingsbase.hpp index bbfad1fbb..c4561a910 100644 --- a/apps/launcher/settings/settingsbase.hpp +++ b/apps/launcher/settings/settingsbase.hpp @@ -48,6 +48,7 @@ public: mCache.clear(); QString sectionPrefix; + QRegExp sectionRe("^\\[([^]]+)\\]"); QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 0071dd1fc..dacd3bb4e 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -3,6 +3,7 @@ set (OPENCS_SRC main.cpp) opencs_units (. editor) +set (CMAKE_BUILD_TYPE DEBUG) opencs_units (model/doc document @@ -71,6 +72,28 @@ opencs_units_noqt (view/tools subviews ) +opencs_units (settings + customblock + proxyblock + settingcontainer + groupbox + settingsitem + abstractblock + settingwidget + itemblock + groupblock + toggleblock + usersettingsdialog + abstractpage + abstractwidget + blankpage + editorpage + ) + +opencs_units_noqt (settings + support + usersettings + ) set (OPENCS_US ) diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 11d877d0b..3fd0881fb 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -3,6 +3,7 @@ #include +#include void CSMDoc::Document::load (const std::vector::const_iterator& begin, const std::vector::const_iterator& end, bool lastAsModified) { diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index a7b198689..aaab50c86 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -105,4 +105,4 @@ namespace CSMDoc }; } -#endif \ No newline at end of file +#endif diff --git a/apps/opencs/ocspropertywidget.cpp b/apps/opencs/ocspropertywidget.cpp new file mode 100644 index 000000000..68315201a --- /dev/null +++ b/apps/opencs/ocspropertywidget.cpp @@ -0,0 +1,6 @@ +#include "ocspropertywidget.hpp" + +OcsPropertyWidget::OcsPropertyWidget(QObject *parent) : + QObject(parent) +{ +} diff --git a/apps/opencs/ocspropertywidget.hpp b/apps/opencs/ocspropertywidget.hpp new file mode 100644 index 000000000..fc64a0a69 --- /dev/null +++ b/apps/opencs/ocspropertywidget.hpp @@ -0,0 +1,18 @@ +#ifndef OCSPROPERTYWIDGET_HPP +#define OCSPROPERTYWIDGET_HPP + +#include + +class OcsPropertyWidget : public QObject +{ + Q_OBJECT +public: + explicit OcsPropertyWidget(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // OCSPROPERTYWIDGET_HPP diff --git a/apps/opencs/settings/abstractwidget.cpp b/apps/opencs/settings/abstractwidget.cpp new file mode 100644 index 000000000..a23c3ee1b --- /dev/null +++ b/apps/opencs/settings/abstractwidget.cpp @@ -0,0 +1,78 @@ +#include "abstractwidget.hpp" + +#include +#include + +void CsSettings::AbstractWidget::build(QWidget *widget, WidgetDef &def, bool noLabel) +{ + if (!mLayout) + createLayout(def.orientation, true); + + buildLabelAndWidget (widget, def, noLabel); + +} + +void CsSettings::AbstractWidget::buildLabelAndWidget (QWidget *widget, WidgetDef &def, bool noLabel) +{ + if (def.widgetWidth > -1) + widget->setFixedWidth (def.widgetWidth); + + if (!(def.caption.isEmpty() || noLabel) ) + { + QLabel *label = new QLabel (def.caption, dynamic_cast(parent())); + label->setBuddy (widget); + mLayout->addWidget (label); + + if (def.labelWidth > -1) + label->setFixedWidth(def.labelWidth); + } + + mLayout->addWidget (widget); + mLayout->setAlignment (widget, getAlignment (def.widgetAlignment)); +} + +void CsSettings::AbstractWidget::createLayout + (OcsWidgetOrientation direction, bool isZeroMargin) +{ + if (direction == OCS_VERTICAL) + mLayout = new QVBoxLayout (); + else + mLayout = new QHBoxLayout (); + + if (isZeroMargin) + mLayout->setContentsMargins(0, 0, 0, 0); +} + +QFlags CsSettings::AbstractWidget::getAlignment (CsSettings::OcsAlignment flag) +{ + return QFlags(static_cast(flag)); +} + +QLayout *CsSettings::AbstractWidget::getLayout() +{ + return mLayout; +} + +void CsSettings::AbstractWidget::slotUpdateWidget (const QString &value) +{ + updateWidget (value); +} + +void CsSettings::AbstractWidget::slotUpdateItem(const QString &value) +{ + emit signalUpdateItem (value); +} + +void CsSettings::AbstractWidget::slotUpdateItem(bool value) +{ + if (value) + emit signalUpdateItem (widget()->objectName()); +} + +void CsSettings::AbstractWidget::slotUpdateItem(int value) +{ + emit signalUpdateItem (QString::number(value)); +} + +void CsSettings::AbstractWidget::slotUpdateItem (QListWidgetItem* current, QListWidgetItem* previous) +{} diff --git a/apps/opencs/settings/abstractwidget.hpp b/apps/opencs/settings/abstractwidget.hpp new file mode 100644 index 000000000..1adf8e84f --- /dev/null +++ b/apps/opencs/settings/abstractwidget.hpp @@ -0,0 +1,64 @@ +#ifndef ABSTRACTWIDGET_HPP +#define ABSTRACTWIDGET_HPP + +#include +#include "support.hpp" + +class QLayout; + +namespace CsSettings +{ + class AbstractWidget : public QObject + { + Q_OBJECT + + QLayout *mLayout; + + public: + + explicit AbstractWidget (QLayout *layout = 0, QWidget* parent = 0) + : QObject (parent), mLayout (layout) + {} + + //retrieve layout for insertion into itemblock + QLayout *getLayout(); + + //create the derived widget instance + void build (QWidget* widget, WidgetDef &def, bool noLabel = false); + + //reference to the derived widget instance + virtual QWidget *widget() = 0; + + protected: + + //called by inbound signal for type-specific widget udpates + virtual void updateWidget (const QString &value) = 0; + + //converts user-defined enum to Qt equivalents + QFlags getAlignment (CsSettings::OcsAlignment flag); + + private: + + //widget initialization utilities + void createLayout (CsSettings::OcsWidgetOrientation direction, bool isZeroMargin); + void buildLabelAndWidget (QWidget *widget, WidgetDef &def, bool noLabel); + + + signals: + + //outbound update + void signalUpdateItem (const QString &value); + + public slots: + + //inbound updates + void slotUpdateWidget (const QString &value); + + //Outbound updates from derived widget signal + void slotUpdateItem (const QString &value); + void slotUpdateItem (bool value); + void slotUpdateItem (int value); + void slotUpdateItem (QListWidgetItem* current, QListWidgetItem* previous); + }; +} +#endif // ABSTRACTWIDGET_HPP diff --git a/apps/opencs/settings/blankpage.cpp b/apps/opencs/settings/blankpage.cpp new file mode 100644 index 000000000..1e2ab9c0f --- /dev/null +++ b/apps/opencs/settings/blankpage.cpp @@ -0,0 +1,58 @@ +#include "blankpage.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_OS_MAC +#include +#endif + +#include "usersettings.hpp" +#include "groupblock.hpp" +#include "toggleblock.hpp" + +CsSettings::BlankPage::BlankPage(QWidget *parent): + AbstractPage("Blank", parent) +{ + initPage(); +} + +CsSettings::BlankPage::BlankPage(const QString &title, QWidget *parent): + AbstractPage(title, parent) +{ + initPage(); +} + +void CsSettings::BlankPage::initPage() +{ + // Hacks to get the stylesheet look properly +#ifdef Q_OS_MAC + QPlastiqueStyle *style = new QPlastiqueStyle; + //profilesComboBox->setStyle(style); +#endif + + setupUi(); +} + +void CsSettings::BlankPage::setupUi() +{ + QGroupBox *pageBox = new QGroupBox(this); + QLayout* pageLayout = new QVBoxLayout(); + + setLayout(pageLayout); + pageLayout->addWidget(pageBox); +} + +void CsSettings::BlankPage::initializeWidgets (const SettingMap &settings) +{ + //iterate each item in each blocks in this section + //validate the corresponding setting against the defined valuelist if any. + foreach (AbstractBlock *block, mAbstractBlocks) + block->updateSettings (settings); +} diff --git a/apps/opencs/settings/blankpage.hpp b/apps/opencs/settings/blankpage.hpp new file mode 100644 index 000000000..9dd6c5e56 --- /dev/null +++ b/apps/opencs/settings/blankpage.hpp @@ -0,0 +1,30 @@ +#ifndef BLANKPAGE_HPP +#define BLANKPAGE_HPP + +#include "abstractpage.hpp" + +class QGroupBox; + +namespace CsSettings { + + class UserSettings; + class AbstractBlock; + + class BlankPage : public AbstractPage + { + Q_OBJECT + + public: + + BlankPage (QWidget *parent = 0); + BlankPage (const QString &title, QWidget *parent); + + void setupUi(); + void initializeWidgets (const SettingMap &settings); + + private: + void initPage(); + }; +} + +#endif // BLANKPAGE_HPP diff --git a/apps/opencs/settings/customblock.cpp b/apps/opencs/settings/customblock.cpp new file mode 100644 index 000000000..f70db47a0 --- /dev/null +++ b/apps/opencs/settings/customblock.cpp @@ -0,0 +1,120 @@ +#include "customblock.hpp" +#include "groupblock.hpp" +#include "itemblock.hpp" +#include "proxyblock.hpp" + +CsSettings::CustomBlock::CustomBlock (QWidget *parent) : AbstractBlock (parent) +{ +} + +int CsSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefList::iterator *it) +{ + int retVal = 0; + + GroupBlockDefList::iterator defaultIt; + GroupBlockDefList::iterator listIt = defList.begin(); + GroupBlockDefList::iterator proxyIt = defaultIt; + + if (it) + listIt = *it; + + ProxyBlock *proxyBlock = new ProxyBlock(getParent()); + + for (; listIt != defList.end(); ++listIt) + { + if (!(*listIt)->isProxy) + retVal = buildGroupBlock (*(*listIt)); + else + { + mGroupList << proxyBlock; + proxyIt = listIt; + } + } + + if (proxyIt != defaultIt) + retVal = buildProxyBlock (*(*proxyIt), proxyBlock); + + return retVal; +} + +CsSettings::GroupBox *CsSettings::CustomBlock::buildGroupBox (CsSettings::OcsWidgetOrientation orientation) +{ + GroupBox *box = new GroupBox (false, mBox); + QLayout *layout = createLayout (orientation, true, box); + + return box; +} + +int CsSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def) +{ + GroupBlock *block = new GroupBlock (getParent()); + + mGroupList << block; + + connect (block, SIGNAL (signalUpdateSetting(const QString &, const QString &)), + this, SLOT (slotUpdateSetting (const QString &, const QString &))); + + return block->build(def); +} + +int CsSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *block) +{ + if (def.properties.size() != 1) + return -1; + + int retVal = block->build(def); + + if (retVal != 0) + return retVal; + + foreach (QStringList *list, *(def.properties.at(0)->proxyList)) + { + QString proxiedBlockName = list->at(0); + + //iterate each group in the custom block, matching it to each proxied setting + //and connecting it appropriately + foreach (GroupBlock *groupBlock, mGroupList) + { + ItemBlock *proxiedBlock = groupBlock->getItemBlock (proxiedBlockName); + + if (proxiedBlock) + { + block->addSetting(proxiedBlock, list); + + //connect the proxy block's update signal to the custom block's slot + connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)), + this, SLOT (slotUpdateSetting (const QString &, const QString &))); + } + } + } + + return 0; +} + +CsSettings::SettingList *CsSettings::CustomBlock::getSettings() +{ + SettingList *settings = new SettingList(); + + foreach (GroupBlock *block, mGroupList) + { + SettingList *groupSettings = block->getSettings(); + + if (groupSettings) + settings->append(*groupSettings); + } + + return settings; +} + +bool CsSettings::CustomBlock::updateSettings (const SettingMap &settings) +{ + bool success = true; + + foreach (GroupBlock *block, mGroupList) + { + bool success2 = block->updateSettings (settings); + success = success && success2; + } + + return success; +} diff --git a/apps/opencs/settings/customblock.hpp b/apps/opencs/settings/customblock.hpp new file mode 100644 index 000000000..ba83464da --- /dev/null +++ b/apps/opencs/settings/customblock.hpp @@ -0,0 +1,36 @@ +#ifndef CUSTOMBLOCK_HPP +#define CUSTOMBLOCK_HPP + +#include "abstractblock.hpp" + +namespace CsSettings +{ + + class ProxyBlock; + + class CustomBlock : public AbstractBlock + { + + protected: + + GroupBlockList mGroupList; + + public: + + explicit CustomBlock (QWidget *parent = 0); + + bool updateSettings (const SettingMap &settings); + SettingList *getSettings(); + int build (GroupBlockDefList &defList, GroupBlockDefList::Iterator *it = 0); + + protected: + + GroupBox *buildGroupBox (OcsWidgetOrientation orientation); + + private: + + int buildGroupBlock(GroupBlockDef &def); + int buildProxyBlock(GroupBlockDef &def, ProxyBlock *block); + }; +} +#endif // CUSTOMBLOCK_HPP diff --git a/apps/opencs/settings/proxyblock.cpp b/apps/opencs/settings/proxyblock.cpp new file mode 100644 index 000000000..46e404a12 --- /dev/null +++ b/apps/opencs/settings/proxyblock.cpp @@ -0,0 +1,149 @@ +#include "proxyblock.hpp" +#include "itemblock.hpp" + +CsSettings::ProxyBlock::ProxyBlock (QWidget *parent) + : GroupBlock (parent) +{ +} +int CsSettings::ProxyBlock::build (GroupBlockDef &proxyDef) +{ + //get the list of pre-defined values for the proxy + mValueList = proxyDef.properties.at(0)->valueList; + + bool success = GroupBlock::build(proxyDef); + + //connect the item block of the proxy setting to the proxy-update slot + connect (getItemBlock(0), SIGNAL (signalUpdateSetting(const QString &, const QString &)), + this, SLOT (slotUpdateProxySetting (const QString &, const QString &))); + + return success; +} + +void CsSettings::ProxyBlock::addSetting (ItemBlock *settingBlock, QStringList *proxyList) +{ + //connect the item block of the proxied seting to the generic update slot + connect (settingBlock, SIGNAL (signalUpdateSetting(const QString &, const QString &)), + this, SLOT (slotUpdateProxySetting(const QString &, const QString &))); + + mProxiedItemBlockList << settingBlock; + mProxyList << proxyList; +} + +bool CsSettings::ProxyBlock::updateSettings (const SettingMap &settings) +{ + return updateByProxiedSettings(&settings); +} + +bool CsSettings::ProxyBlock::updateBySignal(const QString &name, const QString &value, bool &doEmit) +{ + doEmit = false; + return updateProxiedSettings(); +} + +void CsSettings::ProxyBlock::slotUpdateProxySetting (const QString &name, const QString &value) +{ + updateByProxiedSettings(); +} + +bool CsSettings::ProxyBlock::updateProxiedSettings() +{ + foreach (ItemBlock *block, mProxiedItemBlockList) + { + QString value = getItemBlock(0)->getValue(); + + bool success = false; + int i = 0; + for (; i < mValueList->size(); ++i) + { + success = (value == mValueList->at(i)); + + if (success) + break; + } + + if (!success) + return false; + + foreach (QStringList *list, mProxyList) + { + if ( list->at(0) == block->objectName()) + block->update (list->at(++i)); + } + } + + return true; +} + +bool CsSettings::ProxyBlock::updateByProxiedSettings(const SettingMap *settings) +{ + bool success = false; + int commonIndex = -1; + + //update all proxy settings based on values from non-proxies + foreach (QStringList *list, mProxyList) + { + //Iterate each proxy item's proxied setting list, getting the current values + //Compare those value indices. + //If indices match, they correlate to one of the proxy's values in it's value list + + //first value is always the name of the setting the proxy setting manages + QStringList::Iterator itProxyValue = list->begin(); + QString proxiedSettingName = (*itProxyValue); + QString proxiedSettingValue = ""; + itProxyValue++; + + if (!settings) + { + //get the actual setting value + ItemBlock *block = getProxiedItemBlock (proxiedSettingName); + + if (block) + proxiedSettingValue = block->getValue(); + } + else + proxiedSettingValue = (*settings)[proxiedSettingName]->getValue(); + + int j = 0; + + //iterate each value in the proxy string list + for (; itProxyValue != (list)->end(); ++itProxyValue) + { + success = ((*itProxyValue) == proxiedSettingValue); + + if (success) + break; + + j++; + } + + //break if no match was found + if ( !success ) + break; + + if (commonIndex != -1) + success = (commonIndex == j); + else + commonIndex = j; + + //break if indices were found, but mismatch + if (!success) + break; + } + + //if successful, the proxied setting values match a pre-defined value in the + //proxy's value list. Set the proxy to that value index + if (success) + { + ItemBlock *block = getItemBlock(0); + + if (block) + block->update (mValueList->at(commonIndex)); + } + + return success; +} + +CsSettings::ItemBlock *CsSettings::ProxyBlock::getProxiedItemBlock (const QString &name) +{ + return getItemBlock (name, &mProxiedItemBlockList); +} diff --git a/apps/opencs/settings/proxyblock.hpp b/apps/opencs/settings/proxyblock.hpp new file mode 100644 index 000000000..d35d7da69 --- /dev/null +++ b/apps/opencs/settings/proxyblock.hpp @@ -0,0 +1,42 @@ +#ifndef PROXYBLOCK_HPP +#define PROXYBLOCK_HPP + +#include "groupblock.hpp" + +namespace CsSettings +{ + class ProxyBlock : public GroupBlock + { + Q_OBJECT + + //NOTE: mProxyItemBlockList and mProxyList + //should be combined into a value pair and stored in one list. + ItemBlockList mProxiedItemBlockList; + ProxyList mProxyList; + QStringList *mValueList; + + public: + + explicit ProxyBlock (QWidget *parent = 0); + explicit ProxyBlock (ItemBlock *proxyItemBlock, QWidget *parent = 0); + + void addSetting (ItemBlock* settingBlock, QStringList *proxyList); + int build (GroupBlockDef &def); + + SettingList *getSettings() { return 0; } + bool updateSettings (const SettingMap &settings); + bool updateBySignal (const QString &name, const QString &value, bool &doEmit); + + private: + + ItemBlock *getProxiedItemBlock (const QString &name); + bool updateByProxiedSettings(const SettingMap *settings = 0); + bool updateProxiedSettings(); + + private slots: + + void slotUpdateProxySetting (const QString &name, const QString &value); + + }; +} +#endif // PROXYBLOCK_HPP diff --git a/apps/opencs/settings/settingcontainer.cpp b/apps/opencs/settings/settingcontainer.cpp new file mode 100644 index 000000000..700c70fa4 --- /dev/null +++ b/apps/opencs/settings/settingcontainer.cpp @@ -0,0 +1,82 @@ +#include "settingcontainer.hpp" + +#include + +CsSettings::SettingContainer::SettingContainer(QObject *parent) : + QObject(parent), mValue (0), mValues (0) +{ +} + +CsSettings::SettingContainer::SettingContainer(const QString &value, QObject *parent) : + QObject(parent), mValue (new QString (value)), mValues (0) +{ +} + +void CsSettings::SettingContainer::insert (const QString &value) +{ + if (mValue) + { + mValues = new QStringList; + mValues->push_back (*mValue); + mValues->push_back (value); + + delete mValue; + mValue = 0; + } + else + { + delete mValue; + mValue = new QString (value); + } + +} + +void CsSettings::SettingContainer::update (const QString &value, int index) +{ + if (isEmpty()) + mValue = new QString(value); + + else if (mValue) + *mValue = value; + + else if (mValues) + mValues->replace(index, value); +} + +QString CsSettings::SettingContainer::getValue (int index) const +{ + QString retVal(""); + + //if mValue is valid, it's a single-value property. + //ignore the index and return the value + if (mValue) + retVal = *mValue; + + //otherwise, if it's a multivalued property + //return the appropriate value at the index + else if (mValues) + { + if (index == -1) + retVal = mValues->at(0); + + else if (index < mValues->size()) + retVal = mValues->at(index); + } + + return retVal; +} + +int CsSettings::SettingContainer::count () const +{ + int retVal = 0; + + if (!isEmpty()) + { + if (mValues) + retVal = mValues->size(); + else + retVal = 1; + } + + return retVal; +} diff --git a/apps/opencs/settings/settingcontainer.hpp b/apps/opencs/settings/settingcontainer.hpp new file mode 100644 index 000000000..929c6a25d --- /dev/null +++ b/apps/opencs/settings/settingcontainer.hpp @@ -0,0 +1,37 @@ +#ifndef SETTINGCONTAINER_HPP +#define SETTINGCONTAINER_HPP + +#include + +class QStringList; + +namespace CsSettings +{ + class SettingContainer : public QObject + { + Q_OBJECT + + QString *mValue; + QStringList *mValues; + + public: + explicit SettingContainer (QObject *parent = 0); + explicit SettingContainer (const QString &value, QObject *parent = 0); + + virtual QString getName() const {return "";} + + void insert (const QString &value); + void update (const QString &value, int index = 0); + + QString getValue (int index = -1) const; + inline QStringList *getValues() const { return mValues; } + int count() const; + + //test for empty container + //useful for default-constructed containers returned by QMap when invalid key is passed + inline bool isEmpty() const { return (!mValue && !mValues); } + inline bool isMultiValue() const { return (mValues); } + }; +} + +#endif // SETTINGCONTAINER_HPP diff --git a/apps/opencs/settings/usersettings.cpp b/apps/opencs/settings/usersettings.cpp new file mode 100644 index 000000000..2ddef938b --- /dev/null +++ b/apps/opencs/settings/usersettings.cpp @@ -0,0 +1,137 @@ +#include "usersettings.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "settingcontainer.hpp" + +#include +/** + * Workaround for problems with whitespaces in paths in older versions of Boost library + */ +#if (BOOST_VERSION <= 104600) +namespace boost +{ + + template<> + inline boost::filesystem::path lexical_cast(const std::string& arg) + { + return boost::filesystem::path(arg); + } + +} /* namespace boost */ +#endif /* (BOOST_VERSION <= 104600) */ + + +CsSettings::UserSettings::UserSettings(Files::ConfigurationManager &cfg) + : mCfgMgr(cfg) +{ +} + +CsSettings::UserSettings::~UserSettings() +{ +} + +QFile *CsSettings::UserSettings::openFile (const QString &filename) +{ + QFile *file = new QFile(filename); + + bool success = (file->open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) ; + + if (!success) + { + // File cannot be opened or created + QMessageBox msgBox; + msgBox.setWindowTitle(QObject::tr("Error writing OpenMW configuration file")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(QObject::tr("
Could not open or create %0 for writing

\ + Please make sure you have the right permissions \ + and try again.
").arg(file->fileName())); + msgBox.exec(); + delete file; + file = 0; + } + + return file; +} + +bool CsSettings::UserSettings::writeFile(QFile *file, QMap &settings) +{ + if (!file) + return false; + + QTextStream stream(file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + QList keyList = settings.keys(); + + foreach (QString key, keyList) + { + SettingList *sectionSettings = settings[key]; + + stream << "[" << key << "]" << '\n'; + + foreach (SettingContainer *item, *sectionSettings) + stream << item->getName() << " = " << item->getValue() << '\n'; + } + + file->close(); + + return true; +} + +void CsSettings::UserSettings::getSettings(QTextStream &stream, SectionMap §ions) +{ + //looks for a square bracket, "'\\[" + //that has one or more "not nothing" in it, "([^]]+)" + //and is closed with a square bracket, "\\]" + + QRegExp sectionRe("^\\[([^]]+)\\]"); + + //Find any character(s) that is/are not equal sign(s), "[^=]+" + //followed by an optional whitespace, an equal sign, and another optional whirespace, "\\s*=\\s*" + //and one or more periods, "(.+)" + + QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); + + CsSettings::SettingMap *settings = 0; + QString section = "none"; + + while (!stream.atEnd()) + { + QString line = stream.readLine().simplified(); + + if (line.isEmpty() || line.startsWith("#")) + continue; + + //if a section is found, push it onto a new QStringList + //and push the QStringList onto + if (sectionRe.exactMatch(line)) + { + //add the previous section's settings to the member map + if (settings) + sections.insert(section, settings); + + //save new section and create a new list + section = sectionRe.cap(1); + settings = new SettingMap; + continue; + } + + if (keyRe.indexIn(line) != -1) + { + SettingContainer *sc = new SettingContainer (keyRe.cap(2).simplified()); + (*settings)[keyRe.cap(1).simplified()] = sc; + } + + } + sections.insert(section, settings); +} diff --git a/apps/opencs/settings/usersettings.hpp b/apps/opencs/settings/usersettings.hpp new file mode 100644 index 000000000..079e9c0e7 --- /dev/null +++ b/apps/opencs/settings/usersettings.hpp @@ -0,0 +1,35 @@ +#ifndef USERSETTINGS_HPP +#define USERSETTINGS_HPP + +#include +#include +#include +#include + +#include + +#include "support.hpp" + +namespace Files { typedef std::vector PathContainer; + struct ConfigurationManager;} + +class QFile; + +namespace CsSettings { + + class UserSettings + { + public: + UserSettings(Files::ConfigurationManager &cfg); + ~UserSettings(); + + QFile *openFile (const QString &); + bool writeFile(QFile *file, QMap §ions); + void getSettings (QTextStream &stream, SectionMap &settings); + + private: + Files::ConfigurationManager &mCfgMgr; + + }; +} +#endif // USERSETTINGS_HPP diff --git a/apps/opencs/settings/usersettingsdialog.cpp b/apps/opencs/settings/usersettingsdialog.cpp new file mode 100644 index 000000000..9777573ae --- /dev/null +++ b/apps/opencs/settings/usersettingsdialog.cpp @@ -0,0 +1,173 @@ +#include "usersettingsdialog.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "blankpage.hpp" +#include "editorpage.hpp" +#include "support.hpp" + +#include "settingwidget.hpp" +#include + +CsSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) : + QMainWindow (parent), mUserSettings (mCfgMgr), mStackedWidget (0) +{ + setWindowTitle(QString::fromUtf8 ("User Settings")); + buildPages(); + setWidgetStates (loadSettings()); + positionWindow (); + + connect (mListWidget, + SIGNAL (currentItemChanged(QListWidgetItem*, QListWidgetItem*)), + this, + SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*))); +} + +CsSettings::UserSettingsDialog::~UserSettingsDialog() +{ +} + +void CsSettings::UserSettingsDialog::closeEvent (QCloseEvent *event) +{ + writeSettings(); +} + +void CsSettings::UserSettingsDialog::setWidgetStates (SectionMap settingsMap) +{ + //iterate the tabWidget's pages (sections) + for (int i = 0; i < mStackedWidget->count(); i++) + { + //get the settings defined for the entire section + CsSettings::SettingMap *settings = settingsMap [mStackedWidget->widget(i)->objectName()]; + + //if found, initialize the page's widgets + if (settings) + { + AbstractPage *page = getAbstractPage (i); + page->initializeWidgets(*settings); + } + } +} + +void CsSettings::UserSettingsDialog::buildPages() +{ + //craete central widget with it's layout and immediate children + QWidget *centralWidget = new QWidget (this); + + mListWidget = new QListWidget (centralWidget); + mStackedWidget = new QStackedWidget (centralWidget); + + QLayout* dialogLayout = new QHBoxLayout(); + + dialogLayout->addWidget (mListWidget); + dialogLayout->addWidget (mStackedWidget); + + centralWidget->setLayout (dialogLayout); + + setCentralWidget (centralWidget); + setDockOptions (QMainWindow::AllowNestedDocks); + //uncomment to test with sample editor page. + //createSamplePage(); + createPage("Page1"); + createPage("Page2"); + createPage("Page3"); +} + +void CsSettings::UserSettingsDialog::createSamplePage() +{ + //add pages to stackedwidget and items to listwidget + CsSettings::AbstractPage *page + = new CsSettings::EditorPage(this); + + mStackedWidget->addWidget (page); + + new QListWidgetItem (page->objectName(), mListWidget); + + connect ( page, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)), + this, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); +} + +void CsSettings::UserSettingsDialog::positionWindow () +{ + QRect scr = QApplication::desktop()->screenGeometry(); + + move(scr.center().x() - (width() / 2), scr.center().y() - (height() / 2)); + +} + +CsSettings::SectionMap CsSettings::UserSettingsDialog::loadSettings () +{ + QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string()); + + mPaths.append(QString("opencs.cfg")); + mPaths.append(userPath + QString("opencs.cfg")); + + SectionMap settingsMap; + + foreach (const QString &path, mPaths) + { + qDebug() << "Loading config file:" << qPrintable(path); + QFile file(path); + + if (file.exists()) + { + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error opening OpenCS configuration file")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(QObject::tr("
Could not open %0 for reading

\ + Please make sure you have the right permissions \ + and try again.
").arg(file.fileName())); + msgBox.exec(); + return settingsMap; + } + + QTextStream stream(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + + mUserSettings.getSettings(stream, settingsMap); + } + + file.close(); + } + + return settingsMap; +} + +void CsSettings::UserSettingsDialog::writeSettings() +{ + QMap settings; + + for (int i = 0; i < mStackedWidget->count(); ++i) + { + AbstractPage *page = getAbstractPage (i); + settings [page->objectName()] = page->getSettings(); + } + + mUserSettings.writeFile(mUserSettings.openFile(mPaths.back()), settings); + +} + +CsSettings::AbstractPage *CsSettings::UserSettingsDialog::getAbstractPage (int index) +{ + return dynamic_cast(mStackedWidget->widget(index)); +} + +void CsSettings::UserSettingsDialog::slotChangePage(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (!current) + current = previous; + + if (!(current == previous)) + mStackedWidget->setCurrentIndex (mListWidget->row(current)); +} diff --git a/apps/opencs/settings/usersettingsdialog.hpp b/apps/opencs/settings/usersettingsdialog.hpp new file mode 100644 index 000000000..3b968e549 --- /dev/null +++ b/apps/opencs/settings/usersettingsdialog.hpp @@ -0,0 +1,71 @@ +#ifndef USERSETTINGSDIALOG_H +#define USERSETTINGSDIALOG_H + +#include +#include + +#include +#include "usersettings.hpp" +#include "support.hpp" + +class QHBoxLayout; +class AbstractWidget; +class QStackedWidget; +class QListWidget; + +namespace CsSettings { + + class AbstractPage; + class UserSettingsDialog : public QMainWindow + { + Q_OBJECT + + QStringList mPaths; + QListWidget *mListWidget; + QStackedWidget *mStackedWidget; + UserSettings mUserSettings; + Files::ConfigurationManager mCfgMgr; + + public: + UserSettingsDialog(QMainWindow *parent = 0); + ~UserSettingsDialog(); + + private: + + void closeEvent (QCloseEvent *event); + AbstractPage *getAbstractPage (int index); + void setWidgetStates (SectionMap settingsMap); + void buildPages(); + void positionWindow (); + SectionMap loadSettings(); + void writeSettings(); + void createSamplePage(); + + template + void createPage (const QString &title) + { + T *page = new T(title, this); + + mStackedWidget->addWidget (dynamic_cast(page)); + + new QListWidgetItem (page->objectName(), mListWidget); + + //finishing touches + if (mStackedWidget->sizeHint().width() < 640) + mStackedWidget->sizeHint().setWidth(640); + + if (mStackedWidget->sizeHint().height() < 480) + mStackedWidget->sizeHint().setHeight(480); + + resize (mStackedWidget->sizeHint()); + } + + signals: + void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); + + public slots: + void slotChangePage (QListWidgetItem*, QListWidgetItem*); + }; + +} +#endif // USERSETTINGSDIALOG_H diff --git a/apps/opencs/settings/usersettingsdialog.ui b/apps/opencs/settings/usersettingsdialog.ui new file mode 100644 index 000000000..4cd9dd113 --- /dev/null +++ b/apps/opencs/settings/usersettingsdialog.ui @@ -0,0 +1,68 @@ + + + UserSettingsDialog + + + + 0 + 0 + 638 + 478 + + + + Dialog + + + + + 10 + 440 + 621 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + buttonBox + accepted() + UserSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UserSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/apps/opencs/view/doc/startup.cpp b/apps/opencs/view/doc/startup.cpp index 7861a1c2e..6c1e74058 100644 --- a/apps/opencs/view/doc/startup.cpp +++ b/apps/opencs/view/doc/startup.cpp @@ -1,8 +1,11 @@ #include "startup.hpp" +#include +#include #include #include +#include CSVDoc::StartupDialogue::StartupDialogue() { @@ -17,4 +20,8 @@ CSVDoc::StartupDialogue::StartupDialogue() layout->addWidget (loadDocument); setLayout (layout); -} \ No newline at end of file + + QRect scr = QApplication::desktop()->screenGeometry(); + QRect rect = geometry(); + move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y()); +} diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 286d7a6ed..85821833b 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -9,15 +9,15 @@ #include #include "../../model/doc/document.hpp" - #include "../world/subviews.hpp" - #include "../tools/subviews.hpp" - +#include "../../settings/usersettingsdialog.hpp" #include "viewmanager.hpp" #include "operations.hpp" #include "subview.hpp" +#include + void CSVDoc::View::closeEvent (QCloseEvent *event) { if (!mViewManager.closeRequest (this)) @@ -80,12 +80,23 @@ void CSVDoc::View::setupWorldMenu() world->addAction (mVerify); } +void CSVDoc::View::setupSettingsMenu() +{ + QMenu *settings = menuBar()->addMenu( (tr ("&Settings"))); + + QAction *userSettings = new QAction (tr ("User Settings"), this); + connect (userSettings, SIGNAL (triggered()), this, SLOT (showUserSettings())); + settings->addAction (userSettings); + +} + void CSVDoc::View::setupUi() { setupFileMenu(); setupEditMenu(); setupViewMenu(); setupWorldMenu(); + setupSettingsMenu(); } void CSVDoc::View::updateTitle() @@ -243,3 +254,29 @@ QDockWidget *CSVDoc::View::getOperations() const { return mOperations; } + +void CSVDoc::View::showUserSettings() +{ + CsSettings::UserSettingsDialog *settingsDialog = new CsSettings::UserSettingsDialog(this); + + connect (settingsDialog, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), + this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)) ); + + settingsDialog->show(); +} + +void CSVDoc::View::slotUpdateEditorSetting(const QString &settingName, const QString &settingValue) +{ + static QString lastValue = ""; + + if (lastValue != settingValue) + { + if (settingName == "Undo Stack Size"); + + if (settingName == "Top-Level Window Count"); + + if (settingName == "Reuse Subwindows"); + + lastValue = settingValue; + } +} diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 28ab24b74..a46b72d42 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -59,6 +59,8 @@ namespace CSVDoc void setupWorldMenu(); + void setupSettingsMenu(); + void setupUi(); void updateTitle(); @@ -94,6 +96,8 @@ namespace CSVDoc void addSubView (const CSMWorld::UniversalId& id); + void slotUpdateEditorSetting (const QString &settingName, const QString &settingValue); + private slots: void newView(); @@ -107,6 +111,8 @@ namespace CSVDoc void addGmstsSubView(); void abortOperation (int type); + + void showUserSettings(); }; } diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 718b80728..81fb2f4e3 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -3,6 +3,9 @@ #include +#include +#include + #include "../../model/doc/documentmanager.hpp" #include "../../model/doc/document.hpp" @@ -69,6 +72,12 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) mViews.push_back (view); + if (mViews.size()==1) + { + QRect scr = QApplication::desktop()->screenGeometry(); + QRect rect = view->geometry(); + view->move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y()); + } view->show(); connect (view, SIGNAL (newDocumentRequest ()), this, SIGNAL (newDocumentRequest())); diff --git a/files/ui/datafilespage.ui b/files/ui/datafilespage.ui index 5c498d4d5..041a9576d 100644 --- a/files/ui/datafilespage.ui +++ b/files/ui/datafilespage.ui @@ -6,8 +6,8 @@ 0 0 - 520 - 256 + 518 + 304 @@ -112,7 +112,9 @@ - + + + New Profile @@ -126,7 +128,9 @@ - + + + Delete Profile From cb9c82324cbe5c35cba38720ae90d47a52c496be Mon Sep 17 00:00:00 2001 From: graffy76 Date: Tue, 7 May 2013 20:36:34 -0500 Subject: [PATCH 2/9] UserSettings system --- apps/opencs/settings/abstractblock.cpp | 111 +++++++++++++ apps/opencs/settings/abstractblock.hpp | 71 +++++++++ apps/opencs/settings/abstractpage.cpp | 39 +++++ apps/opencs/settings/abstractpage.hpp | 61 ++++++++ apps/opencs/settings/editorpage.cpp | 163 +++++++++++++++++++ apps/opencs/settings/editorpage.hpp | 28 ++++ apps/opencs/settings/groupblock.cpp | 108 +++++++++++++ apps/opencs/settings/groupblock.hpp | 32 ++++ apps/opencs/settings/groupbox.cpp | 56 +++++++ apps/opencs/settings/groupbox.hpp | 29 ++++ apps/opencs/settings/itemblock.cpp | 115 ++++++++++++++ apps/opencs/settings/itemblock.hpp | 38 +++++ apps/opencs/settings/settingsitem.cpp | 102 ++++++++++++ apps/opencs/settings/settingsitem.hpp | 47 ++++++ apps/opencs/settings/settingwidget.cpp | 1 + apps/opencs/settings/settingwidget.hpp | 208 +++++++++++++++++++++++++ apps/opencs/settings/support.cpp | 1 + apps/opencs/settings/support.hpp | 170 ++++++++++++++++++++ apps/opencs/settings/toggleblock.cpp | 80 ++++++++++ apps/opencs/settings/toggleblock.hpp | 27 ++++ 20 files changed, 1487 insertions(+) create mode 100644 apps/opencs/settings/abstractblock.cpp create mode 100644 apps/opencs/settings/abstractblock.hpp create mode 100644 apps/opencs/settings/abstractpage.cpp create mode 100644 apps/opencs/settings/abstractpage.hpp create mode 100644 apps/opencs/settings/editorpage.cpp create mode 100644 apps/opencs/settings/editorpage.hpp create mode 100644 apps/opencs/settings/groupblock.cpp create mode 100644 apps/opencs/settings/groupblock.hpp create mode 100644 apps/opencs/settings/groupbox.cpp create mode 100644 apps/opencs/settings/groupbox.hpp create mode 100644 apps/opencs/settings/itemblock.cpp create mode 100644 apps/opencs/settings/itemblock.hpp create mode 100644 apps/opencs/settings/settingsitem.cpp create mode 100644 apps/opencs/settings/settingsitem.hpp create mode 100644 apps/opencs/settings/settingwidget.cpp create mode 100644 apps/opencs/settings/settingwidget.hpp create mode 100644 apps/opencs/settings/support.cpp create mode 100644 apps/opencs/settings/support.hpp create mode 100644 apps/opencs/settings/toggleblock.cpp create mode 100644 apps/opencs/settings/toggleblock.hpp diff --git a/apps/opencs/settings/abstractblock.cpp b/apps/opencs/settings/abstractblock.cpp new file mode 100644 index 000000000..8fab5819c --- /dev/null +++ b/apps/opencs/settings/abstractblock.cpp @@ -0,0 +1,111 @@ +#include "abstractblock.hpp" + +CsSettings::AbstractBlock::AbstractBlock(QWidget* parent) + : QObject (parent), mBox ( new GroupBox (parent) ), mWidgetParent (parent) +{} + +CsSettings::AbstractBlock::AbstractBlock(bool isVisible, QWidget* parent) + : QObject (parent), mBox ( new GroupBox (isVisible, parent)), mWidgetParent (parent) +{} + +QLayout *CsSettings::AbstractBlock::createLayout (OcsWidgetOrientation direction, bool isZeroMargin, QWidget* parent) +{ + QLayout *layout = 0; + + if (direction == OCS_VERTICAL) + layout = new QVBoxLayout (parent); + else + layout = new QHBoxLayout (parent); + + if (isZeroMargin) + layout->setContentsMargins(0, 0, 0, 0); + + return layout; +} + +QGroupBox *CsSettings::AbstractBlock::getGroupBox() +{ + return mBox; +} + +CsSettings::AbstractWidget *CsSettings::AbstractBlock::buildWidget (const QString& widgetName, WidgetDef &def, + QLayout *layout, bool isConnected) const +{ + AbstractWidget *widg = 0; + + switch (def.type) + { + + case OCS_RADIO_WIDGET: + widg = createSettingWidget (def, layout); + break; + + case OCS_SPIN_WIDGET: + widg = createSettingWidget (def, layout); + break; + + case OCS_CHECK_WIDGET: + widg = createSettingWidget (def, layout); + break; + + case OCS_TEXT_WIDGET: + widg = createSettingWidget (def, layout); + break; + + case OCS_LIST_WIDGET: + widg = createSettingWidget (def, layout); + break; + + case OCS_COMBO_WIDGET: + widg = createSettingWidget (def, layout); + break; + + default: + break; + }; + + if (!mBox->layout()) + mBox->setLayout(widg->getLayout()); + + widg->widget()->setObjectName(widgetName); + + if (isConnected) + connect (widg, SIGNAL (signalUpdateItem (const QString &)), this, SLOT (slotUpdate (const QString &))); + connect (this, SIGNAL (signalUpdateWidget (const QString &)), widg, SLOT (slotUpdateWidget (const QString &) )); + + return widg; +} + +void CsSettings::AbstractBlock::setVisible (bool isVisible) +{ + mBox->setBorderVisibility (isVisible); +} + +bool CsSettings::AbstractBlock::isVisible () const +{ + return mBox->borderVisibile(); +} + +QWidget *CsSettings::AbstractBlock::getParent() const +{ + return mWidgetParent; +} + +void CsSettings::AbstractBlock::slotUpdate (const QString &value) +{ + slotUpdateSetting (objectName(), value); +} + +void CsSettings::AbstractBlock::slotSetEnabled(bool value) +{ + mBox->setEnabled(value); +} + +void CsSettings::AbstractBlock::slotUpdateSetting (const QString &settingName, const QString &settingValue) +{ + bool doEmit = true; + updateBySignal (settingName, settingValue, doEmit); + + if (doEmit) + emit signalUpdateSetting (settingName, settingValue); +} diff --git a/apps/opencs/settings/abstractblock.hpp b/apps/opencs/settings/abstractblock.hpp new file mode 100644 index 000000000..aa57d4fcb --- /dev/null +++ b/apps/opencs/settings/abstractblock.hpp @@ -0,0 +1,71 @@ +#ifndef ABSTRACTBLOCK_HPP +#define ABSTRACTBLOCK_HPP + +#include +#include + +#include "settingwidget.hpp" +#include "settingsitem.hpp" +#include "groupbox.hpp" + +namespace CsSettings +{ + + class AbstractBlock : public QObject + { + Q_OBJECT + + protected: + + typedef QMap SettingsItemMap; + GroupBox *mBox; + QWidget *mWidgetParent; + + public: + + explicit AbstractBlock (QWidget *parent = 0); + explicit AbstractBlock (bool isVisible, QWidget *parent = 0); + + QGroupBox *getGroupBox(); + void setVisible (bool isVisible); + bool isVisible() const; + + virtual SettingList *getSettings() = 0; + virtual bool updateSettings (const SettingMap &settings) = 0; + virtual bool updateBySignal (const QString &name, const QString &value, bool &doEmit) + { return false; } + + protected: + + QLayout *createLayout (OcsWidgetOrientation direction, bool isZeroMargin, QWidget* parent = 0); + AbstractWidget *buildWidget (const QString &widgetName, WidgetDef &wDef, + QLayout *layout = 0, bool isConnected = true) const; + + template + AbstractWidget *createSettingWidget (WidgetDef &wDef, QLayout *layout) const + { + return new SettingWidget (wDef, layout, mBox); + } + + QWidget *getParent() const; + + public slots: + + void slotSetEnabled (bool value); + void slotUpdateSetting (const QString &settingName, const QString &settingValue); + + private slots: + + void slotUpdate (const QString &value); + + signals: + + //signal to functions outside the settings tab widget + void signalUpdateSetting (const QString &propertyName, const QString &propertyValue); + void signalUpdateWidget (const QString & value); + + //propertyName and propertyValue are for properties for which the updated setting acts as a proxy + void signalUpdateProxySetting (const QString &propertyName, const QString &propertyValue); + }; +} +#endif // ABSTRACTBLOCK_HPP diff --git a/apps/opencs/settings/abstractpage.cpp b/apps/opencs/settings/abstractpage.cpp new file mode 100644 index 000000000..1fd60fbf0 --- /dev/null +++ b/apps/opencs/settings/abstractpage.cpp @@ -0,0 +1,39 @@ +#include "abstractpage.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CsSettings::AbstractPage::AbstractPage(QWidget *parent): + QWidget(parent) +{ +} + +CsSettings::AbstractPage::AbstractPage(const QString &pageName, QWidget *parent): + QWidget(parent) +{ + QWidget::setObjectName (pageName); +} + +CsSettings::AbstractPage::~AbstractPage() +{ +} + +CsSettings::SettingList *CsSettings::AbstractPage::getSettings() +{ + SettingList *settings = new SettingList(); + + foreach (AbstractBlock *block, mAbstractBlocks) + { + SettingList *groupSettings = block->getSettings(); + settings->append (*groupSettings); + } + + return settings; +} diff --git a/apps/opencs/settings/abstractpage.hpp b/apps/opencs/settings/abstractpage.hpp new file mode 100644 index 000000000..b5ee86f57 --- /dev/null +++ b/apps/opencs/settings/abstractpage.hpp @@ -0,0 +1,61 @@ +#ifndef ABSTRACTPAGE_HPP +#define ABSTRACTPAGE_HPP + +#include +#include +#include + +#include "abstractblock.hpp" + +class SettingMap; +class SettingList; + +namespace CsSettings { + + typedef QList AbstractBlockList; + + class AbstractPage: public QWidget + { + + Q_OBJECT + + protected: + + AbstractBlockList mAbstractBlocks; + + public: + + AbstractPage(QWidget *parent = 0); + AbstractPage (const QString &pageName, QWidget* parent = 0); + + ~AbstractPage(); + + virtual void setupUi()=0; + + virtual void initializeWidgets (const SettingMap &settings) = 0; + + SettingList *getSettings(); + + void setObjectName(); + + protected: + + template + AbstractBlock *buildBlock (T &def) + { + S *block = new S (this); + int ret = block->build (def); + + if (ret < 0) + return 0; + + QWidget::layout()->addWidget (block->getGroupBox()); + + return block; + } + + + }; +} + +#endif // ABSTRACTPAGE_HPP diff --git a/apps/opencs/settings/editorpage.cpp b/apps/opencs/settings/editorpage.cpp new file mode 100644 index 000000000..eb6b58ef9 --- /dev/null +++ b/apps/opencs/settings/editorpage.cpp @@ -0,0 +1,163 @@ +#include "editorpage.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_OS_MAC +#include +#endif + +#include "usersettings.hpp" +#include "groupblock.hpp" +#include "toggleblock.hpp" + +CsSettings::EditorPage::EditorPage(QWidget *parent): + AbstractPage("Editor", parent) +{ + // Hacks to get the stylesheet look properly +#ifdef Q_OS_MAC + QPlastiqueStyle *style = new QPlastiqueStyle; + //profilesComboBox->setStyle(style); +#endif + + setupUi(); +} + +void CsSettings::EditorPage::setupUi() +{ + GroupBlockDef undoStack (QString("Undo Stack Size")); + GroupBlockDef topLevelWindowCount (QString("Maximum Top-Level Window Count")); + GroupBlockDef reuseSubwindow (QString("Reuse Subwindows")); + GroupBlockDef customWindowSize (QString ("Custom Window Size")); + GroupBlockDef definedWindowSize (QString ("Pre-Defined Window Size")); + GroupBlockDef windowSizeToggle (QString ("Window Size")); + CustomBlockDef windowSize (QString ("Window Size")); + + //////////////////////////// + //undo stack size property + /////////////////////////// + + SettingsItemDef *undoStackItem = new SettingsItemDef (undoStack.title, "32"); + undoStack.properties << undoStackItem; + undoStackItem->minMax.left = "0"; + undoStackItem->minMax.right = "64"; + + WidgetDef stackWidget (OCS_SPIN_WIDGET); + stackWidget.minMax = &(undoStackItem->minMax); + stackWidget.widgetWidth = 50; + + undoStackItem->widget = stackWidget; + + ////////////////////////////////////// + //number of top level windows property + ///////////////////////////////////// + + SettingsItemDef *topLevelItem = new SettingsItemDef (topLevelWindowCount.title, "100"); + topLevelWindowCount.properties << topLevelItem; + topLevelItem->minMax.left = "1"; + topLevelItem->minMax.right = "256"; + + WidgetDef topLvlWinWidget (OCS_SPIN_WIDGET); + topLvlWinWidget.minMax = &(topLevelItem->minMax); + topLvlWinWidget.widgetWidth = 50; + + topLevelItem->widget = topLvlWinWidget; + + /////////////////////////// + //reuse subwindows property + //////////////////////////// + + SettingsItemDef *reuseSubItem = new SettingsItemDef (reuseSubwindow.title, "Reuse Subwindows"); + *(reuseSubItem->valueList) << "None" << "Top-Level" << "Document-Level"; + + WidgetDef reuseSubWidget (OCS_RADIO_WIDGET); + reuseSubWidget.valueList = (reuseSubItem->valueList); + reuseSubWidget.widgetAlignment = OCS_LEFT; + + reuseSubwindow.properties << reuseSubItem; + reuseSubItem->widget = reuseSubWidget; + + /////////////////////////////// + //custom window size properties + /////////////////////////////// + + //custom width + SettingsItemDef *widthItem = new SettingsItemDef ("Window Width", "640"); + widthItem->widget = WidgetDef (OCS_TEXT_WIDGET); + widthItem->widget.widgetWidth = 45; + + //custom height + SettingsItemDef *heightItem = new SettingsItemDef ("Window Height", "480"); + heightItem->widget = WidgetDef (OCS_TEXT_WIDGET); + heightItem->widget.widgetWidth = 45; + heightItem->widget.caption = "x"; + + customWindowSize.properties << widthItem << heightItem; + customWindowSize.widgetOrientation = OCS_HORIZONTAL; + customWindowSize.isVisible = false; + + + //pre-defined + SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480"); + WidgetDef widthByHeightWidget = WidgetDef (OCS_COMBO_WIDGET); + widthByHeightWidget.widgetWidth = 90; + *(widthByHeightItem->valueList) << "640x480" << "800x600" << "1024x768"; + + QStringList *widthProxy = new QStringList; + QStringList *heightProxy = new QStringList; + + (*widthProxy) << "Window Width" << "640" << "800" << "1024"; + (*heightProxy) << "Window Height" << "480" << "600" << "768"; + + *(widthByHeightItem->proxyList) << widthProxy << heightProxy; + + widthByHeightItem->widget = widthByHeightWidget; + + definedWindowSize.properties << widthByHeightItem; + definedWindowSize.isProxy = true; + definedWindowSize.isVisible = false; + + // window size toggle + windowSizeToggle.captions << "Pre-Defined" << "Custom"; + windowSizeToggle.widgetOrientation = OCS_VERTICAL; + windowSizeToggle.isVisible = false; + + //define a widget for each group in the toggle + for (int i = 0; i < 2; i++) + windowSizeToggle.widgets << new WidgetDef (OCS_RADIO_WIDGET); + + windowSizeToggle.widgets.at(0)->isDefault = false; + + windowSize.blockDefList << &windowSizeToggle << &definedWindowSize << &customWindowSize; + windowSize.defaultValue = "Custom"; + + QGridLayout *pageLayout = new QGridLayout(this); + + setLayout (pageLayout); + + mAbstractBlocks << buildBlock (topLevelWindowCount) + << buildBlock (reuseSubwindow) + << buildBlock (windowSize) + << buildBlock (undoStack); + + foreach (AbstractBlock *block, mAbstractBlocks) + { + connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)), + this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) ); + } +} + +void CsSettings::EditorPage::initializeWidgets (const SettingMap &settings) +{ + //iterate each item in each blocks in this section + //validate the corresponding setting against the defined valuelist if any. + for (AbstractBlockList::Iterator it_block = mAbstractBlocks.begin(); + it_block != mAbstractBlocks.end(); ++it_block) + (*it_block)->updateSettings (settings); +} diff --git a/apps/opencs/settings/editorpage.hpp b/apps/opencs/settings/editorpage.hpp new file mode 100644 index 000000000..87ae7da83 --- /dev/null +++ b/apps/opencs/settings/editorpage.hpp @@ -0,0 +1,28 @@ +#ifndef EDITORPAGE_H +#define EDITORPAGE_H + +#include "abstractpage.hpp" + +class QGroupBox; + +namespace CsSettings { + + class UserSettings; + class AbstractBlock; + + class EditorPage : public AbstractPage + { + Q_OBJECT + + public: + + EditorPage(QWidget *parent = 0); + + void setupUi(); + void initializeWidgets (const SettingMap &settings); + + signals: + void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); + }; +} +#endif //EDITORPAGE_H diff --git a/apps/opencs/settings/groupblock.cpp b/apps/opencs/settings/groupblock.cpp new file mode 100644 index 000000000..b5917ec38 --- /dev/null +++ b/apps/opencs/settings/groupblock.cpp @@ -0,0 +1,108 @@ +#include "groupblock.hpp" +#include "itemblock.hpp" + +CsSettings::GroupBlock::GroupBlock (QWidget* parent) + : AbstractBlock (parent) +{} + +CsSettings::GroupBlock::GroupBlock (bool isVisible, QWidget *parent) + : AbstractBlock (isVisible, parent) +{} + +int CsSettings::GroupBlock::build (GroupBlockDef &def) +{ + + if (def.properties.size() == 0) + return -1; + + int retVal = 0; + + setVisible (def.isVisible); + + mBox->setLayout(createLayout (def.widgetOrientation, true)); + + setObjectName (def.title); + mBox->setTitle (def.title); + + foreach (SettingsItemDef *itemDef, def.properties) + { + ItemBlock *block = new ItemBlock (mBox); + + if (block->build (*itemDef) < 0) + { + retVal = -2; + break; + } + + mItemBlockList << block; + mBox->layout()->addWidget (block->getGroupBox()); + + connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)), + this, SLOT (slotUpdateSetting (const QString &, const QString &) )); + } + + return retVal; +} + +CsSettings::SettingList *CsSettings::GroupBlock::getSettings() +{ + SettingList *settings = 0; + + foreach (ItemBlock *block, mItemBlockList) + { + if (!settings) + settings = new SettingList(); + + settings->append(*(block->getSettings ())); + } + + return settings; +} + +CsSettings::ItemBlock *CsSettings::GroupBlock::getItemBlock (const QString &name, ItemBlockList *blockList) +{ + ItemBlock *retBlock = 0; + + if (!blockList) + blockList = &mItemBlockList; + + foreach (ItemBlock *block, *blockList) + { + if (block->objectName() == name) + { + retBlock = block; + break; + } + } + + return retBlock; +} + +CsSettings::ItemBlock *CsSettings::GroupBlock::getItemBlock (int index) +{ + ItemBlock *retBlock = 0; + + if (mItemBlockList.size() > index) + retBlock = mItemBlockList.at(index); + + return retBlock; +} + +bool CsSettings::GroupBlock::updateSettings (const SettingMap &settings) +{ + bool success = true; + + //update all non-proxy settings + foreach (ItemBlock *block, mItemBlockList) + { + SettingContainer *setting = settings[block->objectName()]; + + if (setting) + { + bool success2 = block->update (setting->getValue()); + success = success && success2; + } + } + + return success; +} diff --git a/apps/opencs/settings/groupblock.hpp b/apps/opencs/settings/groupblock.hpp new file mode 100644 index 000000000..f3b0c4bae --- /dev/null +++ b/apps/opencs/settings/groupblock.hpp @@ -0,0 +1,32 @@ +#ifndef GROUPBLOCK_HPP +#define GROUPBLOCK_HPP + +#include +#include "abstractblock.hpp" + +namespace CsSettings +{ + class ItemBlock; + + class GroupBlock : public AbstractBlock + { + ItemBlockList mItemBlockList; + + public: + GroupBlock (QWidget* parent = 0); + GroupBlock (bool isVisible, QWidget *parent = 0); + + int build (GroupBlockDef &def); + + bool updateSettings (const SettingMap &settings); + + SettingList *getSettings(); + ItemBlock *getItemBlock (const QString &name, ItemBlockList *blockList = 0); + ItemBlock *getItemBlock (int index); + + protected: + int buildLayout (GroupBlockDef &def); + + }; +} +#endif // GROUPBLOCK_HPP diff --git a/apps/opencs/settings/groupbox.cpp b/apps/opencs/settings/groupbox.cpp new file mode 100644 index 000000000..c996a22aa --- /dev/null +++ b/apps/opencs/settings/groupbox.cpp @@ -0,0 +1,56 @@ +#include "groupbox.hpp" + +const QString CsSettings::GroupBox::INVISIBLE_BOX_STYLE = + QString::fromUtf8("QGroupBox { border: 0px; padding 0px; margin: 0px;}"); + +CsSettings::GroupBox::GroupBox(QWidget *parent) : + QGroupBox (parent) +{ + initBox(); +} + +CsSettings::GroupBox::GroupBox (bool isVisible, QWidget *parent) : + QGroupBox (parent) +{ + initBox(isVisible); +} + +void CsSettings::GroupBox::initBox(bool isVisible) +{ + setFlat (true); + VISIBLE_BOX_STYLE = styleSheet(); + + if (!isVisible) + setStyleSheet (INVISIBLE_BOX_STYLE); +} + +bool CsSettings::GroupBox::borderVisibile() const +{ + return (styleSheet() != INVISIBLE_BOX_STYLE); +} + +void CsSettings::GroupBox::setTitle (const QString &title) +{ + if (borderVisibile() ) + { + QGroupBox::setTitle (title); + setMinimumWidth(); + } +} + +void CsSettings::GroupBox::setBorderVisibility (bool value) +{ + if (value) + setStyleSheet(VISIBLE_BOX_STYLE); + else + setStyleSheet(INVISIBLE_BOX_STYLE); +} + +void CsSettings::GroupBox::setMinimumWidth() +{ + //set minimum width to accommodate title, if needed + //1.5 multiplier to account for bold title. + QFontMetrics fm (font()); + int minWidth = fm.width(title()); + QGroupBox::setMinimumWidth (minWidth * 1.5); +} diff --git a/apps/opencs/settings/groupbox.hpp b/apps/opencs/settings/groupbox.hpp new file mode 100644 index 000000000..d229dbc8e --- /dev/null +++ b/apps/opencs/settings/groupbox.hpp @@ -0,0 +1,29 @@ +#ifndef GROUPBOX_HPP +#define GROUPBOX_HPP + +#include + +namespace CsSettings +{ + class GroupBox : public QGroupBox + { + Q_OBJECT + + static const QString INVISIBLE_BOX_STYLE; + QString VISIBLE_BOX_STYLE; //not a const... + + public: + explicit GroupBox (QWidget *parent = 0); + explicit GroupBox (bool isVisible, QWidget *parent = 0); + + void setTitle (const QString &title); + void setBorderVisibility (bool value); + bool borderVisibile() const; + + private: + void setMinimumWidth(); + void initBox(bool isVisible = true); + }; +} + +#endif // GROUPBOX_HPP diff --git a/apps/opencs/settings/itemblock.cpp b/apps/opencs/settings/itemblock.cpp new file mode 100644 index 000000000..261319d8d --- /dev/null +++ b/apps/opencs/settings/itemblock.cpp @@ -0,0 +1,115 @@ +#include "itemblock.hpp" + +#include + +CsSettings::ItemBlock::ItemBlock (QWidget* parent) + : mSetting (0), AbstractBlock (false, parent) +{ +} + +int CsSettings::ItemBlock::build(SettingsItemDef &iDef) +{ + buildItemBlock (iDef); + buildItemBlockWidgets (iDef); + + return 0; +} + +void CsSettings::ItemBlock::buildItemBlockWidgets (SettingsItemDef &iDef) +{ + WidgetDef wDef = iDef.widget; + QLayout *blockLayout = 0; + QString defaultValue = iDef.defaultValue; + + switch (wDef.type) + { + + case OCS_CHECK_WIDGET: + case OCS_RADIO_WIDGET: + + foreach (QString item, *(iDef.valueList)) + { + wDef.caption = item; + wDef.isDefault = (item == defaultValue); + + blockLayout = buildWidget (item, wDef, blockLayout)->getLayout(); + } + + break; + + case OCS_COMBO_WIDGET: + case OCS_LIST_WIDGET: + + //assign the item's value list to the widget's value list. + //pass through to default to finish widget construction. + if (!wDef.valueList) + wDef.valueList = iDef.valueList; + + default: + //only one instance of this non-list widget type. + //Set it's value to the default value for the item and build the widget. + + if (wDef.value.isEmpty()) + wDef.value = iDef.defaultValue; + + buildWidget (iDef.name, wDef); + } +} + +void CsSettings::ItemBlock::buildItemBlock (SettingsItemDef &iDef) +{ + QString defaultValue = iDef.defaultValue; + + setObjectName(iDef.name); + + mSetting = new SettingsItem (objectName(), + iDef.hasMultipleValues, iDef.defaultValue, + parent()); + + if (iDef.valueList) + mSetting->setValueList(iDef.valueList); + + if (!iDef.minMax.isEmpty()) + mSetting->setValuePair(iDef.minMax); +} + + +bool CsSettings::ItemBlock::update (const QString &value) +{ + bool success = updateItem (value); + + if (success) + signalUpdateWidget (value); + + return success; +} + + +bool CsSettings::ItemBlock::updateItem (const QString &value) +{ + return mSetting->updateItem(value); +} + + +bool CsSettings::ItemBlock::updateBySignal(const QString &name, const QString &value, bool &doEmit) +{ + bool success = (mSetting->getValue() != value); + + if (success) + success = updateItem(value); + + return success; +} + +CsSettings::SettingList *CsSettings::ItemBlock::getSettings () +{ + SettingList *list = new SettingList(); + list->push_back(mSetting); + + return list; +} + +QString CsSettings::ItemBlock::getValue() const +{ + return mSetting->getValue(); +} diff --git a/apps/opencs/settings/itemblock.hpp b/apps/opencs/settings/itemblock.hpp new file mode 100644 index 000000000..8aab65745 --- /dev/null +++ b/apps/opencs/settings/itemblock.hpp @@ -0,0 +1,38 @@ +#ifndef ITEMBLOCK_HPP +#define ITEMBLOCK_HPP + +#include "abstractblock.hpp" + +namespace CsSettings +{ + + class ItemBlock : public AbstractBlock + { + SettingsItem *mSetting; + WidgetList mWidgetList; + + public: + + ItemBlock (QWidget* parent = 0); + + bool updateSettings (const SettingMap &settings) { return false; } + + SettingList *getSettings (); + QString getValue () const; + + int getSettingCount(); + bool update (const QString &value); + + int build(SettingsItemDef &iDef); + + private: + + void buildItemBlock (SettingsItemDef& iDef); + void buildItemBlockWidgets (SettingsItemDef& iDef); + bool updateItem (const QString &); + + bool updateBySignal (const QString &name, const QString &value, bool &doEmit); + }; +} + +#endif // ITEMBLOCK_HPP diff --git a/apps/opencs/settings/settingsitem.cpp b/apps/opencs/settings/settingsitem.cpp new file mode 100644 index 000000000..b2a8b509b --- /dev/null +++ b/apps/opencs/settings/settingsitem.cpp @@ -0,0 +1,102 @@ +#include "settingsitem.hpp" + +bool CsSettings::SettingsItem::updateItem (const QStringList *values) +{ + QStringList::ConstIterator it = values->begin(); + + //if the item is not multivalued, + //save the last value passed in the container + if (!mIsMultiValue) + { + it = values->end(); + it--; + } + + bool isValid = true; + QString value (""); + + for (; it != values->end(); ++it) + { + value = *it; + isValid = validate(value); + + //skip only the invalid values + if (!isValid) + continue; + + insert(value); + } + + return isValid; +} + +bool CsSettings::SettingsItem::updateItem (const QString &value) +{ + //takes a value or a SettingsContainer and updates itself accordingly + //after validating the data against it's own definition + + QString newValue = value; + + if (!validate (newValue)) + newValue = mDefaultValue; + + bool success = (getValue() != newValue); + + if (success) + { + if (mIsMultiValue) + insert (newValue); + else + update (newValue); + } + return success; +} + +bool CsSettings::SettingsItem::updateItem(int valueListIndex) +{ + bool success = false; + + if (mValueList) + { + if (mValueList->size() > valueListIndex) + success = updateItem (mValueList->at(valueListIndex)); + } + return success; +} + +bool CsSettings::SettingsItem::validate (const QString &value) +{ + bool isValid = true; + + //validation required only if a value list or min/max value pair has been provided + if (mValueList->size()>0) + { + for (QStringList::ConstIterator it = mValueList->begin(); it !=mValueList->end(); ++it) + { + isValid = ( value == *it); + + if (isValid) + break; + } + } + + else if (mValuePair) + { + int numVal = value.toInt(); + + isValid = (numVal > mValuePair->left.toInt() && numVal < mValuePair->right.toInt()); + } + + return isValid; +} + +void CsSettings::SettingsItem::setDefaultValue (const QString &value) +{ + mDefaultValue = value; + update (value); +} + +QString CsSettings::SettingsItem::getDefaultValue() const +{ + return mDefaultValue; +} diff --git a/apps/opencs/settings/settingsitem.hpp b/apps/opencs/settings/settingsitem.hpp new file mode 100644 index 000000000..8168edee5 --- /dev/null +++ b/apps/opencs/settings/settingsitem.hpp @@ -0,0 +1,47 @@ +#ifndef SETTINGSITEM_HPP +#define SETTINGSITEM_HPP + +#include +#include "support.hpp" +#include "settingcontainer.hpp" + +namespace CsSettings +{ + class SettingsItem : public SettingContainer + { + QStringPair *mValuePair; + QStringList *mValueList; + bool mIsMultiValue; + QString mName; + QString mDefaultValue; + + public: + explicit SettingsItem(QString name, bool isMultiValue, + const QString& defaultValue, QObject *parent = 0) + : SettingContainer(defaultValue, parent), + mIsMultiValue (isMultiValue), mValueList (0), + mName (name), mValuePair (0), mDefaultValue (defaultValue) + {} + + bool updateItem (const QStringList *values); + bool updateItem (const QString &value); + bool updateItem (int valueListIndex); + + inline QStringList *getValueList() { return mValueList; } + inline void setValueList (QStringList *valueList) { mValueList = valueList; } + + inline QStringPair *getValuePair() { return mValuePair; } + inline void setValuePair (QStringPair valuePair) { mValuePair = new QStringPair(valuePair); } + + inline QString getName () const { return mName; } + inline bool isMultivalue () { return mIsMultiValue; } + + void setDefaultValue (const QString &value); + QString getDefaultValue () const; + + private: + bool validate (const QString &value); + }; +} +#endif // SETTINGSITEM_HPP + diff --git a/apps/opencs/settings/settingwidget.cpp b/apps/opencs/settings/settingwidget.cpp new file mode 100644 index 000000000..2c93986e7 --- /dev/null +++ b/apps/opencs/settings/settingwidget.cpp @@ -0,0 +1 @@ +#include "settingwidget.hpp" diff --git a/apps/opencs/settings/settingwidget.hpp b/apps/opencs/settings/settingwidget.hpp new file mode 100644 index 000000000..4e4bad132 --- /dev/null +++ b/apps/opencs/settings/settingwidget.hpp @@ -0,0 +1,208 @@ +#ifndef SETTINGWIDGET_HPP +#define SETTINGWIDGET_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "abstractwidget.hpp" + +namespace CsSettings +{ + //VALID FOR RADIOBUTTON / CHECKBOX (or other toggle widget with it's own label) + template + class SettingWidget : public AbstractWidget + { + + T1 *mWidget; + + public: + + explicit SettingWidget(WidgetDef &def, QLayout *layout, QWidget* parent = 0) + : AbstractWidget (layout, parent), mWidget (new T1 (parent)) + { + mWidget->setText(def.caption); + build (mWidget, def, true); + mWidget->setChecked(def.isDefault); + + connect (mWidget, SIGNAL (toggled (bool)), + this, SLOT (slotUpdateItem (bool))); + } + + QWidget *widget() { return mWidget; } + + private: + + void updateWidget (const QString &value) + { + if ( value == mWidget->objectName() && !mWidget->isChecked() ) + mWidget->setChecked (true); + } + }; + + template <> + class SettingWidget : public AbstractWidget + { + + QSpinBox *mWidget; + + public: + + SettingWidget(WidgetDef &def, QLayout *layout, QWidget *parent = 0) + : AbstractWidget (layout, parent), mWidget (new QSpinBox (parent)) + { + def.caption += tr(" (%1 to %2)").arg(def.minMax->left).arg(def.minMax->right); + + mWidget->setMaximum (def.minMax->right.toInt()); + mWidget->setMinimum (def.minMax->left.toInt()); + mWidget->setValue (def.value.toInt()); + + build (mWidget, def); + + connect (mWidget, SIGNAL (valueChanged (int)), + this, SLOT (slotUpdateItem (int))); + + mWidget->setAlignment (getAlignment(def.valueAlignment)); + + + } + + QWidget *widget() { return mWidget; } + + private: + + void updateWidget (const QString &value) + { + int intVal = value.toInt(); + + if (intVal >= mWidget->minimum() && intVal <= mWidget->maximum() && intVal != mWidget->value()) + mWidget->setValue (intVal); + } + + signals: + + }; + + template <> + class SettingWidget : public CsSettings::AbstractWidget + { + + QComboBox *mWidget; + + + public: + + explicit SettingWidget(WidgetDef &def, QLayout *layout, QWidget *parent = 0) + : AbstractWidget (layout, parent), mWidget (new QComboBox (parent)) + { + int i = 0; + + foreach (QString item, *(def.valueList)) + { + mWidget->addItem (item); + + if (item == def.value) + mWidget->setCurrentIndex(i); + + i++; + } + + build (mWidget, def); + + connect (mWidget, SIGNAL (currentIndexChanged (const QString &)), + this, SLOT (slotUpdateItem (const QString &))); + + //center the combo box items + mWidget->setEditable (true); + mWidget->lineEdit()->setReadOnly (true); + mWidget->lineEdit()->setAlignment (getAlignment(def.valueAlignment)); + + QFlags alignment = mWidget->lineEdit()->alignment(); + + for (int j = 0; j < mWidget->count(); j++) + mWidget->setItemData (j, QVariant(alignment), Qt::TextAlignmentRole); + } + + QWidget *widget() { return mWidget; } + + private: + + void updateWidget (const QString &value) + { + if (mWidget->currentText() != value) + mWidget->setCurrentIndex(mWidget->findText(value)); + } + + }; + + template <> + class SettingWidget : public CsSettings::AbstractWidget + { + + QLineEdit *mWidget; + + public: + + explicit SettingWidget(WidgetDef &def, QLayout *layout, QWidget *parent = 0) + : AbstractWidget (layout, parent), mWidget (new QLineEdit (parent)) + { + if (!def.inputMask.isEmpty()) + mWidget->setInputMask (def.inputMask); + + mWidget->setText (def.value); + + build (mWidget, def); + + connect (mWidget, SIGNAL (textChanged (const QString &)), + this, SLOT (slotUpdateItem (const QString &))); + + mWidget->setAlignment (getAlignment(def.valueAlignment)); + } + + QWidget *widget() { return mWidget; } + + void updateWidget (const QString &value) + { + if (mWidget->text() != value) + mWidget->setText(value); + } + }; + + template <> + class SettingWidget : public CsSettings::AbstractWidget + { + + QListWidget *mWidget; + + public: + + explicit SettingWidget(WidgetDef &def, QLayout *layout, QWidget *parent = 0 ) + : AbstractWidget (layout, parent), mWidget (new QListWidget (parent)) + { + int i = 0; + + foreach (QString item, *(def.valueList)) + { + mWidget->addItem (item); + + if (item == def.value) {} + i++; + } + build (mWidget, def); + } + + QWidget *widget() { return mWidget; } + + private: + void updateWidget (const QString &value) {} + }; + +} +#endif // SETTINGWIDGET_HPP diff --git a/apps/opencs/settings/support.cpp b/apps/opencs/settings/support.cpp new file mode 100644 index 000000000..d79edfdb3 --- /dev/null +++ b/apps/opencs/settings/support.cpp @@ -0,0 +1 @@ +#include "support.hpp" diff --git a/apps/opencs/settings/support.hpp b/apps/opencs/settings/support.hpp new file mode 100644 index 000000000..6953cbb61 --- /dev/null +++ b/apps/opencs/settings/support.hpp @@ -0,0 +1,170 @@ +#ifndef SUPPORT_HPP +#define SUPPORT_HPP + +#include +#include + +class QLayout; +class QWidget; +class QListWidgetItem; + +namespace CsSettings +{ + + class SettingContainer; + struct WidgetDef; + class ItemBlock; + class GroupBlock; + struct GroupBlockDef; + + typedef QList GroupBlockDefList; + typedef QList GroupBlockList; + typedef QList ItemBlockList; + typedef QList SettingList; + typedef QMap SettingMap; + typedef QMap SectionMap; + typedef QList ProxyList; + typedef QList WidgetList; + typedef QMap ItemBlockMap; + + enum OcsWidgetOrientation + { + OCS_HORIZONTAL, + OCS_VERTICAL + }; + + enum OcsWidgetType + { + OCS_CHECK_WIDGET, + OCS_COMBO_WIDGET, + OCS_TEXT_WIDGET, + OCS_LIST_WIDGET, + OCS_RADIO_WIDGET, + OCS_SPIN_WIDGET, + OCS_UNDEFINED_WIDGET + }; + + enum OcsAlignment + { + OCS_LEFT = Qt::AlignLeft, + OCS_CENTER = Qt::AlignHCenter, + OCS_RIGHT = Qt::AlignRight + }; + + struct QStringPair + { + QStringPair(): left (""), right ("") + {} + + QStringPair (const QString &leftValue, const QString &rightValue) + : left (leftValue), right(rightValue) + {} + + QStringPair (const QStringPair &pair) + : left (pair.left), right (pair.right) + {} + + QString left; + QString right; + + bool isEmpty() + { return (left.isEmpty() && right.isEmpty()); } + }; + + //template for defining the widget of a property. + struct WidgetDef + { + OcsWidgetType type; //type of widget providing input + int labelWidth; //width of caption label + int widgetWidth; //width of input widget + OcsWidgetOrientation orientation; //label / widget orientation (horizontal / vertical) + QString inputMask; //input mask (line edit) + QString caption; //label caption. Leave empty for multiple items. See BlockDef::captionList + QString value; //widget value. Leave empty for multiple items. See BlockDef::valueList + QStringPair *minMax; //Min/Max QString value pair. If empty, assigned to property item value pair. + QStringList *valueList; //value list for list widgets. If left empty, is assigned to property item value list during block build(). + bool isDefault; //isDefault - determined at runtime. + OcsAlignment valueAlignment; //left / center / right-justify text in widget + OcsAlignment widgetAlignment; //left / center / right-justify widget in group box + + + WidgetDef() : labelWidth (-1), widgetWidth (-1), + orientation (OCS_HORIZONTAL), + isDefault (true), valueAlignment (OCS_CENTER), + widgetAlignment (OCS_RIGHT), + inputMask (""), value (""), + caption (""), valueList (0) + {} + + WidgetDef (OcsWidgetType widgType) + : type (widgType), orientation (OCS_HORIZONTAL), + caption (""), value (""), valueAlignment (OCS_CENTER), + widgetAlignment (OCS_RIGHT), + labelWidth (-1), widgetWidth (-1), + valueList (0), isDefault (true) + {} + + }; + + //Defines the attributes of the property as it is represented in the config file + //as well as the UI elements (group box and widget) that serve it. + //Only one widget may serve as the input widget for the property. + struct SettingsItemDef + { + QString name; //property name + QStringList *valueList; //list of valid values for the property. + //Used to populate option widget captions or list widget item lists (see WidgetDef::caption / value) + QString defaultValue; + bool hasMultipleValues; + QStringPair minMax; //minimum / maximum value pair + WidgetDef widget; //definition of the input widget for this setting + OcsWidgetOrientation orientation; //general orientation of the widget / label for this property + ProxyList *proxyList; //list of property and corresponding default values for proxy widget + + SettingsItemDef() : name (""), defaultValue (""), orientation (OCS_VERTICAL), hasMultipleValues (false) + {} + + SettingsItemDef (QString propName, QString propDefault, OcsWidgetOrientation propOrient = OCS_VERTICAL) + : name (propName), defaultValue (propDefault), orientation (propOrient), + hasMultipleValues(false), valueList (new QStringList), proxyList ( new ProxyList) + {} + }; + + + //Hierarchically, this is a "sub-section" of properties within a section, solely for UI organization. + //Does not correlate to config file structure. + struct GroupBlockDef + { + QString title; //title of the block containing the property or properties of this sub-section + QStringList captions; //list of captions for widgets at the block level (not associated with any particular property) + WidgetList widgets; //list of widgets at the block level (not associated with any particular property) + QList properties; //list of the property(ies) which are subordinate to the property block. + OcsWidgetOrientation widgetOrientation; //general orientation of widgets in group block + bool isVisible; //determines whether or not box border/title are visible + bool isProxy; //indicates whether or not this block defines a proxy block + QString defaultValue; //generic default value attribute + + GroupBlockDef (): title(""), widgetOrientation (OCS_VERTICAL), isVisible (true), isProxy (false), defaultValue ("") + {} + + GroupBlockDef (QString blockTitle) + : title (blockTitle), widgetOrientation (OCS_VERTICAL), isProxy (false), isVisible (true), defaultValue ("") + {} + }; + + struct CustomBlockDef + { + QString title; + QString defaultValue; //default value for widgets unique to the custom block + GroupBlockDefList blockDefList; //list of settings groups that comprise the settings within the custom block + OcsWidgetOrientation blockOrientation; + + CustomBlockDef (): title (""), defaultValue (""), blockOrientation (OCS_HORIZONTAL) + {} + + CustomBlockDef (const QString &blockTitle) + : title (blockTitle), defaultValue (""), blockOrientation (OCS_HORIZONTAL) + {} + }; +} +#endif // SUPPORT_HPP diff --git a/apps/opencs/settings/toggleblock.cpp b/apps/opencs/settings/toggleblock.cpp new file mode 100644 index 000000000..f30ffceb0 --- /dev/null +++ b/apps/opencs/settings/toggleblock.cpp @@ -0,0 +1,80 @@ +#include "toggleblock.hpp" +#include "groupblock.hpp" +#include "groupbox.hpp" +#include "itemblock.hpp" + +CsSettings::ToggleBlock::ToggleBlock(QWidget *parent) : + CustomBlock(parent) +{} + +int CsSettings::ToggleBlock::build(CustomBlockDef &def) +{ + if (def.blockDefList.size()==0) + return -1; + + QList::Iterator it = def.blockDefList.begin(); + + //first def in the list is the def for the toggle block + GroupBlockDef *toggleDef = *it++; + + if (toggleDef->captions.size() != def.blockDefList.size()-1 ) + return -2; + + if (toggleDef->widgets.size() == 0) + return -3; + + //create the toogle block UI structure + QLayout *blockLayout = createLayout (def.blockOrientation, true); + GroupBox *propertyBox = buildGroupBox (toggleDef->widgetOrientation); + + mBox->setLayout(blockLayout); + mBox->setTitle (toggleDef->title); + + //build the blocks contained in the def list + //this manages proxy block construction. + //Any settings managed by the proxy setting + //must be included in the blocks defined in the list. + CustomBlock::build (def.blockDefList, &it); + + for (GroupBlockList::iterator it = mGroupList.begin(); it != mGroupList.end(); ++it) + propertyBox->layout()->addWidget ((*it)->getGroupBox()); + + //build togle widgets, linking them to the settings + GroupBox *toggleBox = buildToggleWidgets (*toggleDef, def.defaultValue); + + blockLayout->addWidget(toggleBox); + blockLayout->addWidget(propertyBox); + blockLayout->setAlignment (propertyBox, Qt::AlignRight); + + return 0; +} + +CsSettings::GroupBox *CsSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle) +{ + GroupBox *box = new GroupBox (false, getParent()); + + QLayout *layout = createLayout (def.widgetOrientation, true, static_cast(box)); + + for (int i = 0; i < def.widgets.size(); ++i) + { + QString caption = def.captions.at(i); + WidgetDef *wDef = def.widgets.at(i); + + wDef->caption = caption; + wDef->widgetAlignment = OCS_LEFT; + + AbstractWidget *widg = buildWidget (caption, *wDef, layout, false); + + GroupBlock *block = mGroupList.at(i); + + //connect widget's update to the property block's enabled status + connect (widg->widget(), SIGNAL (toggled (bool)), block, SLOT (slotSetEnabled(bool))); + + //enable the default toggle option + block->getGroupBox()->setEnabled( caption == defaultToggle ); + + layout = widg->getLayout(); + } + + return box; +} diff --git a/apps/opencs/settings/toggleblock.hpp b/apps/opencs/settings/toggleblock.hpp new file mode 100644 index 000000000..990dc0826 --- /dev/null +++ b/apps/opencs/settings/toggleblock.hpp @@ -0,0 +1,27 @@ +#ifndef TOGGLEBLOCK_HPP +#define TOGGLEBLOCK_HPP + +#include + +#include "customblock.hpp" + +namespace CsSettings +{ + class GroupBlock; + class GroupBox; + class ToggleWidget; + class ItemBlock; + + class ToggleBlock : public CustomBlock + { + + public: + explicit ToggleBlock(QWidget *parent = 0); + + int build (CustomBlockDef &def); + + private: + GroupBox *buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle); + }; +} +#endif // TOGGLEBLOCK_HPP From 8d0f350446ecc74122889a29dd9f74bf9bccf7b6 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Fri, 10 May 2013 10:00:58 -0500 Subject: [PATCH 3/9] New file structure separating view classes from model classes. Deleted .ui file. --- apps/opencs/CMakeLists.txt | 11 +-- .../{ => model}/settings/settingcontainer.cpp | 0 .../{ => model}/settings/settingcontainer.hpp | 0 .../{ => model}/settings/settingsitem.cpp | 0 .../{ => model}/settings/settingsitem.hpp | 0 apps/opencs/{ => model}/settings/support.cpp | 0 apps/opencs/{ => model}/settings/support.hpp | 0 .../{ => model}/settings/usersettings.cpp | 0 .../{ => model}/settings/usersettings.hpp | 0 apps/opencs/settings/usersettingsdialog.ui | 68 ------------------- apps/opencs/view/doc/view.cpp | 2 +- .../{ => view}/settings/abstractblock.cpp | 0 .../{ => view}/settings/abstractblock.hpp | 2 +- .../{ => view}/settings/abstractpage.cpp | 0 .../{ => view}/settings/abstractpage.hpp | 0 .../{ => view}/settings/abstractwidget.cpp | 0 .../{ => view}/settings/abstractwidget.hpp | 2 +- apps/opencs/{ => view}/settings/blankpage.cpp | 2 +- apps/opencs/{ => view}/settings/blankpage.hpp | 0 .../{ => view}/settings/customblock.cpp | 0 .../{ => view}/settings/customblock.hpp | 0 .../opencs/{ => view}/settings/editorpage.cpp | 2 +- .../opencs/{ => view}/settings/editorpage.hpp | 0 .../opencs/{ => view}/settings/groupblock.cpp | 0 .../opencs/{ => view}/settings/groupblock.hpp | 0 apps/opencs/{ => view}/settings/groupbox.cpp | 0 apps/opencs/{ => view}/settings/groupbox.hpp | 0 apps/opencs/{ => view}/settings/itemblock.cpp | 0 apps/opencs/{ => view}/settings/itemblock.hpp | 0 .../opencs/{ => view}/settings/proxyblock.cpp | 0 .../opencs/{ => view}/settings/proxyblock.hpp | 0 .../{ => view}/settings/settingwidget.cpp | 0 .../{ => view}/settings/settingwidget.hpp | 0 .../{ => view}/settings/toggleblock.cpp | 0 .../{ => view}/settings/toggleblock.hpp | 0 .../settings/usersettingsdialog.cpp | 2 +- .../settings/usersettingsdialog.hpp | 4 +- 37 files changed, 15 insertions(+), 80 deletions(-) rename apps/opencs/{ => model}/settings/settingcontainer.cpp (100%) rename apps/opencs/{ => model}/settings/settingcontainer.hpp (100%) rename apps/opencs/{ => model}/settings/settingsitem.cpp (100%) rename apps/opencs/{ => model}/settings/settingsitem.hpp (100%) rename apps/opencs/{ => model}/settings/support.cpp (100%) rename apps/opencs/{ => model}/settings/support.hpp (100%) rename apps/opencs/{ => model}/settings/usersettings.cpp (100%) rename apps/opencs/{ => model}/settings/usersettings.hpp (100%) delete mode 100644 apps/opencs/settings/usersettingsdialog.ui rename apps/opencs/{ => view}/settings/abstractblock.cpp (100%) rename apps/opencs/{ => view}/settings/abstractblock.hpp (97%) rename apps/opencs/{ => view}/settings/abstractpage.cpp (100%) rename apps/opencs/{ => view}/settings/abstractpage.hpp (100%) rename apps/opencs/{ => view}/settings/abstractwidget.cpp (100%) rename apps/opencs/{ => view}/settings/abstractwidget.hpp (97%) rename apps/opencs/{ => view}/settings/blankpage.cpp (96%) rename apps/opencs/{ => view}/settings/blankpage.hpp (100%) rename apps/opencs/{ => view}/settings/customblock.cpp (100%) rename apps/opencs/{ => view}/settings/customblock.hpp (100%) rename apps/opencs/{ => view}/settings/editorpage.cpp (99%) rename apps/opencs/{ => view}/settings/editorpage.hpp (100%) rename apps/opencs/{ => view}/settings/groupblock.cpp (100%) rename apps/opencs/{ => view}/settings/groupblock.hpp (100%) rename apps/opencs/{ => view}/settings/groupbox.cpp (100%) rename apps/opencs/{ => view}/settings/groupbox.hpp (100%) rename apps/opencs/{ => view}/settings/itemblock.cpp (100%) rename apps/opencs/{ => view}/settings/itemblock.hpp (100%) rename apps/opencs/{ => view}/settings/proxyblock.cpp (100%) rename apps/opencs/{ => view}/settings/proxyblock.hpp (100%) rename apps/opencs/{ => view}/settings/settingwidget.cpp (100%) rename apps/opencs/{ => view}/settings/settingwidget.hpp (100%) rename apps/opencs/{ => view}/settings/toggleblock.cpp (100%) rename apps/opencs/{ => view}/settings/toggleblock.hpp (100%) rename apps/opencs/{ => view}/settings/usersettingsdialog.cpp (99%) rename apps/opencs/{ => view}/settings/usersettingsdialog.hpp (95%) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index dacd3bb4e..558845902 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -72,12 +72,10 @@ opencs_units_noqt (view/tools subviews ) -opencs_units (settings +opencs_units (view/settings customblock proxyblock - settingcontainer groupbox - settingsitem abstractblock settingwidget itemblock @@ -90,7 +88,12 @@ opencs_units (settings editorpage ) -opencs_units_noqt (settings +opencs_units (model/settings + settingcontainer + settingsitem + ) + +opencs_units_noqt (model/settings support usersettings ) diff --git a/apps/opencs/settings/settingcontainer.cpp b/apps/opencs/model/settings/settingcontainer.cpp similarity index 100% rename from apps/opencs/settings/settingcontainer.cpp rename to apps/opencs/model/settings/settingcontainer.cpp diff --git a/apps/opencs/settings/settingcontainer.hpp b/apps/opencs/model/settings/settingcontainer.hpp similarity index 100% rename from apps/opencs/settings/settingcontainer.hpp rename to apps/opencs/model/settings/settingcontainer.hpp diff --git a/apps/opencs/settings/settingsitem.cpp b/apps/opencs/model/settings/settingsitem.cpp similarity index 100% rename from apps/opencs/settings/settingsitem.cpp rename to apps/opencs/model/settings/settingsitem.cpp diff --git a/apps/opencs/settings/settingsitem.hpp b/apps/opencs/model/settings/settingsitem.hpp similarity index 100% rename from apps/opencs/settings/settingsitem.hpp rename to apps/opencs/model/settings/settingsitem.hpp diff --git a/apps/opencs/settings/support.cpp b/apps/opencs/model/settings/support.cpp similarity index 100% rename from apps/opencs/settings/support.cpp rename to apps/opencs/model/settings/support.cpp diff --git a/apps/opencs/settings/support.hpp b/apps/opencs/model/settings/support.hpp similarity index 100% rename from apps/opencs/settings/support.hpp rename to apps/opencs/model/settings/support.hpp diff --git a/apps/opencs/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp similarity index 100% rename from apps/opencs/settings/usersettings.cpp rename to apps/opencs/model/settings/usersettings.cpp diff --git a/apps/opencs/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp similarity index 100% rename from apps/opencs/settings/usersettings.hpp rename to apps/opencs/model/settings/usersettings.hpp diff --git a/apps/opencs/settings/usersettingsdialog.ui b/apps/opencs/settings/usersettingsdialog.ui deleted file mode 100644 index 4cd9dd113..000000000 --- a/apps/opencs/settings/usersettingsdialog.ui +++ /dev/null @@ -1,68 +0,0 @@ - - - UserSettingsDialog - - - - 0 - 0 - 638 - 478 - - - - Dialog - - - - - 10 - 440 - 621 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - buttonBox - accepted() - UserSettingsDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - UserSettingsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 85821833b..665ca2b3a 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -11,7 +11,7 @@ #include "../../model/doc/document.hpp" #include "../world/subviews.hpp" #include "../tools/subviews.hpp" -#include "../../settings/usersettingsdialog.hpp" +#include "../settings/usersettingsdialog.hpp" #include "viewmanager.hpp" #include "operations.hpp" #include "subview.hpp" diff --git a/apps/opencs/settings/abstractblock.cpp b/apps/opencs/view/settings/abstractblock.cpp similarity index 100% rename from apps/opencs/settings/abstractblock.cpp rename to apps/opencs/view/settings/abstractblock.cpp diff --git a/apps/opencs/settings/abstractblock.hpp b/apps/opencs/view/settings/abstractblock.hpp similarity index 97% rename from apps/opencs/settings/abstractblock.hpp rename to apps/opencs/view/settings/abstractblock.hpp index aa57d4fcb..31c093283 100644 --- a/apps/opencs/settings/abstractblock.hpp +++ b/apps/opencs/view/settings/abstractblock.hpp @@ -5,7 +5,7 @@ #include #include "settingwidget.hpp" -#include "settingsitem.hpp" +#include "../../model/settings/settingsitem.hpp" #include "groupbox.hpp" namespace CsSettings diff --git a/apps/opencs/settings/abstractpage.cpp b/apps/opencs/view/settings/abstractpage.cpp similarity index 100% rename from apps/opencs/settings/abstractpage.cpp rename to apps/opencs/view/settings/abstractpage.cpp diff --git a/apps/opencs/settings/abstractpage.hpp b/apps/opencs/view/settings/abstractpage.hpp similarity index 100% rename from apps/opencs/settings/abstractpage.hpp rename to apps/opencs/view/settings/abstractpage.hpp diff --git a/apps/opencs/settings/abstractwidget.cpp b/apps/opencs/view/settings/abstractwidget.cpp similarity index 100% rename from apps/opencs/settings/abstractwidget.cpp rename to apps/opencs/view/settings/abstractwidget.cpp diff --git a/apps/opencs/settings/abstractwidget.hpp b/apps/opencs/view/settings/abstractwidget.hpp similarity index 97% rename from apps/opencs/settings/abstractwidget.hpp rename to apps/opencs/view/settings/abstractwidget.hpp index 1adf8e84f..b5c646754 100644 --- a/apps/opencs/settings/abstractwidget.hpp +++ b/apps/opencs/view/settings/abstractwidget.hpp @@ -2,7 +2,7 @@ #define ABSTRACTWIDGET_HPP #include -#include "support.hpp" +#include "../../model/settings/support.hpp" class QLayout; diff --git a/apps/opencs/settings/blankpage.cpp b/apps/opencs/view/settings/blankpage.cpp similarity index 96% rename from apps/opencs/settings/blankpage.cpp rename to apps/opencs/view/settings/blankpage.cpp index 1e2ab9c0f..deb77e057 100644 --- a/apps/opencs/settings/blankpage.cpp +++ b/apps/opencs/view/settings/blankpage.cpp @@ -13,7 +13,7 @@ #include #endif -#include "usersettings.hpp" +#include "../../model/settings/usersettings.hpp" #include "groupblock.hpp" #include "toggleblock.hpp" diff --git a/apps/opencs/settings/blankpage.hpp b/apps/opencs/view/settings/blankpage.hpp similarity index 100% rename from apps/opencs/settings/blankpage.hpp rename to apps/opencs/view/settings/blankpage.hpp diff --git a/apps/opencs/settings/customblock.cpp b/apps/opencs/view/settings/customblock.cpp similarity index 100% rename from apps/opencs/settings/customblock.cpp rename to apps/opencs/view/settings/customblock.cpp diff --git a/apps/opencs/settings/customblock.hpp b/apps/opencs/view/settings/customblock.hpp similarity index 100% rename from apps/opencs/settings/customblock.hpp rename to apps/opencs/view/settings/customblock.hpp diff --git a/apps/opencs/settings/editorpage.cpp b/apps/opencs/view/settings/editorpage.cpp similarity index 99% rename from apps/opencs/settings/editorpage.cpp rename to apps/opencs/view/settings/editorpage.cpp index eb6b58ef9..2a9bf0aab 100644 --- a/apps/opencs/settings/editorpage.cpp +++ b/apps/opencs/view/settings/editorpage.cpp @@ -13,7 +13,7 @@ #include #endif -#include "usersettings.hpp" +#include "../../model/settings/usersettings.hpp" #include "groupblock.hpp" #include "toggleblock.hpp" diff --git a/apps/opencs/settings/editorpage.hpp b/apps/opencs/view/settings/editorpage.hpp similarity index 100% rename from apps/opencs/settings/editorpage.hpp rename to apps/opencs/view/settings/editorpage.hpp diff --git a/apps/opencs/settings/groupblock.cpp b/apps/opencs/view/settings/groupblock.cpp similarity index 100% rename from apps/opencs/settings/groupblock.cpp rename to apps/opencs/view/settings/groupblock.cpp diff --git a/apps/opencs/settings/groupblock.hpp b/apps/opencs/view/settings/groupblock.hpp similarity index 100% rename from apps/opencs/settings/groupblock.hpp rename to apps/opencs/view/settings/groupblock.hpp diff --git a/apps/opencs/settings/groupbox.cpp b/apps/opencs/view/settings/groupbox.cpp similarity index 100% rename from apps/opencs/settings/groupbox.cpp rename to apps/opencs/view/settings/groupbox.cpp diff --git a/apps/opencs/settings/groupbox.hpp b/apps/opencs/view/settings/groupbox.hpp similarity index 100% rename from apps/opencs/settings/groupbox.hpp rename to apps/opencs/view/settings/groupbox.hpp diff --git a/apps/opencs/settings/itemblock.cpp b/apps/opencs/view/settings/itemblock.cpp similarity index 100% rename from apps/opencs/settings/itemblock.cpp rename to apps/opencs/view/settings/itemblock.cpp diff --git a/apps/opencs/settings/itemblock.hpp b/apps/opencs/view/settings/itemblock.hpp similarity index 100% rename from apps/opencs/settings/itemblock.hpp rename to apps/opencs/view/settings/itemblock.hpp diff --git a/apps/opencs/settings/proxyblock.cpp b/apps/opencs/view/settings/proxyblock.cpp similarity index 100% rename from apps/opencs/settings/proxyblock.cpp rename to apps/opencs/view/settings/proxyblock.cpp diff --git a/apps/opencs/settings/proxyblock.hpp b/apps/opencs/view/settings/proxyblock.hpp similarity index 100% rename from apps/opencs/settings/proxyblock.hpp rename to apps/opencs/view/settings/proxyblock.hpp diff --git a/apps/opencs/settings/settingwidget.cpp b/apps/opencs/view/settings/settingwidget.cpp similarity index 100% rename from apps/opencs/settings/settingwidget.cpp rename to apps/opencs/view/settings/settingwidget.cpp diff --git a/apps/opencs/settings/settingwidget.hpp b/apps/opencs/view/settings/settingwidget.hpp similarity index 100% rename from apps/opencs/settings/settingwidget.hpp rename to apps/opencs/view/settings/settingwidget.hpp diff --git a/apps/opencs/settings/toggleblock.cpp b/apps/opencs/view/settings/toggleblock.cpp similarity index 100% rename from apps/opencs/settings/toggleblock.cpp rename to apps/opencs/view/settings/toggleblock.cpp diff --git a/apps/opencs/settings/toggleblock.hpp b/apps/opencs/view/settings/toggleblock.hpp similarity index 100% rename from apps/opencs/settings/toggleblock.hpp rename to apps/opencs/view/settings/toggleblock.hpp diff --git a/apps/opencs/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp similarity index 99% rename from apps/opencs/settings/usersettingsdialog.cpp rename to apps/opencs/view/settings/usersettingsdialog.cpp index 9777573ae..19c81fde9 100644 --- a/apps/opencs/settings/usersettingsdialog.cpp +++ b/apps/opencs/view/settings/usersettingsdialog.cpp @@ -12,7 +12,7 @@ #include "blankpage.hpp" #include "editorpage.hpp" -#include "support.hpp" +#include "../../model/settings/support.hpp" #include "settingwidget.hpp" #include diff --git a/apps/opencs/settings/usersettingsdialog.hpp b/apps/opencs/view/settings/usersettingsdialog.hpp similarity index 95% rename from apps/opencs/settings/usersettingsdialog.hpp rename to apps/opencs/view/settings/usersettingsdialog.hpp index 3b968e549..9836fa5d9 100644 --- a/apps/opencs/settings/usersettingsdialog.hpp +++ b/apps/opencs/view/settings/usersettingsdialog.hpp @@ -5,8 +5,8 @@ #include #include -#include "usersettings.hpp" -#include "support.hpp" +#include "../../model/settings/usersettings.hpp" +#include "../../model/settings/support.hpp" class QHBoxLayout; class AbstractWidget; From a8b45e0a137791d5aeb656512ad27528c00e3006 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 11 May 2013 05:55:46 -0500 Subject: [PATCH 4/9] Three primary changes: 1. Declared QStringPair::isEmpty() const 2. Split the CsSettings namespace into two: CSMSettings and CSVSettings. (Required splitting the support.hpp file) 3. Declared several classes as _noqt in CMakeLists.txt for OpenCS --- apps/opencs/CMakeLists.txt | 24 +-- .../model/settings/settingcontainer.cpp | 12 +- .../model/settings/settingcontainer.hpp | 2 +- apps/opencs/model/settings/settingsitem.cpp | 12 +- apps/opencs/model/settings/settingsitem.hpp | 2 +- apps/opencs/model/settings/support.hpp | 145 +----------------- apps/opencs/model/settings/usersettings.cpp | 12 +- apps/opencs/model/settings/usersettings.hpp | 2 +- apps/opencs/view/doc/view.cpp | 8 +- apps/opencs/view/settings/abstractblock.cpp | 25 +-- apps/opencs/view/settings/abstractblock.hpp | 8 +- apps/opencs/view/settings/abstractpage.cpp | 12 +- apps/opencs/view/settings/abstractpage.hpp | 8 +- apps/opencs/view/settings/abstractwidget.cpp | 20 +-- apps/opencs/view/settings/abstractwidget.hpp | 8 +- apps/opencs/view/settings/blankpage.cpp | 10 +- apps/opencs/view/settings/blankpage.hpp | 5 +- apps/opencs/view/settings/customblock.cpp | 18 +-- apps/opencs/view/settings/customblock.hpp | 6 +- apps/opencs/view/settings/editorpage.cpp | 6 +- apps/opencs/view/settings/editorpage.hpp | 4 +- apps/opencs/view/settings/groupblock.cpp | 20 +-- apps/opencs/view/settings/groupblock.hpp | 6 +- apps/opencs/view/settings/groupbox.cpp | 16 +- apps/opencs/view/settings/groupbox.hpp | 4 +- apps/opencs/view/settings/itemblock.cpp | 22 +-- apps/opencs/view/settings/itemblock.hpp | 8 +- apps/opencs/view/settings/proxyblock.cpp | 18 +-- apps/opencs/view/settings/proxyblock.hpp | 8 +- apps/opencs/view/settings/settingwidget.hpp | 12 +- apps/opencs/view/settings/support.cpp | 1 + apps/opencs/view/settings/support.hpp | 144 +++++++++++++++++ apps/opencs/view/settings/toggleblock.cpp | 6 +- apps/opencs/view/settings/toggleblock.hpp | 2 +- .../view/settings/usersettingsdialog.cpp | 34 ++-- .../view/settings/usersettingsdialog.hpp | 8 +- 36 files changed, 334 insertions(+), 324 deletions(-) create mode 100644 apps/opencs/view/settings/support.cpp create mode 100644 apps/opencs/view/settings/support.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 558845902..f60da9472 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -73,29 +73,33 @@ opencs_units_noqt (view/tools ) opencs_units (view/settings - customblock - proxyblock - groupbox abstractblock - settingwidget - itemblock - groupblock - toggleblock + proxyblock + abstractwidget usersettingsdialog + editorpage + ) + +opencs_units_noqt (view/settings abstractpage - abstractwidget blankpage - editorpage + groupblock + customblock + groupbox + itemblock + settingwidget + toggleblock + support ) opencs_units (model/settings settingcontainer - settingsitem ) opencs_units_noqt (model/settings support usersettings + settingsitem ) set (OPENCS_US diff --git a/apps/opencs/model/settings/settingcontainer.cpp b/apps/opencs/model/settings/settingcontainer.cpp index 700c70fa4..a75a84ec5 100644 --- a/apps/opencs/model/settings/settingcontainer.cpp +++ b/apps/opencs/model/settings/settingcontainer.cpp @@ -2,17 +2,17 @@ #include -CsSettings::SettingContainer::SettingContainer(QObject *parent) : +CSMSettings::SettingContainer::SettingContainer(QObject *parent) : QObject(parent), mValue (0), mValues (0) { } -CsSettings::SettingContainer::SettingContainer(const QString &value, QObject *parent) : +CSMSettings::SettingContainer::SettingContainer(const QString &value, QObject *parent) : QObject(parent), mValue (new QString (value)), mValues (0) { } -void CsSettings::SettingContainer::insert (const QString &value) +void CSMSettings::SettingContainer::insert (const QString &value) { if (mValue) { @@ -31,7 +31,7 @@ void CsSettings::SettingContainer::insert (const QString &value) } -void CsSettings::SettingContainer::update (const QString &value, int index) +void CSMSettings::SettingContainer::update (const QString &value, int index) { if (isEmpty()) mValue = new QString(value); @@ -43,7 +43,7 @@ void CsSettings::SettingContainer::update (const QString &value, int index) mValues->replace(index, value); } -QString CsSettings::SettingContainer::getValue (int index) const +QString CSMSettings::SettingContainer::getValue (int index) const { QString retVal(""); @@ -66,7 +66,7 @@ QString CsSettings::SettingContainer::getValue (int index) const return retVal; } -int CsSettings::SettingContainer::count () const +int CSMSettings::SettingContainer::count () const { int retVal = 0; diff --git a/apps/opencs/model/settings/settingcontainer.hpp b/apps/opencs/model/settings/settingcontainer.hpp index 929c6a25d..eb264248d 100644 --- a/apps/opencs/model/settings/settingcontainer.hpp +++ b/apps/opencs/model/settings/settingcontainer.hpp @@ -5,7 +5,7 @@ class QStringList; -namespace CsSettings +namespace CSMSettings { class SettingContainer : public QObject { diff --git a/apps/opencs/model/settings/settingsitem.cpp b/apps/opencs/model/settings/settingsitem.cpp index b2a8b509b..fef9d3e2f 100644 --- a/apps/opencs/model/settings/settingsitem.cpp +++ b/apps/opencs/model/settings/settingsitem.cpp @@ -1,6 +1,6 @@ #include "settingsitem.hpp" -bool CsSettings::SettingsItem::updateItem (const QStringList *values) +bool CSMSettings::SettingsItem::updateItem (const QStringList *values) { QStringList::ConstIterator it = values->begin(); @@ -30,7 +30,7 @@ bool CsSettings::SettingsItem::updateItem (const QStringList *values) return isValid; } -bool CsSettings::SettingsItem::updateItem (const QString &value) +bool CSMSettings::SettingsItem::updateItem (const QString &value) { //takes a value or a SettingsContainer and updates itself accordingly //after validating the data against it's own definition @@ -52,7 +52,7 @@ bool CsSettings::SettingsItem::updateItem (const QString &value) return success; } -bool CsSettings::SettingsItem::updateItem(int valueListIndex) +bool CSMSettings::SettingsItem::updateItem(int valueListIndex) { bool success = false; @@ -64,7 +64,7 @@ bool CsSettings::SettingsItem::updateItem(int valueListIndex) return success; } -bool CsSettings::SettingsItem::validate (const QString &value) +bool CSMSettings::SettingsItem::validate (const QString &value) { bool isValid = true; @@ -90,13 +90,13 @@ bool CsSettings::SettingsItem::validate (const QString &value) return isValid; } -void CsSettings::SettingsItem::setDefaultValue (const QString &value) +void CSMSettings::SettingsItem::setDefaultValue (const QString &value) { mDefaultValue = value; update (value); } -QString CsSettings::SettingsItem::getDefaultValue() const +QString CSMSettings::SettingsItem::getDefaultValue() const { return mDefaultValue; } diff --git a/apps/opencs/model/settings/settingsitem.hpp b/apps/opencs/model/settings/settingsitem.hpp index 8168edee5..8be05a4c7 100644 --- a/apps/opencs/model/settings/settingsitem.hpp +++ b/apps/opencs/model/settings/settingsitem.hpp @@ -5,7 +5,7 @@ #include "support.hpp" #include "settingcontainer.hpp" -namespace CsSettings +namespace CSMSettings { class SettingsItem : public SettingContainer { diff --git a/apps/opencs/model/settings/support.hpp b/apps/opencs/model/settings/support.hpp index 6953cbb61..1155d2a29 100644 --- a/apps/opencs/model/settings/support.hpp +++ b/apps/opencs/model/settings/support.hpp @@ -1,5 +1,5 @@ -#ifndef SUPPORT_HPP -#define SUPPORT_HPP +#ifndef MODEL_SUPPORT_HPP +#define MODEL_SUPPORT_HPP #include #include @@ -8,48 +8,13 @@ class QLayout; class QWidget; class QListWidgetItem; -namespace CsSettings +namespace CSMSettings { - class SettingContainer; - struct WidgetDef; - class ItemBlock; - class GroupBlock; - struct GroupBlockDef; - typedef QList GroupBlockDefList; - typedef QList GroupBlockList; - typedef QList ItemBlockList; - typedef QList SettingList; - typedef QMap SettingMap; + typedef QList SettingList; + typedef QMap SettingMap; typedef QMap SectionMap; - typedef QList ProxyList; - typedef QList WidgetList; - typedef QMap ItemBlockMap; - - enum OcsWidgetOrientation - { - OCS_HORIZONTAL, - OCS_VERTICAL - }; - - enum OcsWidgetType - { - OCS_CHECK_WIDGET, - OCS_COMBO_WIDGET, - OCS_TEXT_WIDGET, - OCS_LIST_WIDGET, - OCS_RADIO_WIDGET, - OCS_SPIN_WIDGET, - OCS_UNDEFINED_WIDGET - }; - - enum OcsAlignment - { - OCS_LEFT = Qt::AlignLeft, - OCS_CENTER = Qt::AlignHCenter, - OCS_RIGHT = Qt::AlignRight - }; struct QStringPair { @@ -67,104 +32,8 @@ namespace CsSettings QString left; QString right; - bool isEmpty() + bool isEmpty() const { return (left.isEmpty() && right.isEmpty()); } }; - - //template for defining the widget of a property. - struct WidgetDef - { - OcsWidgetType type; //type of widget providing input - int labelWidth; //width of caption label - int widgetWidth; //width of input widget - OcsWidgetOrientation orientation; //label / widget orientation (horizontal / vertical) - QString inputMask; //input mask (line edit) - QString caption; //label caption. Leave empty for multiple items. See BlockDef::captionList - QString value; //widget value. Leave empty for multiple items. See BlockDef::valueList - QStringPair *minMax; //Min/Max QString value pair. If empty, assigned to property item value pair. - QStringList *valueList; //value list for list widgets. If left empty, is assigned to property item value list during block build(). - bool isDefault; //isDefault - determined at runtime. - OcsAlignment valueAlignment; //left / center / right-justify text in widget - OcsAlignment widgetAlignment; //left / center / right-justify widget in group box - - - WidgetDef() : labelWidth (-1), widgetWidth (-1), - orientation (OCS_HORIZONTAL), - isDefault (true), valueAlignment (OCS_CENTER), - widgetAlignment (OCS_RIGHT), - inputMask (""), value (""), - caption (""), valueList (0) - {} - - WidgetDef (OcsWidgetType widgType) - : type (widgType), orientation (OCS_HORIZONTAL), - caption (""), value (""), valueAlignment (OCS_CENTER), - widgetAlignment (OCS_RIGHT), - labelWidth (-1), widgetWidth (-1), - valueList (0), isDefault (true) - {} - - }; - - //Defines the attributes of the property as it is represented in the config file - //as well as the UI elements (group box and widget) that serve it. - //Only one widget may serve as the input widget for the property. - struct SettingsItemDef - { - QString name; //property name - QStringList *valueList; //list of valid values for the property. - //Used to populate option widget captions or list widget item lists (see WidgetDef::caption / value) - QString defaultValue; - bool hasMultipleValues; - QStringPair minMax; //minimum / maximum value pair - WidgetDef widget; //definition of the input widget for this setting - OcsWidgetOrientation orientation; //general orientation of the widget / label for this property - ProxyList *proxyList; //list of property and corresponding default values for proxy widget - - SettingsItemDef() : name (""), defaultValue (""), orientation (OCS_VERTICAL), hasMultipleValues (false) - {} - - SettingsItemDef (QString propName, QString propDefault, OcsWidgetOrientation propOrient = OCS_VERTICAL) - : name (propName), defaultValue (propDefault), orientation (propOrient), - hasMultipleValues(false), valueList (new QStringList), proxyList ( new ProxyList) - {} - }; - - - //Hierarchically, this is a "sub-section" of properties within a section, solely for UI organization. - //Does not correlate to config file structure. - struct GroupBlockDef - { - QString title; //title of the block containing the property or properties of this sub-section - QStringList captions; //list of captions for widgets at the block level (not associated with any particular property) - WidgetList widgets; //list of widgets at the block level (not associated with any particular property) - QList properties; //list of the property(ies) which are subordinate to the property block. - OcsWidgetOrientation widgetOrientation; //general orientation of widgets in group block - bool isVisible; //determines whether or not box border/title are visible - bool isProxy; //indicates whether or not this block defines a proxy block - QString defaultValue; //generic default value attribute - - GroupBlockDef (): title(""), widgetOrientation (OCS_VERTICAL), isVisible (true), isProxy (false), defaultValue ("") - {} - - GroupBlockDef (QString blockTitle) - : title (blockTitle), widgetOrientation (OCS_VERTICAL), isProxy (false), isVisible (true), defaultValue ("") - {} - }; - - struct CustomBlockDef - { - QString title; - QString defaultValue; //default value for widgets unique to the custom block - GroupBlockDefList blockDefList; //list of settings groups that comprise the settings within the custom block - OcsWidgetOrientation blockOrientation; - - CustomBlockDef (): title (""), defaultValue (""), blockOrientation (OCS_HORIZONTAL) - {} - - CustomBlockDef (const QString &blockTitle) - : title (blockTitle), defaultValue (""), blockOrientation (OCS_HORIZONTAL) - {} - }; } -#endif // SUPPORT_HPP +#endif // MODEL_SUPPORT_HPP diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 2ddef938b..b33b39203 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -30,16 +30,16 @@ namespace boost #endif /* (BOOST_VERSION <= 104600) */ -CsSettings::UserSettings::UserSettings(Files::ConfigurationManager &cfg) +CSMSettings::UserSettings::UserSettings(Files::ConfigurationManager &cfg) : mCfgMgr(cfg) { } -CsSettings::UserSettings::~UserSettings() +CSMSettings::UserSettings::~UserSettings() { } -QFile *CsSettings::UserSettings::openFile (const QString &filename) +QFile *CSMSettings::UserSettings::openFile (const QString &filename) { QFile *file = new QFile(filename); @@ -63,7 +63,7 @@ QFile *CsSettings::UserSettings::openFile (const QString &filename) return file; } -bool CsSettings::UserSettings::writeFile(QFile *file, QMap &settings) +bool CSMSettings::UserSettings::writeFile(QFile *file, QMap &settings) { if (!file) return false; @@ -88,7 +88,7 @@ bool CsSettings::UserSettings::writeFile(QFile *file, QMap PathContainer; class QFile; -namespace CsSettings { +namespace CSMSettings { class UserSettings { diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 665ca2b3a..4d1ab78bd 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -257,7 +257,7 @@ QDockWidget *CSVDoc::View::getOperations() const void CSVDoc::View::showUserSettings() { - CsSettings::UserSettingsDialog *settingsDialog = new CsSettings::UserSettingsDialog(this); + CSVSettings::UserSettingsDialog *settingsDialog = new CSVSettings::UserSettingsDialog(this); connect (settingsDialog, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)) ); @@ -271,11 +271,7 @@ void CSVDoc::View::slotUpdateEditorSetting(const QString &settingName, const QSt if (lastValue != settingValue) { - if (settingName == "Undo Stack Size"); - - if (settingName == "Top-Level Window Count"); - - if (settingName == "Reuse Subwindows"); + //evaluate settingName against tokens to determine which function to call to update Editor application. lastValue = settingValue; } diff --git a/apps/opencs/view/settings/abstractblock.cpp b/apps/opencs/view/settings/abstractblock.cpp index 8fab5819c..b2041ccbe 100644 --- a/apps/opencs/view/settings/abstractblock.cpp +++ b/apps/opencs/view/settings/abstractblock.cpp @@ -1,14 +1,15 @@ #include "abstractblock.hpp" -CsSettings::AbstractBlock::AbstractBlock(QWidget* parent) +CSVSettings::AbstractBlock::AbstractBlock(QWidget* parent) : QObject (parent), mBox ( new GroupBox (parent) ), mWidgetParent (parent) {} -CsSettings::AbstractBlock::AbstractBlock(bool isVisible, QWidget* parent) +CSVSettings::AbstractBlock::AbstractBlock(bool isVisible, QWidget* parent) : QObject (parent), mBox ( new GroupBox (isVisible, parent)), mWidgetParent (parent) {} -QLayout *CsSettings::AbstractBlock::createLayout (OcsWidgetOrientation direction, bool isZeroMargin, QWidget* parent) +QLayout *CSVSettings::AbstractBlock::createLayout (OcsWidgetOrientation direction, + bool isZeroMargin, QWidget* parent) { QLayout *layout = 0; @@ -23,13 +24,13 @@ QLayout *CsSettings::AbstractBlock::createLayout (OcsWidgetOrientation direction return layout; } -QGroupBox *CsSettings::AbstractBlock::getGroupBox() +QGroupBox *CSVSettings::AbstractBlock::getGroupBox() { return mBox; } -CsSettings::AbstractWidget *CsSettings::AbstractBlock::buildWidget (const QString& widgetName, WidgetDef &def, - QLayout *layout, bool isConnected) const +CSVSettings::AbstractWidget *CSVSettings::AbstractBlock::buildWidget (const QString& widgetName, WidgetDef &def, + QLayout *layout, bool isConnected) const { AbstractWidget *widg = 0; @@ -76,32 +77,32 @@ CsSettings::AbstractWidget *CsSettings::AbstractBlock::buildWidget (const QStrin return widg; } -void CsSettings::AbstractBlock::setVisible (bool isVisible) +void CSVSettings::AbstractBlock::setVisible (bool isVisible) { mBox->setBorderVisibility (isVisible); } -bool CsSettings::AbstractBlock::isVisible () const +bool CSVSettings::AbstractBlock::isVisible () const { return mBox->borderVisibile(); } -QWidget *CsSettings::AbstractBlock::getParent() const +QWidget *CSVSettings::AbstractBlock::getParent() const { return mWidgetParent; } -void CsSettings::AbstractBlock::slotUpdate (const QString &value) +void CSVSettings::AbstractBlock::slotUpdate (const QString &value) { slotUpdateSetting (objectName(), value); } -void CsSettings::AbstractBlock::slotSetEnabled(bool value) +void CSVSettings::AbstractBlock::slotSetEnabled(bool value) { mBox->setEnabled(value); } -void CsSettings::AbstractBlock::slotUpdateSetting (const QString &settingName, const QString &settingValue) +void CSVSettings::AbstractBlock::slotUpdateSetting (const QString &settingName, const QString &settingValue) { bool doEmit = true; updateBySignal (settingName, settingValue, doEmit); diff --git a/apps/opencs/view/settings/abstractblock.hpp b/apps/opencs/view/settings/abstractblock.hpp index 31c093283..278e351ef 100644 --- a/apps/opencs/view/settings/abstractblock.hpp +++ b/apps/opencs/view/settings/abstractblock.hpp @@ -8,7 +8,7 @@ #include "../../model/settings/settingsitem.hpp" #include "groupbox.hpp" -namespace CsSettings +namespace CSVSettings { class AbstractBlock : public QObject @@ -17,7 +17,7 @@ namespace CsSettings protected: - typedef QMap SettingsItemMap; + typedef QMap SettingsItemMap; GroupBox *mBox; QWidget *mWidgetParent; @@ -30,8 +30,8 @@ namespace CsSettings void setVisible (bool isVisible); bool isVisible() const; - virtual SettingList *getSettings() = 0; - virtual bool updateSettings (const SettingMap &settings) = 0; + virtual CSMSettings::SettingList *getSettings() = 0; + virtual bool updateSettings (const CSMSettings::SettingMap &settings) = 0; virtual bool updateBySignal (const QString &name, const QString &value, bool &doEmit) { return false; } diff --git a/apps/opencs/view/settings/abstractpage.cpp b/apps/opencs/view/settings/abstractpage.cpp index 1fd60fbf0..512b5abbd 100644 --- a/apps/opencs/view/settings/abstractpage.cpp +++ b/apps/opencs/view/settings/abstractpage.cpp @@ -10,28 +10,28 @@ #include #include -CsSettings::AbstractPage::AbstractPage(QWidget *parent): +CSVSettings::AbstractPage::AbstractPage(QWidget *parent): QWidget(parent) { } -CsSettings::AbstractPage::AbstractPage(const QString &pageName, QWidget *parent): +CSVSettings::AbstractPage::AbstractPage(const QString &pageName, QWidget *parent): QWidget(parent) { QWidget::setObjectName (pageName); } -CsSettings::AbstractPage::~AbstractPage() +CSVSettings::AbstractPage::~AbstractPage() { } -CsSettings::SettingList *CsSettings::AbstractPage::getSettings() +CSMSettings::SettingList *CSVSettings::AbstractPage::getSettings() { - SettingList *settings = new SettingList(); + CSMSettings::SettingList *settings = new CSMSettings::SettingList(); foreach (AbstractBlock *block, mAbstractBlocks) { - SettingList *groupSettings = block->getSettings(); + CSMSettings::SettingList *groupSettings = block->getSettings(); settings->append (*groupSettings); } diff --git a/apps/opencs/view/settings/abstractpage.hpp b/apps/opencs/view/settings/abstractpage.hpp index b5ee86f57..15ac82a62 100644 --- a/apps/opencs/view/settings/abstractpage.hpp +++ b/apps/opencs/view/settings/abstractpage.hpp @@ -10,15 +10,13 @@ class SettingMap; class SettingList; -namespace CsSettings { +namespace CSVSettings { typedef QList AbstractBlockList; class AbstractPage: public QWidget { - Q_OBJECT - protected: AbstractBlockList mAbstractBlocks; @@ -32,9 +30,9 @@ namespace CsSettings { virtual void setupUi()=0; - virtual void initializeWidgets (const SettingMap &settings) = 0; + virtual void initializeWidgets (const CSMSettings::SettingMap &settings) = 0; - SettingList *getSettings(); + CSMSettings::SettingList *getSettings(); void setObjectName(); diff --git a/apps/opencs/view/settings/abstractwidget.cpp b/apps/opencs/view/settings/abstractwidget.cpp index a23c3ee1b..6f6d45316 100644 --- a/apps/opencs/view/settings/abstractwidget.cpp +++ b/apps/opencs/view/settings/abstractwidget.cpp @@ -3,7 +3,7 @@ #include #include -void CsSettings::AbstractWidget::build(QWidget *widget, WidgetDef &def, bool noLabel) +void CSVSettings::AbstractWidget::build(QWidget *widget, WidgetDef &def, bool noLabel) { if (!mLayout) createLayout(def.orientation, true); @@ -12,7 +12,7 @@ void CsSettings::AbstractWidget::build(QWidget *widget, WidgetDef &def, bool noL } -void CsSettings::AbstractWidget::buildLabelAndWidget (QWidget *widget, WidgetDef &def, bool noLabel) +void CSVSettings::AbstractWidget::buildLabelAndWidget (QWidget *widget, WidgetDef &def, bool noLabel) { if (def.widgetWidth > -1) widget->setFixedWidth (def.widgetWidth); @@ -31,7 +31,7 @@ void CsSettings::AbstractWidget::buildLabelAndWidget (QWidget *widget, WidgetDef mLayout->setAlignment (widget, getAlignment (def.widgetAlignment)); } -void CsSettings::AbstractWidget::createLayout +void CSVSettings::AbstractWidget::createLayout (OcsWidgetOrientation direction, bool isZeroMargin) { if (direction == OCS_VERTICAL) @@ -43,36 +43,36 @@ void CsSettings::AbstractWidget::createLayout mLayout->setContentsMargins(0, 0, 0, 0); } -QFlags CsSettings::AbstractWidget::getAlignment (CsSettings::OcsAlignment flag) +QFlags CSVSettings::AbstractWidget::getAlignment (CSVSettings::OcsAlignment flag) { return QFlags(static_cast(flag)); } -QLayout *CsSettings::AbstractWidget::getLayout() +QLayout *CSVSettings::AbstractWidget::getLayout() { return mLayout; } -void CsSettings::AbstractWidget::slotUpdateWidget (const QString &value) +void CSVSettings::AbstractWidget::slotUpdateWidget (const QString &value) { updateWidget (value); } -void CsSettings::AbstractWidget::slotUpdateItem(const QString &value) +void CSVSettings::AbstractWidget::slotUpdateItem(const QString &value) { emit signalUpdateItem (value); } -void CsSettings::AbstractWidget::slotUpdateItem(bool value) +void CSVSettings::AbstractWidget::slotUpdateItem(bool value) { if (value) emit signalUpdateItem (widget()->objectName()); } -void CsSettings::AbstractWidget::slotUpdateItem(int value) +void CSVSettings::AbstractWidget::slotUpdateItem(int value) { emit signalUpdateItem (QString::number(value)); } -void CsSettings::AbstractWidget::slotUpdateItem (QListWidgetItem* current, QListWidgetItem* previous) +void CSVSettings::AbstractWidget::slotUpdateItem (QListWidgetItem* current, QListWidgetItem* previous) {} diff --git a/apps/opencs/view/settings/abstractwidget.hpp b/apps/opencs/view/settings/abstractwidget.hpp index b5c646754..98653e465 100644 --- a/apps/opencs/view/settings/abstractwidget.hpp +++ b/apps/opencs/view/settings/abstractwidget.hpp @@ -2,11 +2,11 @@ #define ABSTRACTWIDGET_HPP #include -#include "../../model/settings/support.hpp" +#include "support.hpp" class QLayout; -namespace CsSettings +namespace CSVSettings { class AbstractWidget : public QObject { @@ -35,12 +35,12 @@ namespace CsSettings virtual void updateWidget (const QString &value) = 0; //converts user-defined enum to Qt equivalents - QFlags getAlignment (CsSettings::OcsAlignment flag); + QFlags getAlignment (OcsAlignment flag); private: //widget initialization utilities - void createLayout (CsSettings::OcsWidgetOrientation direction, bool isZeroMargin); + void createLayout (OcsWidgetOrientation direction, bool isZeroMargin); void buildLabelAndWidget (QWidget *widget, WidgetDef &def, bool noLabel); diff --git a/apps/opencs/view/settings/blankpage.cpp b/apps/opencs/view/settings/blankpage.cpp index deb77e057..57d5c7caa 100644 --- a/apps/opencs/view/settings/blankpage.cpp +++ b/apps/opencs/view/settings/blankpage.cpp @@ -17,19 +17,19 @@ #include "groupblock.hpp" #include "toggleblock.hpp" -CsSettings::BlankPage::BlankPage(QWidget *parent): +CSVSettings::BlankPage::BlankPage(QWidget *parent): AbstractPage("Blank", parent) { initPage(); } -CsSettings::BlankPage::BlankPage(const QString &title, QWidget *parent): +CSVSettings::BlankPage::BlankPage(const QString &title, QWidget *parent): AbstractPage(title, parent) { initPage(); } -void CsSettings::BlankPage::initPage() +void CSVSettings::BlankPage::initPage() { // Hacks to get the stylesheet look properly #ifdef Q_OS_MAC @@ -40,7 +40,7 @@ void CsSettings::BlankPage::initPage() setupUi(); } -void CsSettings::BlankPage::setupUi() +void CSVSettings::BlankPage::setupUi() { QGroupBox *pageBox = new QGroupBox(this); QLayout* pageLayout = new QVBoxLayout(); @@ -49,7 +49,7 @@ void CsSettings::BlankPage::setupUi() pageLayout->addWidget(pageBox); } -void CsSettings::BlankPage::initializeWidgets (const SettingMap &settings) +void CSVSettings::BlankPage::initializeWidgets (const CSMSettings::SettingMap &settings) { //iterate each item in each blocks in this section //validate the corresponding setting against the defined valuelist if any. diff --git a/apps/opencs/view/settings/blankpage.hpp b/apps/opencs/view/settings/blankpage.hpp index 9dd6c5e56..648d373f3 100644 --- a/apps/opencs/view/settings/blankpage.hpp +++ b/apps/opencs/view/settings/blankpage.hpp @@ -5,14 +5,13 @@ class QGroupBox; -namespace CsSettings { +namespace CSVSettings { class UserSettings; class AbstractBlock; class BlankPage : public AbstractPage { - Q_OBJECT public: @@ -20,7 +19,7 @@ namespace CsSettings { BlankPage (const QString &title, QWidget *parent); void setupUi(); - void initializeWidgets (const SettingMap &settings); + void initializeWidgets (const CSMSettings::SettingMap &settings); private: void initPage(); diff --git a/apps/opencs/view/settings/customblock.cpp b/apps/opencs/view/settings/customblock.cpp index f70db47a0..03b838501 100644 --- a/apps/opencs/view/settings/customblock.cpp +++ b/apps/opencs/view/settings/customblock.cpp @@ -3,11 +3,11 @@ #include "itemblock.hpp" #include "proxyblock.hpp" -CsSettings::CustomBlock::CustomBlock (QWidget *parent) : AbstractBlock (parent) +CSVSettings::CustomBlock::CustomBlock (QWidget *parent) : AbstractBlock (parent) { } -int CsSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefList::iterator *it) +int CSVSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefList::iterator *it) { int retVal = 0; @@ -37,7 +37,7 @@ int CsSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefList return retVal; } -CsSettings::GroupBox *CsSettings::CustomBlock::buildGroupBox (CsSettings::OcsWidgetOrientation orientation) +CSVSettings::GroupBox *CSVSettings::CustomBlock::buildGroupBox (OcsWidgetOrientation orientation) { GroupBox *box = new GroupBox (false, mBox); QLayout *layout = createLayout (orientation, true, box); @@ -45,7 +45,7 @@ CsSettings::GroupBox *CsSettings::CustomBlock::buildGroupBox (CsSettings::OcsWid return box; } -int CsSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def) +int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def) { GroupBlock *block = new GroupBlock (getParent()); @@ -57,7 +57,7 @@ int CsSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def) return block->build(def); } -int CsSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *block) +int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *block) { if (def.properties.size() != 1) return -1; @@ -91,13 +91,13 @@ int CsSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *blo return 0; } -CsSettings::SettingList *CsSettings::CustomBlock::getSettings() +CSMSettings::SettingList *CSVSettings::CustomBlock::getSettings() { - SettingList *settings = new SettingList(); + CSMSettings::SettingList *settings = new CSMSettings::SettingList(); foreach (GroupBlock *block, mGroupList) { - SettingList *groupSettings = block->getSettings(); + CSMSettings::SettingList *groupSettings = block->getSettings(); if (groupSettings) settings->append(*groupSettings); @@ -106,7 +106,7 @@ CsSettings::SettingList *CsSettings::CustomBlock::getSettings() return settings; } -bool CsSettings::CustomBlock::updateSettings (const SettingMap &settings) +bool CSVSettings::CustomBlock::updateSettings (const CSMSettings::SettingMap &settings) { bool success = true; diff --git a/apps/opencs/view/settings/customblock.hpp b/apps/opencs/view/settings/customblock.hpp index ba83464da..4bcc85c5c 100644 --- a/apps/opencs/view/settings/customblock.hpp +++ b/apps/opencs/view/settings/customblock.hpp @@ -3,7 +3,7 @@ #include "abstractblock.hpp" -namespace CsSettings +namespace CSVSettings { class ProxyBlock; @@ -19,8 +19,8 @@ namespace CsSettings explicit CustomBlock (QWidget *parent = 0); - bool updateSettings (const SettingMap &settings); - SettingList *getSettings(); + bool updateSettings (const CSMSettings::SettingMap &settings); + CSMSettings::SettingList *getSettings(); int build (GroupBlockDefList &defList, GroupBlockDefList::Iterator *it = 0); protected: diff --git a/apps/opencs/view/settings/editorpage.cpp b/apps/opencs/view/settings/editorpage.cpp index 2a9bf0aab..83f29438d 100644 --- a/apps/opencs/view/settings/editorpage.cpp +++ b/apps/opencs/view/settings/editorpage.cpp @@ -17,7 +17,7 @@ #include "groupblock.hpp" #include "toggleblock.hpp" -CsSettings::EditorPage::EditorPage(QWidget *parent): +CSVSettings::EditorPage::EditorPage(QWidget *parent): AbstractPage("Editor", parent) { // Hacks to get the stylesheet look properly @@ -29,7 +29,7 @@ CsSettings::EditorPage::EditorPage(QWidget *parent): setupUi(); } -void CsSettings::EditorPage::setupUi() +void CSVSettings::EditorPage::setupUi() { GroupBlockDef undoStack (QString("Undo Stack Size")); GroupBlockDef topLevelWindowCount (QString("Maximum Top-Level Window Count")); @@ -153,7 +153,7 @@ void CsSettings::EditorPage::setupUi() } } -void CsSettings::EditorPage::initializeWidgets (const SettingMap &settings) +void CSVSettings::EditorPage::initializeWidgets (const CSMSettings::SettingMap &settings) { //iterate each item in each blocks in this section //validate the corresponding setting against the defined valuelist if any. diff --git a/apps/opencs/view/settings/editorpage.hpp b/apps/opencs/view/settings/editorpage.hpp index 87ae7da83..0c1e80e89 100644 --- a/apps/opencs/view/settings/editorpage.hpp +++ b/apps/opencs/view/settings/editorpage.hpp @@ -5,7 +5,7 @@ class QGroupBox; -namespace CsSettings { +namespace CSVSettings { class UserSettings; class AbstractBlock; @@ -19,7 +19,7 @@ namespace CsSettings { EditorPage(QWidget *parent = 0); void setupUi(); - void initializeWidgets (const SettingMap &settings); + void initializeWidgets (const CSMSettings::SettingMap &settings); signals: void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); diff --git a/apps/opencs/view/settings/groupblock.cpp b/apps/opencs/view/settings/groupblock.cpp index b5917ec38..b18f629ba 100644 --- a/apps/opencs/view/settings/groupblock.cpp +++ b/apps/opencs/view/settings/groupblock.cpp @@ -1,15 +1,15 @@ #include "groupblock.hpp" #include "itemblock.hpp" -CsSettings::GroupBlock::GroupBlock (QWidget* parent) +CSVSettings::GroupBlock::GroupBlock (QWidget* parent) : AbstractBlock (parent) {} -CsSettings::GroupBlock::GroupBlock (bool isVisible, QWidget *parent) +CSVSettings::GroupBlock::GroupBlock (bool isVisible, QWidget *parent) : AbstractBlock (isVisible, parent) {} -int CsSettings::GroupBlock::build (GroupBlockDef &def) +int CSVSettings::GroupBlock::build (GroupBlockDef &def) { if (def.properties.size() == 0) @@ -44,14 +44,14 @@ int CsSettings::GroupBlock::build (GroupBlockDef &def) return retVal; } -CsSettings::SettingList *CsSettings::GroupBlock::getSettings() +CSMSettings::SettingList *CSVSettings::GroupBlock::getSettings() { - SettingList *settings = 0; + CSMSettings::SettingList *settings = 0; foreach (ItemBlock *block, mItemBlockList) { if (!settings) - settings = new SettingList(); + settings = new CSMSettings::SettingList(); settings->append(*(block->getSettings ())); } @@ -59,7 +59,7 @@ CsSettings::SettingList *CsSettings::GroupBlock::getSettings() return settings; } -CsSettings::ItemBlock *CsSettings::GroupBlock::getItemBlock (const QString &name, ItemBlockList *blockList) +CSVSettings::ItemBlock *CSVSettings::GroupBlock::getItemBlock (const QString &name, ItemBlockList *blockList) { ItemBlock *retBlock = 0; @@ -78,7 +78,7 @@ CsSettings::ItemBlock *CsSettings::GroupBlock::getItemBlock (const QString &name return retBlock; } -CsSettings::ItemBlock *CsSettings::GroupBlock::getItemBlock (int index) +CSVSettings::ItemBlock *CSVSettings::GroupBlock::getItemBlock (int index) { ItemBlock *retBlock = 0; @@ -88,14 +88,14 @@ CsSettings::ItemBlock *CsSettings::GroupBlock::getItemBlock (int index) return retBlock; } -bool CsSettings::GroupBlock::updateSettings (const SettingMap &settings) +bool CSVSettings::GroupBlock::updateSettings (const CSMSettings::SettingMap &settings) { bool success = true; //update all non-proxy settings foreach (ItemBlock *block, mItemBlockList) { - SettingContainer *setting = settings[block->objectName()]; + CSMSettings::SettingContainer *setting = settings[block->objectName()]; if (setting) { diff --git a/apps/opencs/view/settings/groupblock.hpp b/apps/opencs/view/settings/groupblock.hpp index f3b0c4bae..a8fd4e3b4 100644 --- a/apps/opencs/view/settings/groupblock.hpp +++ b/apps/opencs/view/settings/groupblock.hpp @@ -4,7 +4,7 @@ #include #include "abstractblock.hpp" -namespace CsSettings +namespace CSVSettings { class ItemBlock; @@ -18,9 +18,9 @@ namespace CsSettings int build (GroupBlockDef &def); - bool updateSettings (const SettingMap &settings); + bool updateSettings (const CSMSettings::SettingMap &settings); - SettingList *getSettings(); + CSMSettings::SettingList *getSettings(); ItemBlock *getItemBlock (const QString &name, ItemBlockList *blockList = 0); ItemBlock *getItemBlock (int index); diff --git a/apps/opencs/view/settings/groupbox.cpp b/apps/opencs/view/settings/groupbox.cpp index c996a22aa..da2cc2571 100644 --- a/apps/opencs/view/settings/groupbox.cpp +++ b/apps/opencs/view/settings/groupbox.cpp @@ -1,21 +1,21 @@ #include "groupbox.hpp" -const QString CsSettings::GroupBox::INVISIBLE_BOX_STYLE = +const QString CSVSettings::GroupBox::INVISIBLE_BOX_STYLE = QString::fromUtf8("QGroupBox { border: 0px; padding 0px; margin: 0px;}"); -CsSettings::GroupBox::GroupBox(QWidget *parent) : +CSVSettings::GroupBox::GroupBox(QWidget *parent) : QGroupBox (parent) { initBox(); } -CsSettings::GroupBox::GroupBox (bool isVisible, QWidget *parent) : +CSVSettings::GroupBox::GroupBox (bool isVisible, QWidget *parent) : QGroupBox (parent) { initBox(isVisible); } -void CsSettings::GroupBox::initBox(bool isVisible) +void CSVSettings::GroupBox::initBox(bool isVisible) { setFlat (true); VISIBLE_BOX_STYLE = styleSheet(); @@ -24,12 +24,12 @@ void CsSettings::GroupBox::initBox(bool isVisible) setStyleSheet (INVISIBLE_BOX_STYLE); } -bool CsSettings::GroupBox::borderVisibile() const +bool CSVSettings::GroupBox::borderVisibile() const { return (styleSheet() != INVISIBLE_BOX_STYLE); } -void CsSettings::GroupBox::setTitle (const QString &title) +void CSVSettings::GroupBox::setTitle (const QString &title) { if (borderVisibile() ) { @@ -38,7 +38,7 @@ void CsSettings::GroupBox::setTitle (const QString &title) } } -void CsSettings::GroupBox::setBorderVisibility (bool value) +void CSVSettings::GroupBox::setBorderVisibility (bool value) { if (value) setStyleSheet(VISIBLE_BOX_STYLE); @@ -46,7 +46,7 @@ void CsSettings::GroupBox::setBorderVisibility (bool value) setStyleSheet(INVISIBLE_BOX_STYLE); } -void CsSettings::GroupBox::setMinimumWidth() +void CSVSettings::GroupBox::setMinimumWidth() { //set minimum width to accommodate title, if needed //1.5 multiplier to account for bold title. diff --git a/apps/opencs/view/settings/groupbox.hpp b/apps/opencs/view/settings/groupbox.hpp index d229dbc8e..43cb2e0c3 100644 --- a/apps/opencs/view/settings/groupbox.hpp +++ b/apps/opencs/view/settings/groupbox.hpp @@ -3,12 +3,10 @@ #include -namespace CsSettings +namespace CSVSettings { class GroupBox : public QGroupBox { - Q_OBJECT - static const QString INVISIBLE_BOX_STYLE; QString VISIBLE_BOX_STYLE; //not a const... diff --git a/apps/opencs/view/settings/itemblock.cpp b/apps/opencs/view/settings/itemblock.cpp index 261319d8d..0280a6afd 100644 --- a/apps/opencs/view/settings/itemblock.cpp +++ b/apps/opencs/view/settings/itemblock.cpp @@ -2,12 +2,12 @@ #include -CsSettings::ItemBlock::ItemBlock (QWidget* parent) +CSVSettings::ItemBlock::ItemBlock (QWidget* parent) : mSetting (0), AbstractBlock (false, parent) { } -int CsSettings::ItemBlock::build(SettingsItemDef &iDef) +int CSVSettings::ItemBlock::build(SettingsItemDef &iDef) { buildItemBlock (iDef); buildItemBlockWidgets (iDef); @@ -15,7 +15,7 @@ int CsSettings::ItemBlock::build(SettingsItemDef &iDef) return 0; } -void CsSettings::ItemBlock::buildItemBlockWidgets (SettingsItemDef &iDef) +void CSVSettings::ItemBlock::buildItemBlockWidgets (SettingsItemDef &iDef) { WidgetDef wDef = iDef.widget; QLayout *blockLayout = 0; @@ -56,13 +56,13 @@ void CsSettings::ItemBlock::buildItemBlockWidgets (SettingsItemDef &iDef) } } -void CsSettings::ItemBlock::buildItemBlock (SettingsItemDef &iDef) +void CSVSettings::ItemBlock::buildItemBlock (SettingsItemDef &iDef) { QString defaultValue = iDef.defaultValue; setObjectName(iDef.name); - mSetting = new SettingsItem (objectName(), + mSetting = new CSMSettings::SettingsItem (objectName(), iDef.hasMultipleValues, iDef.defaultValue, parent()); @@ -74,7 +74,7 @@ void CsSettings::ItemBlock::buildItemBlock (SettingsItemDef &iDef) } -bool CsSettings::ItemBlock::update (const QString &value) +bool CSVSettings::ItemBlock::update (const QString &value) { bool success = updateItem (value); @@ -85,13 +85,13 @@ bool CsSettings::ItemBlock::update (const QString &value) } -bool CsSettings::ItemBlock::updateItem (const QString &value) +bool CSVSettings::ItemBlock::updateItem (const QString &value) { return mSetting->updateItem(value); } -bool CsSettings::ItemBlock::updateBySignal(const QString &name, const QString &value, bool &doEmit) +bool CSVSettings::ItemBlock::updateBySignal(const QString &name, const QString &value, bool &doEmit) { bool success = (mSetting->getValue() != value); @@ -101,15 +101,15 @@ bool CsSettings::ItemBlock::updateBySignal(const QString &name, const QString &v return success; } -CsSettings::SettingList *CsSettings::ItemBlock::getSettings () +CSMSettings::SettingList *CSVSettings::ItemBlock::getSettings () { - SettingList *list = new SettingList(); + CSMSettings::SettingList *list = new CSMSettings::SettingList(); list->push_back(mSetting); return list; } -QString CsSettings::ItemBlock::getValue() const +QString CSVSettings::ItemBlock::getValue() const { return mSetting->getValue(); } diff --git a/apps/opencs/view/settings/itemblock.hpp b/apps/opencs/view/settings/itemblock.hpp index 8aab65745..c7714ac64 100644 --- a/apps/opencs/view/settings/itemblock.hpp +++ b/apps/opencs/view/settings/itemblock.hpp @@ -3,21 +3,21 @@ #include "abstractblock.hpp" -namespace CsSettings +namespace CSVSettings { class ItemBlock : public AbstractBlock { - SettingsItem *mSetting; + CSMSettings::SettingsItem *mSetting; WidgetList mWidgetList; public: ItemBlock (QWidget* parent = 0); - bool updateSettings (const SettingMap &settings) { return false; } + bool updateSettings (const CSMSettings::SettingMap &settings) { return false; } - SettingList *getSettings (); + CSMSettings::SettingList *getSettings (); QString getValue () const; int getSettingCount(); diff --git a/apps/opencs/view/settings/proxyblock.cpp b/apps/opencs/view/settings/proxyblock.cpp index 46e404a12..71a307084 100644 --- a/apps/opencs/view/settings/proxyblock.cpp +++ b/apps/opencs/view/settings/proxyblock.cpp @@ -1,11 +1,11 @@ #include "proxyblock.hpp" #include "itemblock.hpp" -CsSettings::ProxyBlock::ProxyBlock (QWidget *parent) +CSVSettings::ProxyBlock::ProxyBlock (QWidget *parent) : GroupBlock (parent) { } -int CsSettings::ProxyBlock::build (GroupBlockDef &proxyDef) +int CSVSettings::ProxyBlock::build (GroupBlockDef &proxyDef) { //get the list of pre-defined values for the proxy mValueList = proxyDef.properties.at(0)->valueList; @@ -19,7 +19,7 @@ int CsSettings::ProxyBlock::build (GroupBlockDef &proxyDef) return success; } -void CsSettings::ProxyBlock::addSetting (ItemBlock *settingBlock, QStringList *proxyList) +void CSVSettings::ProxyBlock::addSetting (ItemBlock *settingBlock, QStringList *proxyList) { //connect the item block of the proxied seting to the generic update slot connect (settingBlock, SIGNAL (signalUpdateSetting(const QString &, const QString &)), @@ -29,23 +29,23 @@ void CsSettings::ProxyBlock::addSetting (ItemBlock *settingBlock, QStringList *p mProxyList << proxyList; } -bool CsSettings::ProxyBlock::updateSettings (const SettingMap &settings) +bool CSVSettings::ProxyBlock::updateSettings (const CSMSettings::SettingMap &settings) { return updateByProxiedSettings(&settings); } -bool CsSettings::ProxyBlock::updateBySignal(const QString &name, const QString &value, bool &doEmit) +bool CSVSettings::ProxyBlock::updateBySignal(const QString &name, const QString &value, bool &doEmit) { doEmit = false; return updateProxiedSettings(); } -void CsSettings::ProxyBlock::slotUpdateProxySetting (const QString &name, const QString &value) +void CSVSettings::ProxyBlock::slotUpdateProxySetting (const QString &name, const QString &value) { updateByProxiedSettings(); } -bool CsSettings::ProxyBlock::updateProxiedSettings() +bool CSVSettings::ProxyBlock::updateProxiedSettings() { foreach (ItemBlock *block, mProxiedItemBlockList) { @@ -74,7 +74,7 @@ bool CsSettings::ProxyBlock::updateProxiedSettings() return true; } -bool CsSettings::ProxyBlock::updateByProxiedSettings(const SettingMap *settings) +bool CSVSettings::ProxyBlock::updateByProxiedSettings(const CSMSettings::SettingMap *settings) { bool success = false; int commonIndex = -1; @@ -143,7 +143,7 @@ bool CsSettings::ProxyBlock::updateByProxiedSettings(const SettingMap *settings) return success; } -CsSettings::ItemBlock *CsSettings::ProxyBlock::getProxiedItemBlock (const QString &name) +CSVSettings::ItemBlock *CSVSettings::ProxyBlock::getProxiedItemBlock (const QString &name) { return getItemBlock (name, &mProxiedItemBlockList); } diff --git a/apps/opencs/view/settings/proxyblock.hpp b/apps/opencs/view/settings/proxyblock.hpp index d35d7da69..f757842ea 100644 --- a/apps/opencs/view/settings/proxyblock.hpp +++ b/apps/opencs/view/settings/proxyblock.hpp @@ -3,7 +3,7 @@ #include "groupblock.hpp" -namespace CsSettings +namespace CSVSettings { class ProxyBlock : public GroupBlock { @@ -23,14 +23,14 @@ namespace CsSettings void addSetting (ItemBlock* settingBlock, QStringList *proxyList); int build (GroupBlockDef &def); - SettingList *getSettings() { return 0; } - bool updateSettings (const SettingMap &settings); + CSMSettings::SettingList *getSettings() { return 0; } + bool updateSettings (const CSMSettings::SettingMap &settings); bool updateBySignal (const QString &name, const QString &value, bool &doEmit); private: ItemBlock *getProxiedItemBlock (const QString &name); - bool updateByProxiedSettings(const SettingMap *settings = 0); + bool updateByProxiedSettings(const CSMSettings::SettingMap *settings = 0); bool updateProxiedSettings(); private slots: diff --git a/apps/opencs/view/settings/settingwidget.hpp b/apps/opencs/view/settings/settingwidget.hpp index 4e4bad132..b29523a3a 100644 --- a/apps/opencs/view/settings/settingwidget.hpp +++ b/apps/opencs/view/settings/settingwidget.hpp @@ -14,7 +14,7 @@ #include "abstractwidget.hpp" -namespace CsSettings +namespace CSVSettings { //VALID FOR RADIOBUTTON / CHECKBOX (or other toggle widget with it's own label) template @@ -25,7 +25,7 @@ namespace CsSettings public: - explicit SettingWidget(WidgetDef &def, QLayout *layout, QWidget* parent = 0) + explicit SettingWidget (WidgetDef &def, QLayout *layout, QWidget* parent = 0) : AbstractWidget (layout, parent), mWidget (new T1 (parent)) { mWidget->setText(def.caption); @@ -55,7 +55,7 @@ namespace CsSettings public: - SettingWidget(WidgetDef &def, QLayout *layout, QWidget *parent = 0) + SettingWidget (WidgetDef &def, QLayout *layout, QWidget *parent = 0) : AbstractWidget (layout, parent), mWidget (new QSpinBox (parent)) { def.caption += tr(" (%1 to %2)").arg(def.minMax->left).arg(def.minMax->right); @@ -91,7 +91,7 @@ namespace CsSettings }; template <> - class SettingWidget : public CsSettings::AbstractWidget + class SettingWidget : public CSVSettings::AbstractWidget { QComboBox *mWidget; @@ -143,7 +143,7 @@ namespace CsSettings }; template <> - class SettingWidget : public CsSettings::AbstractWidget + class SettingWidget : public CSVSettings::AbstractWidget { QLineEdit *mWidget; @@ -176,7 +176,7 @@ namespace CsSettings }; template <> - class SettingWidget : public CsSettings::AbstractWidget + class SettingWidget : public CSVSettings::AbstractWidget { QListWidget *mWidget; diff --git a/apps/opencs/view/settings/support.cpp b/apps/opencs/view/settings/support.cpp new file mode 100644 index 000000000..d79edfdb3 --- /dev/null +++ b/apps/opencs/view/settings/support.cpp @@ -0,0 +1 @@ +#include "support.hpp" diff --git a/apps/opencs/view/settings/support.hpp b/apps/opencs/view/settings/support.hpp new file mode 100644 index 000000000..1bd5f841a --- /dev/null +++ b/apps/opencs/view/settings/support.hpp @@ -0,0 +1,144 @@ +#ifndef VIEW_SUPPORT_HPP +#define VIEW_SUPPORT_HPP + +#include +#include + +#include "../../model/settings/support.hpp" + +namespace CSVSettings +{ + struct WidgetDef; + class ItemBlock; + class GroupBlock; + struct GroupBlockDef; + + typedef QList GroupBlockDefList; + typedef QList GroupBlockList; + typedef QList ItemBlockList; + typedef QList ProxyList; + typedef QList WidgetList; + typedef QMap ItemBlockMap; + + enum OcsWidgetOrientation + { + OCS_HORIZONTAL, + OCS_VERTICAL + }; + + enum OcsWidgetType + { + OCS_CHECK_WIDGET, + OCS_COMBO_WIDGET, + OCS_TEXT_WIDGET, + OCS_LIST_WIDGET, + OCS_RADIO_WIDGET, + OCS_SPIN_WIDGET, + OCS_UNDEFINED_WIDGET + }; + + enum OcsAlignment + { + OCS_LEFT = Qt::AlignLeft, + OCS_CENTER = Qt::AlignHCenter, + OCS_RIGHT = Qt::AlignRight + }; + + //template for defining the widget of a property. + struct WidgetDef + { + OcsWidgetType type; //type of widget providing input + int labelWidth; //width of caption label + int widgetWidth; //width of input widget + OcsWidgetOrientation orientation; //label / widget orientation (horizontal / vertical) + QString inputMask; //input mask (line edit) + QString caption; //label caption. Leave empty for multiple items. See BlockDef::captionList + QString value; //widget value. Leave empty for multiple items. See BlockDef::valueList + CSMSettings::QStringPair *minMax; //Min/Max QString value pair. If empty, assigned to property item value pair. + QStringList *valueList; //value list for list widgets. If left empty, is assigned to property item value list during block build(). + bool isDefault; //isDefault - determined at runtime. + OcsAlignment valueAlignment; //left / center / right-justify text in widget + OcsAlignment widgetAlignment; //left / center / right-justify widget in group box + + + WidgetDef() : labelWidth (-1), widgetWidth (-1), + orientation (OCS_HORIZONTAL), + isDefault (true), valueAlignment (OCS_CENTER), + widgetAlignment (OCS_RIGHT), + inputMask (""), value (""), + caption (""), valueList (0) + {} + + WidgetDef (OcsWidgetType widgType) + : type (widgType), orientation (OCS_HORIZONTAL), + caption (""), value (""), valueAlignment (OCS_CENTER), + widgetAlignment (OCS_RIGHT), + labelWidth (-1), widgetWidth (-1), + valueList (0), isDefault (true) + {} + + }; + + //Defines the attributes of the property as it is represented in the config file + //as well as the UI elements (group box and widget) that serve it. + //Only one widget may serve as the input widget for the property. + struct SettingsItemDef + { + QString name; //property name + QStringList *valueList; //list of valid values for the property. + //Used to populate option widget captions or list widget item lists (see WidgetDef::caption / value) + QString defaultValue; + bool hasMultipleValues; + CSMSettings::QStringPair minMax; //minimum / maximum value pair + WidgetDef widget; //definition of the input widget for this setting + OcsWidgetOrientation orientation; //general orientation of the widget / label for this property + ProxyList *proxyList; //list of property and corresponding default values for proxy widget + + SettingsItemDef() : name (""), defaultValue (""), orientation (OCS_VERTICAL), hasMultipleValues (false) + {} + + SettingsItemDef (QString propName, QString propDefault, OcsWidgetOrientation propOrient = OCS_VERTICAL) + : name (propName), defaultValue (propDefault), orientation (propOrient), + hasMultipleValues(false), valueList (new QStringList), proxyList ( new ProxyList) + {} + }; + + + //Hierarchically, this is a "sub-section" of properties within a section, solely for UI organization. + //Does not correlate to config file structure. + struct GroupBlockDef + { + QString title; //title of the block containing the property or properties of this sub-section + QStringList captions; //list of captions for widgets at the block level (not associated with any particular property) + WidgetList widgets; //list of widgets at the block level (not associated with any particular property) + QList properties; //list of the property(ies) which are subordinate to the property block. + OcsWidgetOrientation widgetOrientation; //general orientation of widgets in group block + bool isVisible; //determines whether or not box border/title are visible + bool isProxy; //indicates whether or not this block defines a proxy block + QString defaultValue; //generic default value attribute + + GroupBlockDef (): title(""), widgetOrientation (OCS_VERTICAL), isVisible (true), isProxy (false), defaultValue ("") + {} + + GroupBlockDef (QString blockTitle) + : title (blockTitle), widgetOrientation (OCS_VERTICAL), isProxy (false), isVisible (true), defaultValue ("") + {} + }; + + struct CustomBlockDef + { + QString title; + QString defaultValue; //default value for widgets unique to the custom block + GroupBlockDefList blockDefList; //list of settings groups that comprise the settings within the custom block + OcsWidgetOrientation blockOrientation; + + CustomBlockDef (): title (""), defaultValue (""), blockOrientation (OCS_HORIZONTAL) + {} + + CustomBlockDef (const QString &blockTitle) + : title (blockTitle), defaultValue (""), blockOrientation (OCS_HORIZONTAL) + {} + }; +} + +#endif // VIEW_SUPPORT_HPP diff --git a/apps/opencs/view/settings/toggleblock.cpp b/apps/opencs/view/settings/toggleblock.cpp index f30ffceb0..7c484ac97 100644 --- a/apps/opencs/view/settings/toggleblock.cpp +++ b/apps/opencs/view/settings/toggleblock.cpp @@ -3,11 +3,11 @@ #include "groupbox.hpp" #include "itemblock.hpp" -CsSettings::ToggleBlock::ToggleBlock(QWidget *parent) : +CSVSettings::ToggleBlock::ToggleBlock(QWidget *parent) : CustomBlock(parent) {} -int CsSettings::ToggleBlock::build(CustomBlockDef &def) +int CSVSettings::ToggleBlock::build(CustomBlockDef &def) { if (def.blockDefList.size()==0) return -1; @@ -49,7 +49,7 @@ int CsSettings::ToggleBlock::build(CustomBlockDef &def) return 0; } -CsSettings::GroupBox *CsSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle) +CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle) { GroupBox *box = new GroupBox (false, getParent()); diff --git a/apps/opencs/view/settings/toggleblock.hpp b/apps/opencs/view/settings/toggleblock.hpp index 990dc0826..8afe701b8 100644 --- a/apps/opencs/view/settings/toggleblock.hpp +++ b/apps/opencs/view/settings/toggleblock.hpp @@ -5,7 +5,7 @@ #include "customblock.hpp" -namespace CsSettings +namespace CSVSettings { class GroupBlock; class GroupBox; diff --git a/apps/opencs/view/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp index 19c81fde9..9e3c01eda 100644 --- a/apps/opencs/view/settings/usersettingsdialog.cpp +++ b/apps/opencs/view/settings/usersettingsdialog.cpp @@ -17,7 +17,7 @@ #include "settingwidget.hpp" #include -CsSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) : +CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) : QMainWindow (parent), mUserSettings (mCfgMgr), mStackedWidget (0) { setWindowTitle(QString::fromUtf8 ("User Settings")); @@ -31,22 +31,22 @@ CsSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) : SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*))); } -CsSettings::UserSettingsDialog::~UserSettingsDialog() +CSVSettings::UserSettingsDialog::~UserSettingsDialog() { } -void CsSettings::UserSettingsDialog::closeEvent (QCloseEvent *event) +void CSVSettings::UserSettingsDialog::closeEvent (QCloseEvent *event) { writeSettings(); } -void CsSettings::UserSettingsDialog::setWidgetStates (SectionMap settingsMap) +void CSVSettings::UserSettingsDialog::setWidgetStates (CSMSettings::SectionMap settingsMap) { //iterate the tabWidget's pages (sections) for (int i = 0; i < mStackedWidget->count(); i++) { //get the settings defined for the entire section - CsSettings::SettingMap *settings = settingsMap [mStackedWidget->widget(i)->objectName()]; + CSMSettings::SettingMap *settings = settingsMap [mStackedWidget->widget(i)->objectName()]; //if found, initialize the page's widgets if (settings) @@ -57,7 +57,7 @@ void CsSettings::UserSettingsDialog::setWidgetStates (SectionMap settingsMap) } } -void CsSettings::UserSettingsDialog::buildPages() +void CSVSettings::UserSettingsDialog::buildPages() { //craete central widget with it's layout and immediate children QWidget *centralWidget = new QWidget (this); @@ -75,17 +75,17 @@ void CsSettings::UserSettingsDialog::buildPages() setCentralWidget (centralWidget); setDockOptions (QMainWindow::AllowNestedDocks); //uncomment to test with sample editor page. - //createSamplePage(); + createSamplePage(); createPage("Page1"); createPage("Page2"); createPage("Page3"); } -void CsSettings::UserSettingsDialog::createSamplePage() +void CSVSettings::UserSettingsDialog::createSamplePage() { //add pages to stackedwidget and items to listwidget - CsSettings::AbstractPage *page - = new CsSettings::EditorPage(this); + CSVSettings::AbstractPage *page + = new CSVSettings::EditorPage(this); mStackedWidget->addWidget (page); @@ -95,7 +95,7 @@ void CsSettings::UserSettingsDialog::createSamplePage() this, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); } -void CsSettings::UserSettingsDialog::positionWindow () +void CSVSettings::UserSettingsDialog::positionWindow () { QRect scr = QApplication::desktop()->screenGeometry(); @@ -103,14 +103,14 @@ void CsSettings::UserSettingsDialog::positionWindow () } -CsSettings::SectionMap CsSettings::UserSettingsDialog::loadSettings () +CSMSettings::SectionMap CSVSettings::UserSettingsDialog::loadSettings () { QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string()); mPaths.append(QString("opencs.cfg")); mPaths.append(userPath + QString("opencs.cfg")); - SectionMap settingsMap; + CSMSettings::SectionMap settingsMap; foreach (const QString &path, mPaths) { @@ -144,9 +144,9 @@ CsSettings::SectionMap CsSettings::UserSettingsDialog::loadSettings () return settingsMap; } -void CsSettings::UserSettingsDialog::writeSettings() +void CSVSettings::UserSettingsDialog::writeSettings() { - QMap settings; + QMap settings; for (int i = 0; i < mStackedWidget->count(); ++i) { @@ -158,12 +158,12 @@ void CsSettings::UserSettingsDialog::writeSettings() } -CsSettings::AbstractPage *CsSettings::UserSettingsDialog::getAbstractPage (int index) +CSVSettings::AbstractPage *CSVSettings::UserSettingsDialog::getAbstractPage (int index) { return dynamic_cast(mStackedWidget->widget(index)); } -void CsSettings::UserSettingsDialog::slotChangePage(QListWidgetItem *current, QListWidgetItem *previous) +void CSVSettings::UserSettingsDialog::slotChangePage(QListWidgetItem *current, QListWidgetItem *previous) { if (!current) current = previous; diff --git a/apps/opencs/view/settings/usersettingsdialog.hpp b/apps/opencs/view/settings/usersettingsdialog.hpp index 9836fa5d9..be36d49c2 100644 --- a/apps/opencs/view/settings/usersettingsdialog.hpp +++ b/apps/opencs/view/settings/usersettingsdialog.hpp @@ -13,7 +13,7 @@ class AbstractWidget; class QStackedWidget; class QListWidget; -namespace CsSettings { +namespace CSVSettings { class AbstractPage; class UserSettingsDialog : public QMainWindow @@ -23,7 +23,7 @@ namespace CsSettings { QStringList mPaths; QListWidget *mListWidget; QStackedWidget *mStackedWidget; - UserSettings mUserSettings; + CSMSettings::UserSettings mUserSettings; Files::ConfigurationManager mCfgMgr; public: @@ -34,10 +34,10 @@ namespace CsSettings { void closeEvent (QCloseEvent *event); AbstractPage *getAbstractPage (int index); - void setWidgetStates (SectionMap settingsMap); + void setWidgetStates (CSMSettings::SectionMap settingsMap); void buildPages(); void positionWindow (); - SectionMap loadSettings(); + CSMSettings::SectionMap loadSettings(); void writeSettings(); void createSamplePage(); From d0b23a4786ea985550e3da11dd8d03f3e8d3edd7 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 11 May 2013 07:40:10 -0500 Subject: [PATCH 5/9] Relocated "User Settings" to Edit->Preferences Removed reference from view.hpp --- apps/opencs/view/doc/view.cpp | 17 ++++------------- apps/opencs/view/doc/view.hpp | 2 -- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 4d1ab78bd..d4df3b633 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -16,8 +16,6 @@ #include "operations.hpp" #include "subview.hpp" -#include - void CSVDoc::View::closeEvent (QCloseEvent *event) { if (!mViewManager.closeRequest (this)) @@ -52,6 +50,10 @@ void CSVDoc::View::setupEditMenu() mRedo= mDocument->getUndoStack().createRedoAction (this, tr("&Redo")); mRedo->setShortcuts (QKeySequence::Redo); edit->addAction (mRedo); + + QAction *userSettings = new QAction (tr ("&Preferences"), this); + connect (userSettings, SIGNAL (triggered()), this, SLOT (showUserSettings())); + edit->addAction (userSettings); } void CSVDoc::View::setupViewMenu() @@ -80,23 +82,12 @@ void CSVDoc::View::setupWorldMenu() world->addAction (mVerify); } -void CSVDoc::View::setupSettingsMenu() -{ - QMenu *settings = menuBar()->addMenu( (tr ("&Settings"))); - - QAction *userSettings = new QAction (tr ("User Settings"), this); - connect (userSettings, SIGNAL (triggered()), this, SLOT (showUserSettings())); - settings->addAction (userSettings); - -} - void CSVDoc::View::setupUi() { setupFileMenu(); setupEditMenu(); setupViewMenu(); setupWorldMenu(); - setupSettingsMenu(); } void CSVDoc::View::updateTitle() diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index a46b72d42..b659ce501 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -59,8 +59,6 @@ namespace CSVDoc void setupWorldMenu(); - void setupSettingsMenu(); - void setupUi(); void updateTitle(); From 88df3b980f1836a1b163cec20e8217a32b5ae4d0 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sat, 11 May 2013 20:55:36 -0500 Subject: [PATCH 6/9] Implemented UserSettings as a singleton. --- apps/opencs/editor.hpp | 2 +- apps/opencs/model/settings/usersettings.cpp | 4 ++-- apps/opencs/model/settings/usersettings.hpp | 19 +++++++++++++++---- .../view/settings/usersettingsdialog.cpp | 6 +++--- .../view/settings/usersettingsdialog.hpp | 1 - 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index c242a17ea..593039db3 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -10,6 +10,7 @@ #include "view/doc/viewmanager.hpp" #include "view/doc/startup.hpp" #include "view/doc/filedialog.hpp" +#include "model/settings/usersettings.hpp" namespace CS { @@ -23,7 +24,6 @@ namespace CS FileDialog mFileDialog; Files::ConfigurationManager mCfgMgr; - void setupDataFiles(); // not implemented diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index b33b39203..aabda86b3 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -30,9 +30,9 @@ namespace boost #endif /* (BOOST_VERSION <= 104600) */ -CSMSettings::UserSettings::UserSettings(Files::ConfigurationManager &cfg) - : mCfgMgr(cfg) +CSMSettings::UserSettings::UserSettings() { + mUserSettingsInstance = this; } CSMSettings::UserSettings::~UserSettings() diff --git a/apps/opencs/model/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp index c29e27da2..cef356ad7 100644 --- a/apps/opencs/model/settings/usersettings.hpp +++ b/apps/opencs/model/settings/usersettings.hpp @@ -17,18 +17,29 @@ class QFile; namespace CSMSettings { - class UserSettings + struct UserSettings { public: - UserSettings(Files::ConfigurationManager &cfg); - ~UserSettings(); + + static UserSettings &instance() + { + static UserSettings instance; + + return instance; + } QFile *openFile (const QString &); bool writeFile(QFile *file, QMap §ions); void getSettings (QTextStream &stream, SectionMap &settings); private: - Files::ConfigurationManager &mCfgMgr; + + UserSettings *mUserSettingsInstance; + UserSettings(); + ~UserSettings(); + + UserSettings (UserSettings const &); //not implemented + void operator= (UserSettings const &); //not implemented }; } diff --git a/apps/opencs/view/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp index 9e3c01eda..24aae84f8 100644 --- a/apps/opencs/view/settings/usersettingsdialog.cpp +++ b/apps/opencs/view/settings/usersettingsdialog.cpp @@ -18,7 +18,7 @@ #include CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) : - QMainWindow (parent), mUserSettings (mCfgMgr), mStackedWidget (0) + QMainWindow (parent), mStackedWidget (0) { setWindowTitle(QString::fromUtf8 ("User Settings")); buildPages(); @@ -135,7 +135,7 @@ CSMSettings::SectionMap CSVSettings::UserSettingsDialog::loadSettings () QTextStream stream(&file); stream.setCodec(QTextCodec::codecForName("UTF-8")); - mUserSettings.getSettings(stream, settingsMap); + CSMSettings::UserSettings::instance().getSettings(stream, settingsMap); } file.close(); @@ -154,7 +154,7 @@ void CSVSettings::UserSettingsDialog::writeSettings() settings [page->objectName()] = page->getSettings(); } - mUserSettings.writeFile(mUserSettings.openFile(mPaths.back()), settings); + CSMSettings::UserSettings::instance().writeFile(CSMSettings::UserSettings::instance().openFile(mPaths.back()), settings); } diff --git a/apps/opencs/view/settings/usersettingsdialog.hpp b/apps/opencs/view/settings/usersettingsdialog.hpp index be36d49c2..3b8e3964c 100644 --- a/apps/opencs/view/settings/usersettingsdialog.hpp +++ b/apps/opencs/view/settings/usersettingsdialog.hpp @@ -23,7 +23,6 @@ namespace CSVSettings { QStringList mPaths; QListWidget *mListWidget; QStackedWidget *mStackedWidget; - CSMSettings::UserSettings mUserSettings; Files::ConfigurationManager mCfgMgr; public: From 144be597357f16a0c48d29edc3b437a8da58abc0 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 12 May 2013 14:28:36 -0500 Subject: [PATCH 7/9] Changed enum names to match OpenMW naming conventions --- apps/opencs/editor.hpp | 1 - apps/opencs/view/settings/abstractblock.cpp | 16 ++--- apps/opencs/view/settings/abstractblock.hpp | 2 +- apps/opencs/view/settings/abstractwidget.cpp | 6 +- apps/opencs/view/settings/abstractwidget.hpp | 4 +- apps/opencs/view/settings/customblock.cpp | 2 +- apps/opencs/view/settings/customblock.hpp | 2 +- apps/opencs/view/settings/editorpage.cpp | 20 +++--- apps/opencs/view/settings/itemblock.cpp | 8 +-- apps/opencs/view/settings/support.hpp | 70 ++++++++++---------- apps/opencs/view/settings/toggleblock.cpp | 2 +- 11 files changed, 66 insertions(+), 67 deletions(-) diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 593039db3..6f801e77c 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -10,7 +10,6 @@ #include "view/doc/viewmanager.hpp" #include "view/doc/startup.hpp" #include "view/doc/filedialog.hpp" -#include "model/settings/usersettings.hpp" namespace CS { diff --git a/apps/opencs/view/settings/abstractblock.cpp b/apps/opencs/view/settings/abstractblock.cpp index b2041ccbe..72d360348 100644 --- a/apps/opencs/view/settings/abstractblock.cpp +++ b/apps/opencs/view/settings/abstractblock.cpp @@ -8,12 +8,12 @@ CSVSettings::AbstractBlock::AbstractBlock(bool isVisible, QWidget* parent) : QObject (parent), mBox ( new GroupBox (isVisible, parent)), mWidgetParent (parent) {} -QLayout *CSVSettings::AbstractBlock::createLayout (OcsWidgetOrientation direction, +QLayout *CSVSettings::AbstractBlock::createLayout (Orientation direction, bool isZeroMargin, QWidget* parent) { QLayout *layout = 0; - if (direction == OCS_VERTICAL) + if (direction == Orient_Vertical) layout = new QVBoxLayout (parent); else layout = new QHBoxLayout (parent); @@ -37,27 +37,27 @@ CSVSettings::AbstractWidget *CSVSettings::AbstractBlock::buildWidget (const QStr switch (def.type) { - case OCS_RADIO_WIDGET: + case Widget_RadioButton: widg = createSettingWidget (def, layout); break; - case OCS_SPIN_WIDGET: + case Widget_SpinBox: widg = createSettingWidget (def, layout); break; - case OCS_CHECK_WIDGET: + case Widget_CheckBox: widg = createSettingWidget (def, layout); break; - case OCS_TEXT_WIDGET: + case Widget_LineEdit: widg = createSettingWidget (def, layout); break; - case OCS_LIST_WIDGET: + case Widget_ListBox: widg = createSettingWidget (def, layout); break; - case OCS_COMBO_WIDGET: + case Widget_ComboBox: widg = createSettingWidget (def, layout); break; diff --git a/apps/opencs/view/settings/abstractblock.hpp b/apps/opencs/view/settings/abstractblock.hpp index 278e351ef..42e00b6d7 100644 --- a/apps/opencs/view/settings/abstractblock.hpp +++ b/apps/opencs/view/settings/abstractblock.hpp @@ -37,7 +37,7 @@ namespace CSVSettings protected: - QLayout *createLayout (OcsWidgetOrientation direction, bool isZeroMargin, QWidget* parent = 0); + QLayout *createLayout (Orientation direction, bool isZeroMargin, QWidget* parent = 0); AbstractWidget *buildWidget (const QString &widgetName, WidgetDef &wDef, QLayout *layout = 0, bool isConnected = true) const; diff --git a/apps/opencs/view/settings/abstractwidget.cpp b/apps/opencs/view/settings/abstractwidget.cpp index 6f6d45316..94044e267 100644 --- a/apps/opencs/view/settings/abstractwidget.cpp +++ b/apps/opencs/view/settings/abstractwidget.cpp @@ -32,9 +32,9 @@ void CSVSettings::AbstractWidget::buildLabelAndWidget (QWidget *widget, WidgetDe } void CSVSettings::AbstractWidget::createLayout - (OcsWidgetOrientation direction, bool isZeroMargin) + (Orientation direction, bool isZeroMargin) { - if (direction == OCS_VERTICAL) + if (direction == Orient_Vertical) mLayout = new QVBoxLayout (); else mLayout = new QHBoxLayout (); @@ -43,7 +43,7 @@ void CSVSettings::AbstractWidget::createLayout mLayout->setContentsMargins(0, 0, 0, 0); } -QFlags CSVSettings::AbstractWidget::getAlignment (CSVSettings::OcsAlignment flag) +QFlags CSVSettings::AbstractWidget::getAlignment (CSVSettings::Alignment flag) { return QFlags(static_cast(flag)); } diff --git a/apps/opencs/view/settings/abstractwidget.hpp b/apps/opencs/view/settings/abstractwidget.hpp index 98653e465..ef00993fc 100644 --- a/apps/opencs/view/settings/abstractwidget.hpp +++ b/apps/opencs/view/settings/abstractwidget.hpp @@ -35,12 +35,12 @@ namespace CSVSettings virtual void updateWidget (const QString &value) = 0; //converts user-defined enum to Qt equivalents - QFlags getAlignment (OcsAlignment flag); + QFlags getAlignment (Alignment flag); private: //widget initialization utilities - void createLayout (OcsWidgetOrientation direction, bool isZeroMargin); + void createLayout (Orientation direction, bool isZeroMargin); void buildLabelAndWidget (QWidget *widget, WidgetDef &def, bool noLabel); diff --git a/apps/opencs/view/settings/customblock.cpp b/apps/opencs/view/settings/customblock.cpp index 03b838501..f44189569 100644 --- a/apps/opencs/view/settings/customblock.cpp +++ b/apps/opencs/view/settings/customblock.cpp @@ -37,7 +37,7 @@ int CSVSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefLis return retVal; } -CSVSettings::GroupBox *CSVSettings::CustomBlock::buildGroupBox (OcsWidgetOrientation orientation) +CSVSettings::GroupBox *CSVSettings::CustomBlock::buildGroupBox (Orientation orientation) { GroupBox *box = new GroupBox (false, mBox); QLayout *layout = createLayout (orientation, true, box); diff --git a/apps/opencs/view/settings/customblock.hpp b/apps/opencs/view/settings/customblock.hpp index 4bcc85c5c..b2f2a0261 100644 --- a/apps/opencs/view/settings/customblock.hpp +++ b/apps/opencs/view/settings/customblock.hpp @@ -25,7 +25,7 @@ namespace CSVSettings protected: - GroupBox *buildGroupBox (OcsWidgetOrientation orientation); + GroupBox *buildGroupBox (Orientation orientation); private: diff --git a/apps/opencs/view/settings/editorpage.cpp b/apps/opencs/view/settings/editorpage.cpp index 83f29438d..ad5a15f6f 100644 --- a/apps/opencs/view/settings/editorpage.cpp +++ b/apps/opencs/view/settings/editorpage.cpp @@ -48,7 +48,7 @@ void CSVSettings::EditorPage::setupUi() undoStackItem->minMax.left = "0"; undoStackItem->minMax.right = "64"; - WidgetDef stackWidget (OCS_SPIN_WIDGET); + WidgetDef stackWidget (Widget_SpinBox); stackWidget.minMax = &(undoStackItem->minMax); stackWidget.widgetWidth = 50; @@ -63,7 +63,7 @@ void CSVSettings::EditorPage::setupUi() topLevelItem->minMax.left = "1"; topLevelItem->minMax.right = "256"; - WidgetDef topLvlWinWidget (OCS_SPIN_WIDGET); + WidgetDef topLvlWinWidget (Widget_SpinBox); topLvlWinWidget.minMax = &(topLevelItem->minMax); topLvlWinWidget.widgetWidth = 50; @@ -76,9 +76,9 @@ void CSVSettings::EditorPage::setupUi() SettingsItemDef *reuseSubItem = new SettingsItemDef (reuseSubwindow.title, "Reuse Subwindows"); *(reuseSubItem->valueList) << "None" << "Top-Level" << "Document-Level"; - WidgetDef reuseSubWidget (OCS_RADIO_WIDGET); + WidgetDef reuseSubWidget (Widget_RadioButton); reuseSubWidget.valueList = (reuseSubItem->valueList); - reuseSubWidget.widgetAlignment = OCS_LEFT; + reuseSubWidget.widgetAlignment = Align_Left; reuseSubwindow.properties << reuseSubItem; reuseSubItem->widget = reuseSubWidget; @@ -89,23 +89,23 @@ void CSVSettings::EditorPage::setupUi() //custom width SettingsItemDef *widthItem = new SettingsItemDef ("Window Width", "640"); - widthItem->widget = WidgetDef (OCS_TEXT_WIDGET); + widthItem->widget = WidgetDef (Widget_LineEdit); widthItem->widget.widgetWidth = 45; //custom height SettingsItemDef *heightItem = new SettingsItemDef ("Window Height", "480"); - heightItem->widget = WidgetDef (OCS_TEXT_WIDGET); + heightItem->widget = WidgetDef (Widget_LineEdit); heightItem->widget.widgetWidth = 45; heightItem->widget.caption = "x"; customWindowSize.properties << widthItem << heightItem; - customWindowSize.widgetOrientation = OCS_HORIZONTAL; + customWindowSize.widgetOrientation = Orient_Horizontal; customWindowSize.isVisible = false; //pre-defined SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480"); - WidgetDef widthByHeightWidget = WidgetDef (OCS_COMBO_WIDGET); + WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox); widthByHeightWidget.widgetWidth = 90; *(widthByHeightItem->valueList) << "640x480" << "800x600" << "1024x768"; @@ -125,12 +125,12 @@ void CSVSettings::EditorPage::setupUi() // window size toggle windowSizeToggle.captions << "Pre-Defined" << "Custom"; - windowSizeToggle.widgetOrientation = OCS_VERTICAL; + windowSizeToggle.widgetOrientation = Orient_Vertical; windowSizeToggle.isVisible = false; //define a widget for each group in the toggle for (int i = 0; i < 2; i++) - windowSizeToggle.widgets << new WidgetDef (OCS_RADIO_WIDGET); + windowSizeToggle.widgets << new WidgetDef (Widget_RadioButton); windowSizeToggle.widgets.at(0)->isDefault = false; diff --git a/apps/opencs/view/settings/itemblock.cpp b/apps/opencs/view/settings/itemblock.cpp index 0280a6afd..9cb0ae1a1 100644 --- a/apps/opencs/view/settings/itemblock.cpp +++ b/apps/opencs/view/settings/itemblock.cpp @@ -24,8 +24,8 @@ void CSVSettings::ItemBlock::buildItemBlockWidgets (SettingsItemDef &iDef) switch (wDef.type) { - case OCS_CHECK_WIDGET: - case OCS_RADIO_WIDGET: + case Widget_CheckBox: + case Widget_RadioButton: foreach (QString item, *(iDef.valueList)) { @@ -37,8 +37,8 @@ void CSVSettings::ItemBlock::buildItemBlockWidgets (SettingsItemDef &iDef) break; - case OCS_COMBO_WIDGET: - case OCS_LIST_WIDGET: + case Widget_ComboBox: + case Widget_ListBox: //assign the item's value list to the widget's value list. //pass through to default to finish widget construction. diff --git a/apps/opencs/view/settings/support.hpp b/apps/opencs/view/settings/support.hpp index 1bd5f841a..7185d2706 100644 --- a/apps/opencs/view/settings/support.hpp +++ b/apps/opencs/view/settings/support.hpp @@ -20,59 +20,59 @@ namespace CSVSettings typedef QList WidgetList; typedef QMap ItemBlockMap; - enum OcsWidgetOrientation + enum Orientation { - OCS_HORIZONTAL, - OCS_VERTICAL + Orient_Horizontal, + Orient_Vertical }; - enum OcsWidgetType + enum WidgetType { - OCS_CHECK_WIDGET, - OCS_COMBO_WIDGET, - OCS_TEXT_WIDGET, - OCS_LIST_WIDGET, - OCS_RADIO_WIDGET, - OCS_SPIN_WIDGET, - OCS_UNDEFINED_WIDGET + Widget_CheckBox, + Widget_ComboBox, + Widget_LineEdit, + Widget_ListBox, + Widget_RadioButton, + Widget_SpinBox, + Widget_Undefined }; - enum OcsAlignment + enum Alignment { - OCS_LEFT = Qt::AlignLeft, - OCS_CENTER = Qt::AlignHCenter, - OCS_RIGHT = Qt::AlignRight + Align_Left = Qt::AlignLeft, + Align_Center = Qt::AlignHCenter, + Align_Right = Qt::AlignRight }; //template for defining the widget of a property. struct WidgetDef { - OcsWidgetType type; //type of widget providing input + WidgetType type; //type of widget providing input int labelWidth; //width of caption label int widgetWidth; //width of input widget - OcsWidgetOrientation orientation; //label / widget orientation (horizontal / vertical) + Orientation orientation; //label / widget orientation (horizontal / vertical) QString inputMask; //input mask (line edit) QString caption; //label caption. Leave empty for multiple items. See BlockDef::captionList QString value; //widget value. Leave empty for multiple items. See BlockDef::valueList CSMSettings::QStringPair *minMax; //Min/Max QString value pair. If empty, assigned to property item value pair. QStringList *valueList; //value list for list widgets. If left empty, is assigned to property item value list during block build(). bool isDefault; //isDefault - determined at runtime. - OcsAlignment valueAlignment; //left / center / right-justify text in widget - OcsAlignment widgetAlignment; //left / center / right-justify widget in group box + Alignment valueAlignment; //left / center / right-justify text in widget + Alignment widgetAlignment; //left / center / right-justify widget in group box WidgetDef() : labelWidth (-1), widgetWidth (-1), - orientation (OCS_HORIZONTAL), - isDefault (true), valueAlignment (OCS_CENTER), - widgetAlignment (OCS_RIGHT), + orientation (Orient_Horizontal), + isDefault (true), valueAlignment (Align_Center), + widgetAlignment (Align_Right), inputMask (""), value (""), caption (""), valueList (0) {} - WidgetDef (OcsWidgetType widgType) - : type (widgType), orientation (OCS_HORIZONTAL), - caption (""), value (""), valueAlignment (OCS_CENTER), - widgetAlignment (OCS_RIGHT), + WidgetDef (WidgetType widgType) + : type (widgType), orientation (Orient_Horizontal), + caption (""), value (""), valueAlignment (Align_Center), + widgetAlignment (Align_Right), labelWidth (-1), widgetWidth (-1), valueList (0), isDefault (true) {} @@ -91,13 +91,13 @@ namespace CSVSettings bool hasMultipleValues; CSMSettings::QStringPair minMax; //minimum / maximum value pair WidgetDef widget; //definition of the input widget for this setting - OcsWidgetOrientation orientation; //general orientation of the widget / label for this property + Orientation orientation; //general orientation of the widget / label for this property ProxyList *proxyList; //list of property and corresponding default values for proxy widget - SettingsItemDef() : name (""), defaultValue (""), orientation (OCS_VERTICAL), hasMultipleValues (false) + SettingsItemDef() : name (""), defaultValue (""), orientation (Orient_Vertical), hasMultipleValues (false) {} - SettingsItemDef (QString propName, QString propDefault, OcsWidgetOrientation propOrient = OCS_VERTICAL) + SettingsItemDef (QString propName, QString propDefault, Orientation propOrient = Orient_Vertical) : name (propName), defaultValue (propDefault), orientation (propOrient), hasMultipleValues(false), valueList (new QStringList), proxyList ( new ProxyList) {} @@ -112,16 +112,16 @@ namespace CSVSettings QStringList captions; //list of captions for widgets at the block level (not associated with any particular property) WidgetList widgets; //list of widgets at the block level (not associated with any particular property) QList properties; //list of the property(ies) which are subordinate to the property block. - OcsWidgetOrientation widgetOrientation; //general orientation of widgets in group block + Orientation widgetOrientation; //general orientation of widgets in group block bool isVisible; //determines whether or not box border/title are visible bool isProxy; //indicates whether or not this block defines a proxy block QString defaultValue; //generic default value attribute - GroupBlockDef (): title(""), widgetOrientation (OCS_VERTICAL), isVisible (true), isProxy (false), defaultValue ("") + GroupBlockDef (): title(""), widgetOrientation (Orient_Vertical), isVisible (true), isProxy (false), defaultValue ("") {} GroupBlockDef (QString blockTitle) - : title (blockTitle), widgetOrientation (OCS_VERTICAL), isProxy (false), isVisible (true), defaultValue ("") + : title (blockTitle), widgetOrientation (Orient_Vertical), isProxy (false), isVisible (true), defaultValue ("") {} }; @@ -130,13 +130,13 @@ namespace CSVSettings QString title; QString defaultValue; //default value for widgets unique to the custom block GroupBlockDefList blockDefList; //list of settings groups that comprise the settings within the custom block - OcsWidgetOrientation blockOrientation; + Orientation blockOrientation; - CustomBlockDef (): title (""), defaultValue (""), blockOrientation (OCS_HORIZONTAL) + CustomBlockDef (): title (""), defaultValue (""), blockOrientation (Orient_Horizontal) {} CustomBlockDef (const QString &blockTitle) - : title (blockTitle), defaultValue (""), blockOrientation (OCS_HORIZONTAL) + : title (blockTitle), defaultValue (""), blockOrientation (Orient_Horizontal) {} }; } diff --git a/apps/opencs/view/settings/toggleblock.cpp b/apps/opencs/view/settings/toggleblock.cpp index 7c484ac97..12a42ca9c 100644 --- a/apps/opencs/view/settings/toggleblock.cpp +++ b/apps/opencs/view/settings/toggleblock.cpp @@ -61,7 +61,7 @@ CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockD WidgetDef *wDef = def.widgets.at(i); wDef->caption = caption; - wDef->widgetAlignment = OCS_LEFT; + wDef->widgetAlignment = Align_Left; AbstractWidget *widg = buildWidget (caption, *wDef, layout, false); From c71d921f09166b12233a27bf605fd01b1fb81afe Mon Sep 17 00:00:00 2001 From: graffy76 Date: Sun, 12 May 2013 15:15:57 -0500 Subject: [PATCH 8/9] Moved signalUpdateEditorSettings from UserSettingsDialog to UserSettings. UserSettings is now derived from QObject. --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/settings/usersettings.hpp | 8 +++++++- apps/opencs/view/doc/view.cpp | 6 +++++- apps/opencs/view/settings/usersettingsdialog.cpp | 2 +- apps/opencs/view/settings/usersettingsdialog.hpp | 4 +--- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index f60da9472..f595d8bc8 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -93,12 +93,12 @@ opencs_units_noqt (view/settings ) opencs_units (model/settings + usersettings settingcontainer ) opencs_units_noqt (model/settings support - usersettings settingsitem ) diff --git a/apps/opencs/model/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp index cef356ad7..343702eda 100644 --- a/apps/opencs/model/settings/usersettings.hpp +++ b/apps/opencs/model/settings/usersettings.hpp @@ -17,8 +17,11 @@ class QFile; namespace CSMSettings { - struct UserSettings + struct UserSettings: public QObject { + + Q_OBJECT + public: static UserSettings &instance() @@ -41,6 +44,9 @@ namespace CSMSettings { UserSettings (UserSettings const &); //not implemented void operator= (UserSettings const &); //not implemented + signals: + void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); + }; } #endif // USERSETTINGS_HPP diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index d4df3b633..6d2d3df8c 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -16,6 +16,8 @@ #include "operations.hpp" #include "subview.hpp" +#include + void CSVDoc::View::closeEvent (QCloseEvent *event) { if (!mViewManager.closeRequest (this)) @@ -250,7 +252,7 @@ void CSVDoc::View::showUserSettings() { CSVSettings::UserSettingsDialog *settingsDialog = new CSVSettings::UserSettingsDialog(this); - connect (settingsDialog, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), + connect (&(CSMSettings::UserSettings::instance()), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)) ); settingsDialog->show(); @@ -260,6 +262,8 @@ void CSVDoc::View::slotUpdateEditorSetting(const QString &settingName, const QSt { static QString lastValue = ""; + qDebug() << "updating setting: " << settingName << " = " << settingValue; + if (lastValue != settingValue) { //evaluate settingName against tokens to determine which function to call to update Editor application. diff --git a/apps/opencs/view/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp index 24aae84f8..8f662f3a4 100644 --- a/apps/opencs/view/settings/usersettingsdialog.cpp +++ b/apps/opencs/view/settings/usersettingsdialog.cpp @@ -92,7 +92,7 @@ void CSVSettings::UserSettingsDialog::createSamplePage() new QListWidgetItem (page->objectName(), mListWidget); connect ( page, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)), - this, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); + &(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); } void CSVSettings::UserSettingsDialog::positionWindow () diff --git a/apps/opencs/view/settings/usersettingsdialog.hpp b/apps/opencs/view/settings/usersettingsdialog.hpp index 3b8e3964c..38ae2c538 100644 --- a/apps/opencs/view/settings/usersettingsdialog.hpp +++ b/apps/opencs/view/settings/usersettingsdialog.hpp @@ -16,6 +16,7 @@ class QListWidget; namespace CSVSettings { class AbstractPage; + class UserSettingsDialog : public QMainWindow { Q_OBJECT @@ -59,9 +60,6 @@ namespace CSVSettings { resize (mStackedWidget->sizeHint()); } - signals: - void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); - public slots: void slotChangePage (QListWidgetItem*, QListWidgetItem*); }; From 13242c2bd54fa376d2ac4aed03ed282010f42001 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Thu, 16 May 2013 10:14:13 -0500 Subject: [PATCH 9/9] Eliminated code centering the initial view in the middle of the screen --- apps/opencs/view/doc/view.cpp | 4 ---- apps/opencs/view/doc/viewmanager.cpp | 6 ------ 2 files changed, 10 deletions(-) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 6d2d3df8c..d088a2417 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -16,8 +16,6 @@ #include "operations.hpp" #include "subview.hpp" -#include - void CSVDoc::View::closeEvent (QCloseEvent *event) { if (!mViewManager.closeRequest (this)) @@ -262,8 +260,6 @@ void CSVDoc::View::slotUpdateEditorSetting(const QString &settingName, const QSt { static QString lastValue = ""; - qDebug() << "updating setting: " << settingName << " = " << settingValue; - if (lastValue != settingValue) { //evaluate settingName against tokens to determine which function to call to update Editor application. diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 81fb2f4e3..68d125706 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -72,12 +72,6 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) mViews.push_back (view); - if (mViews.size()==1) - { - QRect scr = QApplication::desktop()->screenGeometry(); - QRect rect = view->geometry(); - view->move (scr.center().x() - rect.center().x(), scr.center().y() - rect.center().y()); - } view->show(); connect (view, SIGNAL (newDocumentRequest ()), this, SIGNAL (newDocumentRequest()));