diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index d30c92350b..85b5ba3b60 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -57,11 +57,11 @@ opencs_hdrs_noqt (view/doc opencs_units (view/world - table tablesubview scriptsubview + table tablesubview scriptsubview util ) opencs_units_noqt (view/world - dialoguesubview util subviews enumdelegate vartypedelegate scripthighlighter recordstatusdelegate + dialoguesubview subviews enumdelegate vartypedelegate scripthighlighter recordstatusdelegate ) @@ -78,6 +78,7 @@ opencs_units (view/settings proxyblock abstractwidget usersettingsdialog + samplepage editorpage ) diff --git a/apps/opencs/model/settings/settingcontainer.hpp b/apps/opencs/model/settings/settingcontainer.hpp index eb264248df..60f4eecad2 100644 --- a/apps/opencs/model/settings/settingcontainer.hpp +++ b/apps/opencs/model/settings/settingcontainer.hpp @@ -18,8 +18,6 @@ namespace CSMSettings 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); diff --git a/apps/opencs/model/settings/settingsitem.hpp b/apps/opencs/model/settings/settingsitem.hpp index 8be05a4c70..9c5ed02af1 100644 --- a/apps/opencs/model/settings/settingsitem.hpp +++ b/apps/opencs/model/settings/settingsitem.hpp @@ -12,7 +12,6 @@ namespace CSMSettings QStringPair *mValuePair; QStringList *mValueList; bool mIsMultiValue; - QString mName; QString mDefaultValue; public: @@ -20,8 +19,10 @@ namespace CSMSettings const QString& defaultValue, QObject *parent = 0) : SettingContainer(defaultValue, parent), mIsMultiValue (isMultiValue), mValueList (0), - mName (name), mValuePair (0), mDefaultValue (defaultValue) - {} + mValuePair (0), mDefaultValue (defaultValue) + { + QObject::setObjectName(name); + } bool updateItem (const QStringList *values); bool updateItem (const QString &value); @@ -33,7 +34,6 @@ namespace CSMSettings 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); diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index aabda86b33..faaa2509b1 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -7,12 +7,15 @@ #include #include #include +#include #include #include "settingcontainer.hpp" #include + +#include /** * Workaround for problems with whitespaces in paths in older versions of Boost library */ @@ -29,47 +32,67 @@ namespace boost } /* namespace boost */ #endif /* (BOOST_VERSION <= 104600) */ - CSMSettings::UserSettings::UserSettings() { mUserSettingsInstance = this; + + mReadWriteMessage = QObject::tr("
Could not open or create file for writing

\ + Please make sure you have the right permissions and try again.
"); + + mReadOnlyMessage = QObject::tr("
Could not open file for reading

\ + Please make sure you have the right permissions and try again.
"); } CSMSettings::UserSettings::~UserSettings() { } -QFile *CSMSettings::UserSettings::openFile (const QString &filename) +QTextStream *CSMSettings::UserSettings::openFileStream (const QString &filePath, bool isReadOnly) { - QFile *file = new QFile(filename); + QFile *file = new QFile(filePath); - bool success = (file->open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) ; + QIODevice::OpenMode openFlags; - if (!success) + if (isReadOnly) + openFlags = QIODevice::ReadOnly | QIODevice::Text; + else + openFlags = QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate; + + if (!(file->open(openFlags))) { // File cannot be opened or created QMessageBox msgBox; - msgBox.setWindowTitle(QObject::tr("Error writing OpenMW configuration file")); + msgBox.setWindowTitle(QObject::tr("OpenCS configuration file I/O error")); 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())); + + QString fileMessage = QObject::tr("
File: %0").arg(file->fileName()); + + if (!isReadOnly) + msgBox.setText (mReadWriteMessage + fileMessage); + else + msgBox.setText (mReadOnlyMessage + fileMessage); + msgBox.exec(); delete file; file = 0; } - return file; + QTextStream *stream = 0; + + if (file) + { + stream = new QTextStream(file); + stream->setCodec(QTextCodec::codecForName("UTF-8")); + } + + return stream; + } -bool CSMSettings::UserSettings::writeFile(QFile *file, QMap &settings) +bool CSMSettings::UserSettings::writeFile(QMap &settings) { - if (!file) - return false; - - QTextStream stream(file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + QTextStream *stream = openFileStream(mPaths.back()); QList keyList = settings.keys(); @@ -77,61 +100,121 @@ bool CSMSettings::UserSettings::writeFile(QFile *file, QMapgetName() << " = " << item->getValue() << '\n'; + *stream << item->objectName() << " = " << item->getValue() << '\n'; } - file->close(); + stream->device()->close(); return true; } -void CSMSettings::UserSettings::getSettings(QTextStream &stream, SectionMap §ions) +const CSMSettings::SectionMap &CSMSettings::UserSettings::getSettings() { - //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*(.+)$"); - - CSMSettings::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); + return mSectionSettings; +} + +void CSMSettings::UserSettings::loadFromFile(const QString &filePath) +{ + if (filePath.isEmpty()) + return; + + mSectionSettings.clear(); + + QTextStream *stream = openFileStream (filePath, true); + + if (stream) + { + //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 whitespace, "\\s*=\\s*" + //and one or more periods, "(.+)" + + QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); + + CSMSettings::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) + mSectionSettings.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()); + sc->setObjectName(keyRe.cap(1).simplified()); + (*settings)[keyRe.cap(1).simplified()] = sc; + } + + } + + mSectionSettings.insert(section, settings); + } + + stream->device()->close(); + + return; +} + +void CSMSettings::UserSettings::loadSettings (const QString &fileName) +{ + if (mPaths.count() == 0) + { + mPaths.append(QString::fromStdString(mCfgMgr.getGlobalPath().string()) + fileName); + mPaths.append(QString::fromStdString(mCfgMgr.getLocalPath().string()) + fileName); + mPaths.append(QString::fromStdString(mCfgMgr.getUserPath().string()) + fileName); + } + + foreach (const QString &path, mPaths) + { + qDebug() << "Loading config file:" << qPrintable(path); + loadFromFile(path); + } +} + +void CSMSettings::UserSettings::updateSettings (const QString §ionName, const QString &settingName) +{ + SettingMap *settings = mSectionSettings[sectionName]; + + if (!settings) + return; + + SettingContainer *setting = 0; + + if (settingName.isEmpty()) + { + foreach (setting, *settings) + emit signalUpdateEditorSetting (setting->objectName(), setting->getValue()); + } + else + { + setting = (*settings)[settingName]; + + if (setting) + emit signalUpdateEditorSetting (setting->objectName(), setting->getValue()); + } } diff --git a/apps/opencs/model/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp index 343702edad..3a7bbd1eb2 100644 --- a/apps/opencs/model/settings/usersettings.hpp +++ b/apps/opencs/model/settings/usersettings.hpp @@ -10,6 +10,10 @@ #include "support.hpp" +#ifndef Q_MOC_RUN +#include +#endif + namespace Files { typedef std::vector PathContainer; struct ConfigurationManager;} @@ -22,6 +26,14 @@ namespace CSMSettings { Q_OBJECT + SectionMap mSectionSettings; + UserSettings *mUserSettingsInstance; + QStringList mPaths; + Files::ConfigurationManager mCfgMgr; + + QString mReadOnlyMessage; + QString mReadWriteMessage; + public: static UserSettings &instance() @@ -31,19 +43,22 @@ namespace CSMSettings { return instance; } - QFile *openFile (const QString &); - bool writeFile(QFile *file, QMap §ions); - void getSettings (QTextStream &stream, SectionMap &settings); + bool writeFile(QMap §ions); + const SectionMap &getSettings (); + void updateSettings (const QString §ionName, const QString &settingName = ""); + void loadSettings (const QString &fileName); private: - UserSettings *mUserSettingsInstance; UserSettings(); ~UserSettings(); UserSettings (UserSettings const &); //not implemented void operator= (UserSettings const &); //not implemented + QTextStream *openFileStream (const QString &filePath, bool isReadOnly = false); + void loadFromFile (const QString &filePath = ""); + signals: void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index e11fe0fc83..2bb8d07b37 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -39,7 +39,7 @@ CSMWorld::RefIdCollection::RefIdCollection() mColumns.push_back (RefIdColumn ("ID", ColumnBase::Display_String, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mId = &mColumns.back(); - mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_Integer, + mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_RecordState, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mModified = &mColumns.back(); mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_Integer, @@ -537,4 +537,4 @@ void CSMWorld::RefIdCollection::load (ESM::ESMReader& reader, bool base, Univers int CSMWorld::RefIdCollection::getAppendIndex (UniversalId::Type type) const { return mData.getAppendIndex (type); -} \ No newline at end of file +} diff --git a/apps/opencs/view/doc/subview.cpp b/apps/opencs/view/doc/subview.cpp index affada0124..731adabb35 100644 --- a/apps/opencs/view/doc/subview.cpp +++ b/apps/opencs/view/doc/subview.cpp @@ -1,5 +1,6 @@ #include "subview.hpp" + CSVDoc::SubView::SubView (const CSMWorld::UniversalId& id) : mUniversalId (id) { /// \todo add a button to the title bar that clones this sub view @@ -15,3 +16,7 @@ CSMWorld::UniversalId CSVDoc::SubView::getUniversalId() const { return mUniversalId; } + +void CSVDoc::SubView::updateEditorSetting (const QString &settingName, const QString &settingValue) +{ +} diff --git a/apps/opencs/view/doc/subview.hpp b/apps/opencs/view/doc/subview.hpp index 985c5eb3ca..280a2a4879 100644 --- a/apps/opencs/view/doc/subview.hpp +++ b/apps/opencs/view/doc/subview.hpp @@ -35,6 +35,7 @@ namespace CSVDoc CSMWorld::UniversalId getUniversalId() const; virtual void setEditLock (bool locked) = 0; + virtual void updateEditorSetting (const QString &, const QString &); signals: @@ -42,4 +43,4 @@ namespace CSVDoc }; } -#endif \ No newline at end of file +#endif diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 2857f4a54a..f85a822d8d 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -258,11 +258,14 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id) /// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis) SubView *view = mSubViewFactory.makeSubView (id, *mDocument); + view->setObjectName ("subview"); mSubViewWindow.addDockWidget (Qt::TopDockWidgetArea, view); connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&)), this, SLOT (addSubView (const CSMWorld::UniversalId&))); + CSMSettings::UserSettings::instance().updateSettings("Editor", "Record Status Display"); + view->show(); } @@ -366,20 +369,13 @@ void CSVDoc::View::showUserSettings() { CSVSettings::UserSettingsDialog *settingsDialog = new CSVSettings::UserSettingsDialog(this); - connect (&(CSMSettings::UserSettings::instance()), 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) +void CSVDoc::View::updateEditorSetting (const QString &settingName, const QString &settingValue) { - static QString lastValue = ""; - - if (lastValue != settingValue) - { - //evaluate settingName against tokens to determine which function to call to update Editor application. - - lastValue = settingValue; - } + if (settingName == "Record Status Display") + foreach (QObject *view, mSubViewWindow.children()) + if (view->objectName() == "subview") + dynamic_cast(view)->updateEditorSetting (settingName, settingValue); } diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 0552a86cbb..2fbe881ebd 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -68,6 +68,8 @@ namespace CSVDoc void exitApplication(); + void loadUserSettings(); + public: View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews); @@ -88,6 +90,8 @@ namespace CSVDoc Operations *getOperations() const; + void updateEditorSetting (const QString &, const QString &); + signals: void newDocumentRequest(); @@ -102,8 +106,6 @@ namespace CSVDoc void abortOperation (int type); - void slotUpdateEditorSetting (const QString &settingName, const QString &settingValue); - private slots: void newView(); diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 97dd8b997c..a5ccc9efcf 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -13,13 +13,13 @@ #include "../world/enumdelegate.hpp" #include "../world/vartypedelegate.hpp" #include "../world/recordstatusdelegate.hpp" +#include "../settings/usersettingsdialog.hpp" #include "view.hpp" #include #include #include -#include void CSVDoc::ViewManager::updateIndices() { @@ -121,6 +121,11 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState, new CSVWorld::RecordStatusDelegateFactory() ); + + connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), + this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); + + CSMSettings::UserSettings::instance().loadSettings("opencs.cfg"); } CSVDoc::ViewManager::~ViewManager() @@ -347,3 +352,10 @@ void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view) if (notifySaveOnClose (view)) QApplication::instance()->exit(); } + +void CSVDoc::ViewManager::slotUpdateEditorSetting (const QString &settingName, const QString &settingValue) +{ + if (settingName == "Record Status Display") + foreach (CSVDoc::View *view, mViews) + view->updateEditorSetting (settingName, settingValue); +} diff --git a/apps/opencs/view/doc/viewmanager.hpp b/apps/opencs/view/doc/viewmanager.hpp index 90f23eaa11..2b0890a21b 100644 --- a/apps/opencs/view/doc/viewmanager.hpp +++ b/apps/opencs/view/doc/viewmanager.hpp @@ -72,6 +72,8 @@ namespace CSVDoc void progress (int current, int max, int type, int threads, CSMDoc::Document *document); void onExitWarningHandler(int state, CSMDoc::Document* document); + + void slotUpdateEditorSetting (const QString &, const QString &); }; } diff --git a/apps/opencs/view/settings/abstractpage.cpp b/apps/opencs/view/settings/abstractpage.cpp index 512b5abbd1..6e34af63b0 100644 --- a/apps/opencs/view/settings/abstractpage.cpp +++ b/apps/opencs/view/settings/abstractpage.cpp @@ -13,18 +13,32 @@ CSVSettings::AbstractPage::AbstractPage(QWidget *parent): QWidget(parent) { + QGridLayout *pageLayout = new QGridLayout(this); + setLayout (pageLayout); } CSVSettings::AbstractPage::AbstractPage(const QString &pageName, QWidget *parent): QWidget(parent) { QWidget::setObjectName (pageName); + + QGridLayout *pageLayout = new QGridLayout(this); + setLayout (pageLayout); } CSVSettings::AbstractPage::~AbstractPage() { } - +/* +void CSVSettings::AbstractPage::setupUi() +{ + // Hacks to get the stylesheet look properly + #ifdef Q_OS_MAC + QPlastiqueStyle *style = new QPlastiqueStyle; + //profilesComboBox->setStyle(style); + #endif +} +*/ CSMSettings::SettingList *CSVSettings::AbstractPage::getSettings() { CSMSettings::SettingList *settings = new CSMSettings::SettingList(); diff --git a/apps/opencs/view/settings/abstractpage.hpp b/apps/opencs/view/settings/abstractpage.hpp index 15ac82a62d..1665b59d24 100644 --- a/apps/opencs/view/settings/abstractpage.hpp +++ b/apps/opencs/view/settings/abstractpage.hpp @@ -28,7 +28,7 @@ namespace CSVSettings { ~AbstractPage(); - virtual void setupUi()=0; + virtual void setupUi() = 0; virtual void initializeWidgets (const CSMSettings::SettingMap &settings) = 0; @@ -39,7 +39,7 @@ namespace CSVSettings { protected: template - AbstractBlock *buildBlock (T &def) + AbstractBlock *buildBlock (T *def) { S *block = new S (this); int ret = block->build (def); @@ -47,12 +47,12 @@ namespace CSVSettings { if (ret < 0) return 0; - QWidget::layout()->addWidget (block->getGroupBox()); + QGroupBox *box = block->getGroupBox(); + QWidget::layout()->addWidget (box); return block; } - }; } diff --git a/apps/opencs/view/settings/blankpage.cpp b/apps/opencs/view/settings/blankpage.cpp index 57d5c7caa7..bf9c3c86ea 100644 --- a/apps/opencs/view/settings/blankpage.cpp +++ b/apps/opencs/view/settings/blankpage.cpp @@ -43,10 +43,7 @@ void CSVSettings::BlankPage::initPage() void CSVSettings::BlankPage::setupUi() { QGroupBox *pageBox = new QGroupBox(this); - QLayout* pageLayout = new QVBoxLayout(); - - setLayout(pageLayout); - pageLayout->addWidget(pageBox); + layout()->addWidget(pageBox); } void CSVSettings::BlankPage::initializeWidgets (const CSMSettings::SettingMap &settings) diff --git a/apps/opencs/view/settings/customblock.cpp b/apps/opencs/view/settings/customblock.cpp index f441895693..933abf423b 100644 --- a/apps/opencs/view/settings/customblock.cpp +++ b/apps/opencs/view/settings/customblock.cpp @@ -23,7 +23,7 @@ int CSVSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefLis for (; listIt != defList.end(); ++listIt) { if (!(*listIt)->isProxy) - retVal = buildGroupBlock (*(*listIt)); + retVal = buildGroupBlock (*listIt); else { mGroupList << proxyBlock; @@ -32,7 +32,7 @@ int CSVSettings::CustomBlock::build(GroupBlockDefList &defList, GroupBlockDefLis } if (proxyIt != defaultIt) - retVal = buildProxyBlock (*(*proxyIt), proxyBlock); + retVal = buildProxyBlock (*proxyIt, proxyBlock); return retVal; } @@ -45,7 +45,7 @@ CSVSettings::GroupBox *CSVSettings::CustomBlock::buildGroupBox (Orientation orie return box; } -int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def) +int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef *def) { GroupBlock *block = new GroupBlock (getParent()); @@ -57,9 +57,9 @@ int CSVSettings::CustomBlock::buildGroupBlock(GroupBlockDef &def) return block->build(def); } -int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *block) +int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef *def, ProxyBlock *block) { - if (def.properties.size() != 1) + if (def->properties.size() != 1) return -1; int retVal = block->build(def); @@ -67,7 +67,7 @@ int CSVSettings::CustomBlock::buildProxyBlock(GroupBlockDef& def, ProxyBlock *bl if (retVal != 0) return retVal; - foreach (QStringList *list, *(def.properties.at(0)->proxyList)) + foreach (QStringList *list, *(def->properties.at(0)->proxyList)) { QString proxiedBlockName = list->at(0); diff --git a/apps/opencs/view/settings/customblock.hpp b/apps/opencs/view/settings/customblock.hpp index b2f2a02617..f831a90baf 100644 --- a/apps/opencs/view/settings/customblock.hpp +++ b/apps/opencs/view/settings/customblock.hpp @@ -29,8 +29,8 @@ namespace CSVSettings private: - int buildGroupBlock(GroupBlockDef &def); - int buildProxyBlock(GroupBlockDef &def, ProxyBlock *block); + int buildGroupBlock(GroupBlockDef *def); + int buildProxyBlock(GroupBlockDef *def, ProxyBlock *block); }; } #endif // CUSTOMBLOCK_HPP diff --git a/apps/opencs/view/settings/editorpage.cpp b/apps/opencs/view/settings/editorpage.cpp index ad5a15f6fd..7d67312e7d 100644 --- a/apps/opencs/view/settings/editorpage.cpp +++ b/apps/opencs/view/settings/editorpage.cpp @@ -1,156 +1,52 @@ #include "editorpage.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_OS_MAC -#include -#endif - -#include "../../model/settings/usersettings.hpp" #include "groupblock.hpp" -#include "toggleblock.hpp" +#include "../../model/settings/usersettings.hpp" -CSVSettings::EditorPage::EditorPage(QWidget *parent): - AbstractPage("Editor", parent) +CSVSettings::EditorPage::EditorPage(QWidget* parent) : + AbstractPage(parent) { - // Hacks to get the stylesheet look properly -#ifdef Q_OS_MAC - QPlastiqueStyle *style = new QPlastiqueStyle; - //profilesComboBox->setStyle(style); -#endif - setupUi(); } +CSVSettings::EditorPage::EditorPage (const QString &pageName, QWidget* parent) + : AbstractPage (pageName, parent) +{ + setupUi(); +} + +CSVSettings::GroupBlockDef *CSVSettings::EditorPage::setupRecordStatusDisplay() +{ + GroupBlockDef *statusBlock = new GroupBlockDef(QString("Record Status Display")); + + SettingsItemDef *statusItem = new SettingsItemDef (statusBlock->title, "Icon and Text"); + *(statusItem->valueList) << QString("Icon and Text") << QString("Icon Only") << QString("Text Only"); + + WidgetDef statusWidget (Widget_RadioButton); + statusWidget.valueList = statusItem->valueList; + + statusItem->widget = statusWidget; + + statusBlock->properties << statusItem; + + return statusBlock; +} + void CSVSettings::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 (Widget_SpinBox); - 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 (Widget_SpinBox); - 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 (Widget_RadioButton); - reuseSubWidget.valueList = (reuseSubItem->valueList); - reuseSubWidget.widgetAlignment = Align_Left; - - reuseSubwindow.properties << reuseSubItem; - reuseSubItem->widget = reuseSubWidget; - - /////////////////////////////// - //custom window size properties - /////////////////////////////// - - //custom width - SettingsItemDef *widthItem = new SettingsItemDef ("Window Width", "640"); - widthItem->widget = WidgetDef (Widget_LineEdit); - widthItem->widget.widgetWidth = 45; - - //custom height - SettingsItemDef *heightItem = new SettingsItemDef ("Window Height", "480"); - heightItem->widget = WidgetDef (Widget_LineEdit); - heightItem->widget.widgetWidth = 45; - heightItem->widget.caption = "x"; - - customWindowSize.properties << widthItem << heightItem; - customWindowSize.widgetOrientation = Orient_Horizontal; - customWindowSize.isVisible = false; - - - //pre-defined - SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480"); - WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox); - 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 = 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 (Widget_RadioButton); - - 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); + mAbstractBlocks << buildBlock(setupRecordStatusDisplay()); foreach (AbstractBlock *block, mAbstractBlocks) { connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)), this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) ); } + + connect ( this, + SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)), + &(CSMSettings::UserSettings::instance()), + SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); + } void CSVSettings::EditorPage::initializeWidgets (const CSMSettings::SettingMap &settings) diff --git a/apps/opencs/view/settings/editorpage.hpp b/apps/opencs/view/settings/editorpage.hpp index 0c1e80e899..09769bf49a 100644 --- a/apps/opencs/view/settings/editorpage.hpp +++ b/apps/opencs/view/settings/editorpage.hpp @@ -1,28 +1,30 @@ -#ifndef EDITORPAGE_H -#define EDITORPAGE_H +#ifndef EDITORPAGE_HPP +#define EDITORPAGE_HPP +#include "support.hpp" #include "abstractpage.hpp" -class QGroupBox; - -namespace CSVSettings { - - class UserSettings; - class AbstractBlock; - +namespace CSVSettings +{ class EditorPage : public AbstractPage { Q_OBJECT public: + explicit EditorPage(QWidget *parent = 0); + explicit EditorPage (const QString &pageName, QWidget* parent = 0); - EditorPage(QWidget *parent = 0); - - void setupUi(); void initializeWidgets (const CSMSettings::SettingMap &settings); + void setupUi(); + + private: + GroupBlockDef *setupRecordStatusDisplay(); signals: void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); + + public slots: }; } -#endif //EDITORPAGE_H + +#endif // EDITORPAGE_HPP diff --git a/apps/opencs/view/settings/groupblock.cpp b/apps/opencs/view/settings/groupblock.cpp index b18f629ba1..f23a4ae282 100644 --- a/apps/opencs/view/settings/groupblock.cpp +++ b/apps/opencs/view/settings/groupblock.cpp @@ -9,22 +9,22 @@ CSVSettings::GroupBlock::GroupBlock (bool isVisible, QWidget *parent) : AbstractBlock (isVisible, parent) {} -int CSVSettings::GroupBlock::build (GroupBlockDef &def) +int CSVSettings::GroupBlock::build (GroupBlockDef *def) { - if (def.properties.size() == 0) + if (def->properties.size() == 0) return -1; int retVal = 0; - setVisible (def.isVisible); + setVisible (def->isVisible); - mBox->setLayout(createLayout (def.widgetOrientation, true)); + mBox->setLayout(createLayout (def->widgetOrientation, true)); - setObjectName (def.title); - mBox->setTitle (def.title); + setObjectName (def->title); + mBox->setTitle (def->title); - foreach (SettingsItemDef *itemDef, def.properties) + foreach (SettingsItemDef *itemDef, def->properties) { ItemBlock *block = new ItemBlock (mBox); diff --git a/apps/opencs/view/settings/groupblock.hpp b/apps/opencs/view/settings/groupblock.hpp index a8fd4e3b44..bd16d0b5b0 100644 --- a/apps/opencs/view/settings/groupblock.hpp +++ b/apps/opencs/view/settings/groupblock.hpp @@ -16,7 +16,7 @@ namespace CSVSettings GroupBlock (QWidget* parent = 0); GroupBlock (bool isVisible, QWidget *parent = 0); - int build (GroupBlockDef &def); + int build (GroupBlockDef *def); bool updateSettings (const CSMSettings::SettingMap &settings); diff --git a/apps/opencs/view/settings/proxyblock.cpp b/apps/opencs/view/settings/proxyblock.cpp index 71a3070841..f47c9dd07d 100644 --- a/apps/opencs/view/settings/proxyblock.cpp +++ b/apps/opencs/view/settings/proxyblock.cpp @@ -5,10 +5,10 @@ CSVSettings::ProxyBlock::ProxyBlock (QWidget *parent) : GroupBlock (parent) { } -int CSVSettings::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; + mValueList = proxyDef->properties.at(0)->valueList; bool success = GroupBlock::build(proxyDef); diff --git a/apps/opencs/view/settings/proxyblock.hpp b/apps/opencs/view/settings/proxyblock.hpp index f757842eaf..73d31fecfc 100644 --- a/apps/opencs/view/settings/proxyblock.hpp +++ b/apps/opencs/view/settings/proxyblock.hpp @@ -21,7 +21,7 @@ namespace CSVSettings explicit ProxyBlock (ItemBlock *proxyItemBlock, QWidget *parent = 0); void addSetting (ItemBlock* settingBlock, QStringList *proxyList); - int build (GroupBlockDef &def); + int build (GroupBlockDef *def); CSMSettings::SettingList *getSettings() { return 0; } bool updateSettings (const CSMSettings::SettingMap &settings); diff --git a/apps/opencs/view/settings/samplepage.cpp b/apps/opencs/view/settings/samplepage.cpp new file mode 100644 index 0000000000..1ed2f0505c --- /dev/null +++ b/apps/opencs/view/settings/samplepage.cpp @@ -0,0 +1,159 @@ +#include "samplepage.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_OS_MAC +#include +#endif + +#include "../../model/settings/usersettings.hpp" +#include "groupblock.hpp" +#include "toggleblock.hpp" + +CSVSettings::SamplePage::SamplePage(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 CSVSettings::SamplePage::setupUi() +{ + GroupBlockDef *undoStack = new GroupBlockDef(QString("Undo Stack Size")); + GroupBlockDef *topLevelWindowCount = new GroupBlockDef(QString("Maximum Top-Level Window Count")); + GroupBlockDef *reuseSubwindow = new GroupBlockDef(QString("Reuse Subwindows")); + GroupBlockDef *customWindowSize = new GroupBlockDef(QString ("Custom Window Size")); + GroupBlockDef *definedWindowSize = new GroupBlockDef(QString ("Pre-Defined Window Size")); + GroupBlockDef *windowSizeToggle = new GroupBlockDef(QString ("Window Size")); + CustomBlockDef *windowSize = new CustomBlockDef(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 (Widget_SpinBox); + 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 (Widget_SpinBox); + 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 (Widget_RadioButton); + reuseSubWidget.valueList = (reuseSubItem->valueList); + reuseSubWidget.widgetAlignment = Align_Left; + + reuseSubwindow->properties << reuseSubItem; + reuseSubItem->widget = reuseSubWidget; + + /////////////////////////////// + //custom window size properties + /////////////////////////////// + + //custom width + SettingsItemDef *widthItem = new SettingsItemDef ("Window Width", "640"); + widthItem->widget = WidgetDef (Widget_LineEdit); + widthItem->widget.widgetWidth = 45; + + //custom height + SettingsItemDef *heightItem = new SettingsItemDef ("Window Height", "480"); + heightItem->widget = WidgetDef (Widget_LineEdit); + heightItem->widget.widgetWidth = 45; + heightItem->widget.caption = "x"; + + customWindowSize->properties << widthItem << heightItem; + customWindowSize->widgetOrientation = Orient_Horizontal; + customWindowSize->isVisible = false; + + + //pre-defined + SettingsItemDef *widthByHeightItem = new SettingsItemDef ("Window Size", "640x480"); + WidgetDef widthByHeightWidget = WidgetDef (Widget_ComboBox); + 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 = 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 (Widget_RadioButton); + + windowSizeToggle->widgets.at(0)->isDefault = false; + + windowSize->blockDefList << windowSizeToggle << definedWindowSize << customWindowSize; + windowSize->defaultValue = "Custom"; + + 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 CSVSettings::SamplePage::initializeWidgets (const CSMSettings::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/view/settings/samplepage.hpp b/apps/opencs/view/settings/samplepage.hpp new file mode 100644 index 0000000000..3a9448bad2 --- /dev/null +++ b/apps/opencs/view/settings/samplepage.hpp @@ -0,0 +1,28 @@ +#ifndef SAMPLEPAGE_H +#define SAMPLEPAGE_H + +#include "abstractpage.hpp" + +class QGroupBox; + +namespace CSVSettings { + + class UserSettings; + class AbstractBlock; + + class SamplePage : public AbstractPage + { + Q_OBJECT + + public: + + explicit SamplePage(QWidget *parent = 0); + + void setupUi(); + void initializeWidgets (const CSMSettings::SettingMap &settings); + + signals: + void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); + }; +} +#endif //SAMPLEPAGE_H diff --git a/apps/opencs/view/settings/toggleblock.cpp b/apps/opencs/view/settings/toggleblock.cpp index 12a42ca9c5..3406a62c4d 100644 --- a/apps/opencs/view/settings/toggleblock.cpp +++ b/apps/opencs/view/settings/toggleblock.cpp @@ -7,24 +7,24 @@ CSVSettings::ToggleBlock::ToggleBlock(QWidget *parent) : CustomBlock(parent) {} -int CSVSettings::ToggleBlock::build(CustomBlockDef &def) +int CSVSettings::ToggleBlock::build(CustomBlockDef *def) { - if (def.blockDefList.size()==0) + if (def->blockDefList.size()==0) return -1; - QList::Iterator it = def.blockDefList.begin(); + 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 ) + 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); + QLayout *blockLayout = createLayout (def->blockOrientation, true); GroupBox *propertyBox = buildGroupBox (toggleDef->widgetOrientation); mBox->setLayout(blockLayout); @@ -34,13 +34,13 @@ int CSVSettings::ToggleBlock::build(CustomBlockDef &def) //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); + 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); + GroupBox *toggleBox = buildToggleWidgets (toggleDef, def->defaultValue); blockLayout->addWidget(toggleBox); blockLayout->addWidget(propertyBox); @@ -49,16 +49,16 @@ int CSVSettings::ToggleBlock::build(CustomBlockDef &def) return 0; } -CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle) +CSVSettings::GroupBox *CSVSettings::ToggleBlock::buildToggleWidgets (GroupBlockDef *def, QString &defaultToggle) { GroupBox *box = new GroupBox (false, getParent()); - QLayout *layout = createLayout (def.widgetOrientation, true, static_cast(box)); + QLayout *layout = createLayout (def->widgetOrientation, true, static_cast(box)); - for (int i = 0; i < def.widgets.size(); ++i) + for (int i = 0; i < def->widgets.size(); ++i) { - QString caption = def.captions.at(i); - WidgetDef *wDef = def.widgets.at(i); + QString caption = def->captions.at(i); + WidgetDef *wDef = def->widgets.at(i); wDef->caption = caption; wDef->widgetAlignment = Align_Left; diff --git a/apps/opencs/view/settings/toggleblock.hpp b/apps/opencs/view/settings/toggleblock.hpp index 8afe701b85..db617e7676 100644 --- a/apps/opencs/view/settings/toggleblock.hpp +++ b/apps/opencs/view/settings/toggleblock.hpp @@ -18,10 +18,10 @@ namespace CSVSettings public: explicit ToggleBlock(QWidget *parent = 0); - int build (CustomBlockDef &def); + int build (CustomBlockDef *def); private: - GroupBox *buildToggleWidgets (GroupBlockDef &def, QString &defaultToggle); + GroupBox *buildToggleWidgets (GroupBlockDef *def, QString &defaultToggle); }; } #endif // TOGGLEBLOCK_HPP diff --git a/apps/opencs/view/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp index 012fc04087..c48e0ee977 100644 --- a/apps/opencs/view/settings/usersettingsdialog.cpp +++ b/apps/opencs/view/settings/usersettingsdialog.cpp @@ -9,26 +9,27 @@ #include #include #include +#include #include "blankpage.hpp" -#include "editorpage.hpp" -#include "../../model/settings/support.hpp" +#include "samplepage.hpp" +#include "../../model/settings/support.hpp" +#include #include "settingwidget.hpp" -#include CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) : QMainWindow (parent), mStackedWidget (0) { setWindowTitle(QString::fromUtf8 ("User Settings")); buildPages(); - setWidgetStates (loadSettings()); + setWidgetStates (); positionWindow (); connect (mListWidget, SIGNAL (currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, - SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*))); + SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*))); } CSVSettings::UserSettingsDialog::~UserSettingsDialog() @@ -40,13 +41,16 @@ void CSVSettings::UserSettingsDialog::closeEvent (QCloseEvent *event) writeSettings(); } -void CSVSettings::UserSettingsDialog::setWidgetStates (CSMSettings::SectionMap settingsMap) +void CSVSettings::UserSettingsDialog::setWidgetStates () { + CSMSettings::UserSettings::instance().loadSettings("opencs.cfg"); + const CSMSettings::SectionMap §ionSettings = CSMSettings::UserSettings::instance().getSettings(); + //iterate the tabWidget's pages (sections) for (int i = 0; i < mStackedWidget->count(); i++) { //get the settings defined for the entire section - CSMSettings::SettingMap *settings = settingsMap [mStackedWidget->widget(i)->objectName()]; + CSMSettings::SettingMap *settings = sectionSettings [mStackedWidget->widget(i)->objectName()]; //if found, initialize the page's widgets if (settings) @@ -65,18 +69,25 @@ void CSVSettings::UserSettingsDialog::buildPages() mListWidget = new QListWidget (centralWidget); mStackedWidget = new QStackedWidget (centralWidget); - QLayout* dialogLayout = new QHBoxLayout(); + QGridLayout* dialogLayout = new QGridLayout(); - dialogLayout->addWidget (mListWidget); - dialogLayout->addWidget (mStackedWidget); + mListWidget->setMinimumWidth(0); + mListWidget->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding); + + mStackedWidget->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); + + dialogLayout->addWidget (mListWidget,0,0); + dialogLayout->addWidget (mStackedWidget,0,1, Qt::AlignTop); centralWidget->setLayout (dialogLayout); setCentralWidget (centralWidget); setDockOptions (QMainWindow::AllowNestedDocks); + //uncomment to test with sample editor page. - //createSamplePage(); - createPage("Page1"); + // TODO: Reimplement sample page using createPage function + //createPage("Sample"); + createPage("Editor"); createPage("Page2"); createPage("Page3"); } @@ -85,14 +96,16 @@ void CSVSettings::UserSettingsDialog::createSamplePage() { //add pages to stackedwidget and items to listwidget CSVSettings::AbstractPage *page - = new CSVSettings::EditorPage(this); + = new CSVSettings::SamplePage(this); mStackedWidget->addWidget (page); - new QListWidgetItem (page->objectName(), mListWidget); + connect ( page, + SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)), + &(CSMSettings::UserSettings::instance()), + SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); - connect ( page, SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)), - &(CSMSettings::UserSettings::instance()), SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); + new QListWidgetItem (page->objectName(), mListWidget); } void CSVSettings::UserSettingsDialog::positionWindow () @@ -103,47 +116,6 @@ void CSVSettings::UserSettingsDialog::positionWindow () } -CSMSettings::SectionMap CSVSettings::UserSettingsDialog::loadSettings () -{ - QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string()); - - mPaths.append(QString("opencs.cfg")); - mPaths.append(userPath + QString("opencs.cfg")); - - CSMSettings::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")); - - CSMSettings::UserSettings::instance().getSettings(stream, settingsMap); - } - - file.close(); - } - - return settingsMap; -} - void CSVSettings::UserSettingsDialog::writeSettings() { QMap settings; @@ -154,7 +126,7 @@ void CSVSettings::UserSettingsDialog::writeSettings() settings [page->objectName()] = page->getSettings(); } - CSMSettings::UserSettings::instance().writeFile(CSMSettings::UserSettings::instance().openFile(mPaths.back()), settings); + CSMSettings::UserSettings::instance().writeFile(settings); } diff --git a/apps/opencs/view/settings/usersettingsdialog.hpp b/apps/opencs/view/settings/usersettingsdialog.hpp index 31d40ca017..5e73fd1235 100644 --- a/apps/opencs/view/settings/usersettingsdialog.hpp +++ b/apps/opencs/view/settings/usersettingsdialog.hpp @@ -4,14 +4,13 @@ #include #include #include - -#ifndef Q_MOC_RUN -#include -#endif +#include #include "../../model/settings/usersettings.hpp" #include "../../model/settings/support.hpp" +#include "editorpage.hpp" + class QHBoxLayout; class AbstractWidget; class QStackedWidget; @@ -28,7 +27,6 @@ namespace CSVSettings { QStringList mPaths; QListWidget *mListWidget; QStackedWidget *mStackedWidget; - Files::ConfigurationManager mCfgMgr; public: UserSettingsDialog(QMainWindow *parent = 0); @@ -38,10 +36,9 @@ namespace CSVSettings { void closeEvent (QCloseEvent *event); AbstractPage *getAbstractPage (int index); - void setWidgetStates (CSMSettings::SectionMap settingsMap); + void setWidgetStates (); void buildPages(); void positionWindow (); - CSMSettings::SectionMap loadSettings(); void writeSettings(); void createSamplePage(); @@ -61,6 +58,12 @@ namespace CSVSettings { if (mStackedWidget->sizeHint().height() < 480) mStackedWidget->sizeHint().setHeight(480); + QFontMetrics fm (QApplication::font()); + int textWidth = fm.width(page->objectName()); + + if ((textWidth + 50) > mListWidget->minimumWidth()) + mListWidget->setMinimumWidth(textWidth + 50); + resize (mStackedWidget->sizeHint()); } diff --git a/apps/opencs/view/world/recordstatusdelegate.cpp b/apps/opencs/view/world/recordstatusdelegate.cpp index aa9487b706..3c61c4af45 100644 --- a/apps/opencs/view/world/recordstatusdelegate.cpp +++ b/apps/opencs/view/world/recordstatusdelegate.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "../../model/settings/usersettings.hpp" CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObject *parent) : CommandDelegate (undoStack, parent) @@ -36,23 +37,23 @@ void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptio switch (index.data().toInt()) { case 0: // State_BaseOnly - text = "base"; + text = "Base"; break; case 1: // State_Modified - text = "modified"; + text = "Modified"; icon = mModifiedIcon; break; case 2: // State_Modified_Only - text = "added"; + text = "Added"; icon = mAddedIcon; break; case 3: // State_Deleted case 4: // State_Erased - text = "deleted"; + text = "Deleted"; icon = mDeletedIcon; break; @@ -70,14 +71,14 @@ void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptio if (mStatusDisplay == 0 && (icon) ) { - iconRect.setRight (iconRect.left() + mIconSize*2); - textRect.setLeft (iconRect.right() + mTextLeftOffset *2); + iconRect.setRight (iconRect.left()+ mIconSize*2); + textRect.setLeft (iconRect.right() + mTextLeftOffset *1.25); } else textRect.setLeft (textRect.left() + mTextLeftOffset ); if ( (mStatusDisplay == 0 || mStatusDisplay == 1) && (icon) ) - painter->drawPixmap(iconRect.center(),icon->pixmap(mIconSize, mIconSize)); + painter->drawPixmap(iconRect.center().x()-10,iconRect.center().y()+2, icon->pixmap(mIconSize, mIconSize)); // icon + text or text only, or force text if no icon exists for status if (mStatusDisplay == 0 || mStatusDisplay == 2 || !(icon) ) @@ -99,3 +100,21 @@ CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate ( { return new RecordStatusDelegate (undoStack, parent); } + +void CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue) +{ + if (settingName == "Record Status Display") + { + if (settingValue == "Icon and Text") + mStatusDisplay = 0; + + else if (settingValue == "Icon Only") + mStatusDisplay = 1; + + else if (settingValue == "Text Only") + mStatusDisplay = 2; + + else + mStatusDisplay = 0; + } +} diff --git a/apps/opencs/view/world/recordstatusdelegate.hpp b/apps/opencs/view/world/recordstatusdelegate.hpp index 9ab19d30ee..3f53f2f556 100644 --- a/apps/opencs/view/world/recordstatusdelegate.hpp +++ b/apps/opencs/view/world/recordstatusdelegate.hpp @@ -35,12 +35,12 @@ namespace CSVWorld QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const; + void updateEditorSetting (const QString &settingName, const QString &settingValue); + }; class RecordStatusDelegateFactory : public CommandDelegateFactory { - //std::vector > mValues; - public: virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index f9167d2591..1ec0dde09c 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -12,6 +12,7 @@ #include "../../model/world/idtableproxymodel.hpp" #include "../../model/world/idtable.hpp" #include "../../model/world/record.hpp" +#include "recordstatusdelegate.hpp" #include "util.hpp" @@ -80,7 +81,7 @@ std::vector CSVWorld::Table::listDeletableSelectedIds() const CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete) -: mUndoStack (undoStack), mCreateAction (0), mEditLock (false) + : mUndoStack (undoStack), mCreateAction (0), mEditLock (false), mRecordStatusDisplay (0) { mModel = &dynamic_cast (*data.getTableModel (id)); @@ -161,6 +162,7 @@ void CSVWorld::Table::createRecord() mUndoStack.push (new CSMWorld::CreateCommand (*mProxyModel, stream.str())); } + } void CSVWorld::Table::revertRecord() @@ -201,4 +203,13 @@ void CSVWorld::Table::deleteRecord() mUndoStack.endMacro(); } } -} \ No newline at end of file +} + +void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QString &settingValue) +{ + if (settingName == "Record Status Display") + { + dynamic_cast(this->itemDelegateForColumn(1))->updateEditorSetting (settingName, settingValue); + emit dataChanged(mModel->index(0,1), mModel->index(mModel->rowCount()-1, 1)); + } +} diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index df0224583e..348e800cfd 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -34,6 +34,7 @@ namespace CSVWorld CSMWorld::IdTableProxyModel *mProxyModel; CSMWorld::IdTable *mModel; bool mEditLock; + int mRecordStatusDisplay; private: @@ -52,6 +53,8 @@ namespace CSVWorld CSMWorld::UniversalId getUniversalId (int row) const; + void updateEditorSetting (const QString &settingName, const QString &settingValue); + private slots: void createRecord(); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index bb4bb76c61..d139ef74b2 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -22,4 +22,11 @@ void CSVWorld::TableSubView::setEditLock (bool locked) void CSVWorld::TableSubView::rowActivated (const QModelIndex& index) { focusId (mTable->getUniversalId (index.row())); -} \ No newline at end of file +} + +void CSVWorld::TableSubView::updateEditorSetting(const QString &settingName, const QString &settingValue) +{ + + if (settingName == "Record Status Display") + mTable->updateEditorSetting(settingName, settingValue); +} diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 0e7b8aa302..13db8255a7 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -23,8 +23,8 @@ namespace CSVWorld public: TableSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete); - virtual void setEditLock (bool locked); + void updateEditorSetting (const QString &, const QString &); private slots: @@ -32,4 +32,4 @@ namespace CSVWorld }; } -#endif \ No newline at end of file +#endif diff --git a/apps/opencs/view/world/util.hpp b/apps/opencs/view/world/util.hpp index 95dfec6c58..251564e96d 100644 --- a/apps/opencs/view/world/util.hpp +++ b/apps/opencs/view/world/util.hpp @@ -82,6 +82,8 @@ namespace CSVWorld ///< \brief Use commands instead of manipulating the model directly class CommandDelegate : public QStyledItemDelegate { + Q_OBJECT + QUndoStack& mUndoStack; bool mEditLock; @@ -105,6 +107,10 @@ namespace CSVWorld void setEditLock (bool locked); bool isEditLocked() const; + + private slots: + + virtual void slotUpdateEditorSetting (const QString &settingName, const QString &settingValue) {} }; }