From dbd1ab05d3d47754b29e127f1cde300477a9e304 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 21 Sep 2014 20:55:52 +1000 Subject: [PATCH] Integrated into the original settings design, except using tabs rather than list & stacked widgets. Works but visuals need updating. --- apps/opencs/CMakeLists.txt | 1 - apps/opencs/editor.hpp | 4 +- apps/opencs/model/settings/setting.cpp | 13 +- apps/opencs/model/settings/setting.hpp | 5 +- apps/opencs/model/settings/support.hpp | 12 +- apps/opencs/model/settings/usersettings.cpp | 181 ++++++- apps/opencs/view/settings/dialog.cpp | 375 +++++++++++++- apps/opencs/view/settings/dialog.hpp | 30 +- apps/opencs/view/settings/settingsdialog.cpp | 486 ------------------- apps/opencs/view/settings/settingsdialog.hpp | 64 --- apps/opencs/view/settings/settingwindow.cpp | 168 ++++++- apps/opencs/view/settings/settingwindow.hpp | 9 +- files/ui/settingstab.ui | 108 +++-- 13 files changed, 790 insertions(+), 666 deletions(-) delete mode 100644 apps/opencs/view/settings/settingsdialog.cpp delete mode 100644 apps/opencs/view/settings/settingsdialog.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 02a6c25a0..ad04b8a37 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -98,7 +98,6 @@ opencs_units_noqt (view/tools ) opencs_units (view/settings - settingsdialog settingwindow dialog page diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 4ccc61a02..c87e24e77 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -26,7 +26,7 @@ #include "view/doc/filedialog.hpp" #include "view/doc/newgame.hpp" -#include "view/settings/settingsdialog.hpp" +#include "view/settings/dialog.hpp" namespace OgreInit { @@ -46,7 +46,7 @@ namespace CS CSVDoc::ViewManager mViewManager; CSVDoc::StartupDialogue mStartup; CSVDoc::NewGameDialogue mNewGame; - CSVSettings::SettingsDialog mSettings; + CSVSettings::Dialog mSettings; CSVDoc::FileDialog mFileDialog; boost::filesystem::path mLocal; boost::filesystem::path mResources; diff --git a/apps/opencs/model/settings/setting.cpp b/apps/opencs/model/settings/setting.cpp index 2f86d4ff8..9e1b497b1 100644 --- a/apps/opencs/model/settings/setting.cpp +++ b/apps/opencs/model/settings/setting.cpp @@ -2,7 +2,7 @@ #include "support.hpp" CSMSettings::Setting::Setting(SettingType typ, const QString &settingName, - const QString &pageName) + const QString &pageName, const QString §ion) : mIsEditorSetting (false) { buildDefaultSetting(); @@ -17,6 +17,7 @@ CSMSettings::Setting::Setting(SettingType typ, const QString &settingName, setProperty (Property_SettingType, QVariant (settingType).toString()); setProperty (Property_Page, pageName); setProperty (Property_Name, settingName); + setProperty (Property_Section, section); } void CSMSettings::Setting::buildDefaultSetting() @@ -194,6 +195,16 @@ QString CSMSettings::Setting::page() const return property (Property_Page).at(0); } +void CSMSettings::Setting::setSection (const QString &value) +{ + setProperty (Property_Section, value); +} + +QString CSMSettings::Setting::section() const +{ + return property (Property_Section).at(0); +} + void CSMSettings::Setting::setPrefix (const QString &value) { setProperty (Property_Prefix, value); diff --git a/apps/opencs/model/settings/setting.hpp b/apps/opencs/model/settings/setting.hpp index e40302f00..ed897e591 100644 --- a/apps/opencs/model/settings/setting.hpp +++ b/apps/opencs/model/settings/setting.hpp @@ -30,7 +30,7 @@ namespace CSMSettings public: explicit Setting(SettingType typ, const QString &settingName, - const QString &pageName); + const QString &pageName, const QString §ion = QString()); void addProxy (const Setting *setting, const QStringList &vals); void addProxy (const Setting *setting, const QList &list); @@ -80,6 +80,9 @@ namespace CSMSettings void setPage (const QString &value); QString page() const; + void setSection (const QString &value); + QString section() const; + void setPrefix (const QString &value); QString prefix() const; diff --git a/apps/opencs/model/settings/support.hpp b/apps/opencs/model/settings/support.hpp index 229e293b8..40db648dc 100644 --- a/apps/opencs/model/settings/support.hpp +++ b/apps/opencs/model/settings/support.hpp @@ -35,12 +35,13 @@ namespace CSMSettings Property_TickInterval = 19, Property_TicksAbove = 20, Property_TicksBelow = 21, + Property_Section = 22, //Stringlists should always be the last items - Property_DefaultValues = 22, - Property_DeclaredValues = 23, - Property_DefinedValues = 24, - Property_Proxies = 25 + Property_DefaultValues = 23, + Property_DeclaredValues = 24, + Property_DefinedValues = 25, + Property_Proxies = 26 }; ///Basic setting widget types. @@ -106,7 +107,7 @@ namespace CSMSettings "is_multi_line", "widget_width", "view_row", "view_column", "delimiter", "is_serializable","column_span", "row_span", "minimum", "maximum", "special_value_text", "prefix", "suffix", "single_step", "wrapping", - "tick_interval", "ticks_above", "ticks_below", + "tick_interval", "ticks_above", "ticks_below", "section", "defaults", "declarations", "definitions", "proxies" }; @@ -135,6 +136,7 @@ namespace CSMSettings "1", //tick interval "false", //ticks above "true", //ticks below + "", //Section "", //default values "", //declared values "", //defined values diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index b3f17a4ff..664865289 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -32,9 +32,12 @@ namespace boost } /* namespace boost */ #endif /* (BOOST_VERSION <= 104600) */ -CSMSettings::UserSettings *CSMSettings::UserSettings::mUserSettingsInstance = 0; +namespace CSMSettings +{ -CSMSettings::UserSettings::UserSettings (const Files::ConfigurationManager& configurationManager) +UserSettings *UserSettings::mUserSettingsInstance = 0; + +UserSettings::UserSettings (const Files::ConfigurationManager& configurationManager) : mCfgMgr (configurationManager) , mSettingDefinitions(NULL) , mSettingCfgDefinitions(NULL) @@ -48,9 +51,138 @@ CSMSettings::UserSettings::UserSettings (const Files::ConfigurationManager& conf mSettingCfgDefinitions = new QSettings(QSettings::IniFormat, QSettings::UserScope, "", QString(), this); } -void CSMSettings::UserSettings::buildSettingModelDefaults() +/* + * Original Design: + * + * + * QGridLayout QGroupBox + * ^ ^ + * | | + * | 1 | + * SettingLayout......Frame + * ^ ^ QMainWindow + * | | ^ QObject + * / \ | ^ + * / \ | | + * / \ 0..n | | 0..n + * View......Page........SettingWindow......UserSettings......Setting + * ^ 0..n ^ + * | | + * | | + * ListView, | + * TextView, etc | + * | + * | + * QStackedWidget QListWidget.....Dialog + * ^ : + * | : + * | : + * ResizeableStackedWidget..... + * + * + * When a Page is created with a list of Views, the Views are added to the Frame. + * + * Editor ctor + * -> Dialog ctor + * -> SettingWindow ctor + * -> SettingWindow::setModel() + * -> Dialog::setupDialog() + * -> buildPageListWidget + * -> buildStackedWidget + * + * Editor::showSettings() + * -> Dialog::show() + * -> Dialog::buildPages() <-- [first time only] + * -> SettingWindow::createPages() + * -> Page ctor + * -> Page::setupViews() + * -> Page::addView() + * -> Frame::addWidget() + * -> SettingLayout::addWidget() + * -> [add page widgets to the stack] + * + */ +/* + * Modified Design: + * + * +----------------------------------------+ + * |+---------+---------+---------+ | + * || | | | | + * || +----------------------------+| + * || || + * || +--------------------------------+ || + * || | | || + * || | View View | || + * || | View View | || + * || | | || + * || +---- Section -------------------+ || + * || || + * || +--------------------------------+ || + * || | | || + * || | +-------------+ | || + * || | | View/Frame | | || + * || | +-------------+ | || + * || | | || + * || +---- Section -------------------+ || + * || || + * || || + * |+-------------- Page ------------------+| + * +---------- SettingWindow ---------------+ + * + * + * + * QGridLayout QGroupBox + * ^ ^ + * | | + * | 1 | + * SettingLayout......Frame + * ^ ^ QTabWidget + * | | ^ QObject + * / \ | ^ + * / \ | | + * / \ 0..n | | 0..n + * View......Page........SettingWindow......UserSettings......Setting + * ^ 0..n ^ + * | | + * | Ui::TabWidget | + * ListView, ^ | + * TextView, etc | | + * \ | + * \ | + * \ | + * Dialog + * + * + * + * + * + * View/Page is still used to uniquely identify a setting (i.e. Section is for + * visual presentation only). This means all views on a page should be unique + * (as before) + * + * + * Editor ctor + * -> Dialog ctor + * -> SettingWindow ctor + * -> SettingWindow::setModel() + * -> Dialog::setupDialog() <-- [no longer required] + * + * Editor::showSettings() + * -> Dialog::show() + * -> Dialog::buildPages() <-- [first time only] + * -> SettingWindow::createPages() + * -> Page ctor + * -> Page::setupViews() + * -> Page::addView() + * -> Frame::addWidget() + * -> SettingLayout::addWidget() + * -> [add pages to tabs then call showWidgets()] + */ +void UserSettings::buildSettingModelDefaults() { - QString section = "Window Size"; + QString section; + + section = "Window Size"; { Setting *width = createSetting (Type_LineEdit, section, "Width"); Setting *height = createSetting (Type_LineEdit, section, "Height"); @@ -283,12 +415,12 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() } } -CSMSettings::UserSettings::~UserSettings() +UserSettings::~UserSettings() { mUserSettingsInstance = 0; } -void CSMSettings::UserSettings::loadSettings (const QString &fileName) +void UserSettings::loadSettings (const QString &fileName) { QString userFilePath = QString::fromUtf8 (mCfgMgr.getUserConfigPath().string().c_str()); @@ -369,7 +501,7 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName) mSettingDefinitions->setValue("Video/use settings.cfg", "true"); } -QStringList CSMSettings::UserSettings::getOgreRenderers() +QStringList UserSettings::getOgreRenderers() { if(mOgreRenderers.empty()) { @@ -382,7 +514,7 @@ QStringList CSMSettings::UserSettings::getOgreRenderers() return mOgreRenderers; } -QStringList CSMSettings::UserSettings::getOgreOptions(const QString &key, const QString &renderer) +QStringList UserSettings::getOgreOptions(const QString &key, const QString &renderer) { QStringList result; @@ -421,7 +553,7 @@ QStringList CSMSettings::UserSettings::getOgreOptions(const QString &key, const return result; } -QStringList CSMSettings::UserSettings::getShaderLanguageByRenderer(const QString &renderer) +QStringList UserSettings::getShaderLanguageByRenderer(const QString &renderer) { QStringList result; @@ -435,24 +567,22 @@ QStringList CSMSettings::UserSettings::getShaderLanguageByRenderer(const QString return result; } -bool CSMSettings::UserSettings::hasSettingDefinitions - (const QString &viewKey) const +bool UserSettings::hasSettingDefinitions (const QString &viewKey) const { return (mSettingDefinitions->contains (viewKey)); } -void CSMSettings::UserSettings::setDefinitions - (const QString &key, const QStringList &list) +void UserSettings::setDefinitions (const QString &key, const QStringList &list) { mSettingDefinitions->setValue (key, list); } -void CSMSettings::UserSettings::saveDefinitions() const +void UserSettings::saveDefinitions() const { mSettingDefinitions->sync(); } -QString CSMSettings::UserSettings::settingValue (const QString &settingKey) +QString UserSettings::settingValue (const QString &settingKey) { QStringList defs; @@ -480,22 +610,20 @@ QString CSMSettings::UserSettings::settingValue (const QString &settingKey) return defs.at(0); } -CSMSettings::UserSettings& CSMSettings::UserSettings::instance() +UserSettings& UserSettings::instance() { assert(mUserSettingsInstance); return *mUserSettingsInstance; } -void CSMSettings::UserSettings::updateUserSetting(const QString &settingKey, - const QStringList &list) +void UserSettings::updateUserSetting(const QString &settingKey, const QStringList &list) { mSettingDefinitions->setValue (settingKey ,list); emit userSettingUpdated (settingKey, list); } -CSMSettings::Setting *CSMSettings::UserSettings::findSetting - (const QString &pageName, const QString &settingName) +Setting *UserSettings::findSetting (const QString &pageName, const QString &settingName) { foreach (Setting *setting, mSettings) { @@ -508,8 +636,7 @@ CSMSettings::Setting *CSMSettings::UserSettings::findSetting return 0; } -void CSMSettings::UserSettings::removeSetting - (const QString &pageName, const QString &settingName) +void UserSettings::removeSetting (const QString &pageName, const QString &settingName) { if (mSettings.isEmpty()) return; @@ -530,7 +657,7 @@ void CSMSettings::UserSettings::removeSetting } } -CSMSettings::SettingPageMap CSMSettings::UserSettings::settingPageMap() const +SettingPageMap UserSettings::settingPageMap() const { SettingPageMap pageMap; @@ -540,8 +667,8 @@ CSMSettings::SettingPageMap CSMSettings::UserSettings::settingPageMap() const return pageMap; } -CSMSettings::Setting *CSMSettings::UserSettings::createSetting - (CSMSettings::SettingType typ, const QString &page, const QString &name) +Setting *UserSettings::createSetting + (SettingType typ, const QString &page, const QString &name) { //get list of all settings for the current setting name if (findSetting (page, name)) @@ -560,10 +687,12 @@ CSMSettings::Setting *CSMSettings::UserSettings::createSetting return setting; } -QStringList CSMSettings::UserSettings::definitions (const QString &viewKey) const +QStringList UserSettings::definitions (const QString &viewKey) const { if (mSettingDefinitions->contains (viewKey)) return mSettingDefinitions->value (viewKey).toStringList(); return QStringList(); } + +} diff --git a/apps/opencs/view/settings/dialog.cpp b/apps/opencs/view/settings/dialog.cpp index 72a022c9d..e9ae194ce 100644 --- a/apps/opencs/view/settings/dialog.cpp +++ b/apps/opencs/view/settings/dialog.cpp @@ -1,39 +1,233 @@ #include "dialog.hpp" -#include +//#include #include +#include #include -#include -#include +//#include +//#include #include "../../model/settings/usersettings.hpp" #include "page.hpp" -#include +//#include -#include +//#include -#include -#include -#include +//#include +//#include +//#include #include #include -CSVSettings::Dialog::Dialog(QMainWindow *parent) - : mStackedWidget (0), mDebugMode (false), SettingWindow (parent) +#include +#include + +namespace { + +QRect getMaximumResolution() { - setWindowTitle(QString::fromUtf8 ("User Settings")); + QRect max; + int screens = QApplication::desktop()->screenCount(); + for(int i = 0; i < screens; ++i) + { + QRect res = QApplication::desktop()->screenGeometry(i); + if(res.width() > max.width()) + max.setWidth(res.width()); + if(res.height() > max.height()) + max.setHeight(res.height()); + } + return max; +} + +QString getAspect(int x, int y) +{ + int gcd = boost::math::gcd (x, y); + int xaspect = x / gcd; + int yaspect = y / gcd; + // special case: 8 : 5 is usually referred to as 16:10 + if (xaspect == 8 && yaspect == 5) + return QString("16:10"); + + return QString(QString::number(xaspect) + ":" + QString::number(yaspect)); +} + +QString getCurrentOgreResolution() +{ + Ogre::ConfigOptionMap& renderOpt = + Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions(); + Ogre::ConfigOptionMap::iterator it = renderOpt.begin(); + for(; it != renderOpt.end(); ++it) + { + if(it->first == "Video Mode" ) + { + QRegExp re("^(\\d+ x \\d+)"); + if (re.indexIn(it->second.currentValue.c_str(), 0) > -1) + return re.cap(1); + } + } + return QString(); // found nothing +} + +bool customCompare(const QString &s1, const QString &s2) +{ + int x1, x2, y1, y2; + QRegExp re("^(\\d+) x (\\d+)"); + + if(re.indexIn(s1) > -1) + { + x1 = re.cap(1).toInt(); + y1 = re.cap(2).toInt(); + } + if(re.indexIn(s2) > -1) + { + x2 = re.cap(1).toInt(); + y2 = re.cap(2).toInt(); + } + + if(x1 == x2) + return y1 > y2; + else + return x1 > x2; +} + +QStringList getAvailableResolutions() +{ + // store available rendering devices and available resolutions + QStringList result; + + Ogre::ConfigOptionMap& renderOpt = Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions(); + Ogre::ConfigOptionMap::iterator it = renderOpt.begin(); + for(;it != renderOpt.end(); ++it) + { + if(it->first == "Rendering Device" ) + { + if(it->second.possibleValues.empty()) + { + return result; // FIXME: add error message + } + // Store Available Rendering Devices + Ogre::StringVector::iterator iter = it->second.possibleValues.begin(); + for(;iter != it->second.possibleValues.end(); ++iter) + { + std::cout << "rd: " << *iter << std::endl; // FIXME: debug + } + } + if(it->first == "Video Mode" ) + { + if(it->second.possibleValues.empty()) + { + return result; // FIXME: add error message + } + // FIXME: how to default to the current value? + std::cout << "vm current: " << it->second.currentValue << std::endl; // FIXME: debug + // Store Available Resolutions + Ogre::StringVector::iterator iter = it->second.possibleValues.begin(); + for(; iter != it->second.possibleValues.end(); ++iter) + { + // extract x and y values + QRegExp re("^(\\d+) x (\\d+)"); + if(re.indexIn((*iter).c_str(), 0) > -1) + { + QString aspect = getAspect(re.cap(1).toInt(), re.cap(2).toInt()); + QString resolution = re.cap(1) + QString(" x ") + re.cap(2); + if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) { + resolution.append(QObject::tr("\t(Wide ") + aspect + ")"); + + } else if (aspect == QLatin1String("4:3")) { + resolution.append(QObject::tr("\t(Standard 4:3)")); + } + result.append(resolution); + } + } + } + } + result.removeDuplicates(); + qStableSort(result.begin(), result.end(), customCompare); + return result; +} + +} + + +CSVSettings::Dialog::Dialog(QTabWidget *parent) + : /*mStackedWidget (0),*/ mDebugMode (false), SettingWindow (parent) +{ + setObjectName(QString::fromUtf8 ("User Settings")); + + setupUi(this); + + // Set the maximum res we can set in windowed mode + QRect res = getMaximumResolution(); + sbWidth->setMaximum(res.width()); + sbHeight->setMaximum(res.height()); + + connect(cbOverride, SIGNAL(toggled(bool)), this, SLOT(slotOverrideToggled(bool))); + connect(cmbRenderSys, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(slotRendererChanged(const QString&))); + // to update the checkbox on the view menu + connect(cbStatusBar, SIGNAL(toggled(bool)), this, SIGNAL (toggleStatusBar(bool))); setupDialog(); +#if 0 + // FIXME: delete - don't need this for tabs connect (mPageListWidget, SIGNAL (currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*))); +#endif } +void CSVSettings::Dialog::slotRendererChanged(const QString &renderer) +{ + cmbAntiAlias->clear(); + cmbAntiAlias->addItems(model()->getOgreOptions(QString("FSAA"), renderer)); + + cmbShaderLang->clear(); + cmbShaderLang->addItems(model()->getShaderLanguageByRenderer(renderer)); + + if(model()->settingValue("Video/use settings.cfg") == "true") + { + labRenderSys->setEnabled(false); + cmbRenderSys->setEnabled(false); + labAntiAlias->setEnabled(false); + cmbAntiAlias->setEnabled(false); + //cbVsync->setEnabled(false); + labShaderLang->setEnabled(false); + cmbShaderLang->setEnabled(false); + } + else + cbOverride->setChecked(false); +} + +void CSVSettings::Dialog::slotOverrideToggled(bool checked) +{ + if(checked) + { + labRenderSys->setEnabled(false); + cmbRenderSys->setEnabled(false); + labAntiAlias->setEnabled(false); + cmbAntiAlias->setEnabled(false); + //cbVsync->setEnabled(false); + labShaderLang->setEnabled(false); + cmbShaderLang->setEnabled(false); + } + else + { + labRenderSys->setEnabled(true); + cmbRenderSys->setEnabled(true); + labAntiAlias->setEnabled(true); + cmbAntiAlias->setEnabled(true); + //cbVsync->setEnabled(true); + labShaderLang->setEnabled(true); + cmbShaderLang->setEnabled(true); + } +} + +#if 0 +// FIXME: delete - not required for tabs void CSVSettings::Dialog::slotChangePage (QListWidgetItem *cur, QListWidgetItem *prev) { @@ -43,9 +237,11 @@ void CSVSettings::Dialog::slotChangePage layout()->activate(); setFixedSize(minimumSizeHint()); } +#endif void CSVSettings::Dialog::setupDialog() { +#if 0 //create central widget with it's layout and immediate children QWidget *centralWidget = new QGroupBox (this); @@ -56,29 +252,112 @@ void CSVSettings::Dialog::setupDialog() buildPageListWidget (centralWidget); buildStackedWidget (centralWidget); +#endif } void CSVSettings::Dialog::buildPages() { + int index = -1; + + // initialised in the constructor + slotOverrideToggled(cbOverride->isChecked()); + + // Ogre renderer + cmbRenderSys->clear(); + cmbRenderSys->addItems(model()->getOgreRenderers()); + //slotRendererChanged(Ogre::Root::getSingleton().getRenderSystem()->getName().c_str()); + + // antialiasing + QString antialiasing = model()->settingValue("Video/antialiasing"); + index = cmbAntiAlias->findData(antialiasing, Qt::DisplayRole); + if(index != -1) + cmbAntiAlias->setCurrentIndex(index); + + // vsync + //cbVsync->setChecked(model()->settingValue("Video/vsync") == "true"); + cbVsync->setChecked(false); // disable vsync option for now + cbVsync->setEnabled(false); // disable vsync option for now + + // shader lang + QString shaderlang = model()->settingValue("General/shader mode"); + index = cmbShaderLang->findData(shaderlang, Qt::DisplayRole); + if(index != -1) + cmbShaderLang->setCurrentIndex(index); + + if(model()->settingValue("Window Size/Width") != "") + sbWidth->setValue(model()->settingValue("Window Size/Width").toInt()); + + if(model()->settingValue("Window Size/Height") != "") + sbHeight->setValue(model()->settingValue("Window Size/Height").toInt()); + + // update display resolution combo box + cmbStdWinSize->clear(); + cmbStdWinSize->addItems(getAvailableResolutions()); + + QString currRes = model()->settingValue("Window Size/Width") + " x " + + model()->settingValue("Window Size/Height"); + + index = cmbStdWinSize->findData(currRes, Qt::DisplayRole, Qt::MatchStartsWith); + if(index != -1) + { + // show the values in ini file + cmbStdWinSize->setCurrentIndex(index); + //slotStandardToggled(true); + } + else + { + // show what's in Ogre instead + index = cmbStdWinSize->findData(getCurrentOgreResolution(), + Qt::DisplayRole, Qt::MatchStartsWith); + if(index != -1) + cmbStdWinSize->setCurrentIndex(index); + + //rbCustWinSize->setChecked(true); + //slotStandardToggled(false); + } + + // status bar + cbStatusBar->setChecked(model()->settingValue("Display/show statusbar") == "true"); + + // display format + QString recStat = model()->settingValue("Display Format/Record Status Display"); + index = cmbRecStatus->findData(recStat, Qt::DisplayRole); + if(index != -1) + cmbRecStatus->setCurrentIndex(index); + + QString refIdType = model()->settingValue("Display Format/Referenceable ID Type Display"); + index = cmbRefIdType->findData(refIdType, Qt::DisplayRole); + if(index != -1) + cmbRefIdType->setCurrentIndex(index); + SettingWindow::createPages (); - QFontMetrics fm (QApplication::font()); + //QFontMetrics fm (QApplication::font()); foreach (Page *page, SettingWindow::pages()) { QString pageName = page->objectName(); - int textWidth = fm.width(pageName); + //int textWidth = fm.width(pageName); - new QListWidgetItem (pageName, mPageListWidget); - mPageListWidget->setFixedWidth (textWidth + 50); + // each page is added as a tab to Ui::TabWiget + addTab(page, page->objectName()); - mStackedWidget->addWidget (&dynamic_cast(*(page))); + // add section and views to the page + buildTabPage(page); + page->showWidgets(); + + //new QListWidgetItem (pageName, mPageListWidget); + //mPageListWidget->setFixedWidth (textWidth + 50); + + //mStackedWidget->addWidget (&dynamic_cast(*(page))); } - resize (mStackedWidget->sizeHint()); + //resize (mStackedWidget->sizeHint()); } +#if 0 +// FIXME: delete - not required, using tabs instead void CSVSettings::Dialog::buildPageListWidget (QWidget *centralWidget) { mPageListWidget = new QListWidget (centralWidget); @@ -96,6 +375,7 @@ void CSVSettings::Dialog::buildStackedWidget (QWidget *centralWidget) centralWidget->layout()->addWidget (mStackedWidget); } +#endif void CSVSettings::Dialog::closeEvent (QCloseEvent *event) { @@ -103,6 +383,67 @@ void CSVSettings::Dialog::closeEvent (QCloseEvent *event) //model is updated SettingWindow::closeEvent (event); + // override + if(cbOverride->isChecked()) + model()->setDefinitions("Video/use settings.cfg", QStringList("true")); + else + model()->setDefinitions("Video/use settings.cfg", QStringList("false")); + + // render system + model()->setDefinitions("Video/render system", + QStringList(cmbRenderSys->currentText())); + + // vsync + if(cbVsync->isChecked()) + model()->setDefinitions("Video/vsync", QStringList("true")); + else + model()->setDefinitions("Video/vsync", QStringList("false")); + + // antialiasing + model()->setDefinitions("Video/antialiasing", + QStringList(cmbAntiAlias->currentText())); +#if 0 + QRegExp reAA("^\\D*(\\d+)\\D*"); + if(reAA.indexIn(cmbAntiAlias->currentText()) > -1) + model()->setDefinitions("Video/antialiasing", QStringList(reAA.cap(1))); +#endif + + // shader lang + model()->setDefinitions("General/shader mode", + QStringList(cmbShaderLang->currentText().toLower())); + + // window size + if(0) //rbStdWinSize->isChecked()) + { + QRegExp re("^(\\d+) x (\\d+)"); + if(re.indexIn(cmbStdWinSize->currentText()) > -1) + { + model()->setDefinitions("Window Size/Width", QStringList(re.cap(1))); + model()->setDefinitions("Window Size/Height", QStringList(re.cap(2))); + } + //} + //else + //{ + model()->setDefinitions("Window Size/Width", + QStringList(QString::number(sbWidth->value()))); + model()->setDefinitions("Window Size/Height", + QStringList(QString::number(sbHeight->value()))); + } + + // status bar + if(cbStatusBar->isChecked()) + model()->setDefinitions("Display/show statusbar", QStringList("true")); + else + model()->setDefinitions("Display/show statusbar", QStringList("false")); + + // display format + model()->setDefinitions("Display Format/Record Status Display", + QStringList(cmbRecStatus->currentText())); + model()->setDefinitions("Display Format/Referenceable ID Type Display", + QStringList(cmbRefIdType->currentText())); + + std::cout << "closeEvent" << std::endl; + saveSettings(); } diff --git a/apps/opencs/view/settings/dialog.hpp b/apps/opencs/view/settings/dialog.hpp index b0e12c461..c82df8dad 100644 --- a/apps/opencs/view/settings/dialog.hpp +++ b/apps/opencs/view/settings/dialog.hpp @@ -2,28 +2,30 @@ #define CSVSETTINGS_DIALOG_H #include "settingwindow.hpp" -#include "resizeablestackedwidget.hpp" +//#include "resizeablestackedwidget.hpp" #include -class QStackedWidget; -class QListWidget; -class QListWidgetItem; +//class QStackedWidget; +//class QListWidget; +//class QListWidgetItem; + +#include "ui_settingstab.h" namespace CSVSettings { class Page; - class Dialog : public SettingWindow + class Dialog : public SettingWindow, private Ui::TabWidget { Q_OBJECT - QListWidget *mPageListWidget; - ResizeableStackedWidget *mStackedWidget; + //QListWidget *mPageListWidget; + //ResizeableStackedWidget *mStackedWidget; bool mDebugMode; public: - explicit Dialog (QMainWindow *parent = 0); + explicit Dialog (QTabWidget *parent = 0); ///Enables setting debug mode. When the dialog opens, a page is created ///which displays the SettingModel's contents in a Tree view. @@ -39,8 +41,8 @@ namespace CSVSettings { private: void buildPages(); - void buildPageListWidget (QWidget *centralWidget); - void buildStackedWidget (QWidget *centralWidget); + //void buildPageListWidget (QWidget *centralWidget); + //void buildStackedWidget (QWidget *centralWidget); public slots: @@ -48,7 +50,13 @@ namespace CSVSettings { private slots: - void slotChangePage (QListWidgetItem *, QListWidgetItem *); + //void slotChangePage (QListWidgetItem *, QListWidgetItem *); // FIXME: delete + void slotOverrideToggled(bool checked); + void slotRendererChanged(const QString &renderer); + + signals: + + void toggleStatusBar(bool checked); // FIXME: maybe not needed }; } #endif // CSVSETTINGS_DIALOG_H diff --git a/apps/opencs/view/settings/settingsdialog.cpp b/apps/opencs/view/settings/settingsdialog.cpp deleted file mode 100644 index 7d5e5bec5..000000000 --- a/apps/opencs/view/settings/settingsdialog.cpp +++ /dev/null @@ -1,486 +0,0 @@ -#include "settingsdialog.hpp" - -#include -#include - -#include - -#include "../../model/settings/usersettings.hpp" - -namespace -{ -// copied from the launcher & adapted - -QString getAspect(int x, int y) -{ - int gcd = boost::math::gcd (x, y); - int xaspect = x / gcd; - int yaspect = y / gcd; - // special case: 8 : 5 is usually referred to as 16:10 - if (xaspect == 8 && yaspect == 5) - return QString("16:10"); - - return QString(QString::number(xaspect) + ":" + QString::number(yaspect)); -} - -QRect getMaximumResolution() -{ - QRect max; - int screens = QApplication::desktop()->screenCount(); - for(int i = 0; i < screens; ++i) - { - QRect res = QApplication::desktop()->screenGeometry(i); - if(res.width() > max.width()) - max.setWidth(res.width()); - if(res.height() > max.height()) - max.setHeight(res.height()); - } - return max; -} - -QString getCurrentOgreResolution() -{ - Ogre::ConfigOptionMap& renderOpt = - Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions(); - Ogre::ConfigOptionMap::iterator it = renderOpt.begin(); - for(; it != renderOpt.end(); ++it) - { - if(it->first == "Video Mode" ) - { - QRegExp re("^(\\d+ x \\d+)"); - if (re.indexIn(it->second.currentValue.c_str(), 0) > -1) - return re.cap(1); - } - } - return QString(); // found nothing -} - -bool customCompare(const QString &s1, const QString &s2) -{ - int x1, x2, y1, y2; - QRegExp re("^(\\d+) x (\\d+)"); - - if(re.indexIn(s1) > -1) - { - x1 = re.cap(1).toInt(); - y1 = re.cap(2).toInt(); - } - if(re.indexIn(s2) > -1) - { - x2 = re.cap(1).toInt(); - y2 = re.cap(2).toInt(); - } - - if(x1 == x2) - return y1 > y2; - else - return x1 > x2; -} - -QStringList getAvailableResolutions() -{ - // store available rendering devices and available resolutions - QStringList result; - - Ogre::ConfigOptionMap& renderOpt = Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions(); - Ogre::ConfigOptionMap::iterator it = renderOpt.begin(); - for(;it != renderOpt.end(); ++it) - { - if(it->first == "Rendering Device" ) - { - if(it->second.possibleValues.empty()) - { - return result; // FIXME: add error message - } - // Store Available Rendering Devices - Ogre::StringVector::iterator iter = it->second.possibleValues.begin(); - for(;iter != it->second.possibleValues.end(); ++iter) - { - std::cout << "rd: " << *iter << std::endl; // FIXME: debug - } - } - if(it->first == "Video Mode" ) - { - if(it->second.possibleValues.empty()) - { - return result; // FIXME: add error message - } - // FIXME: how to default to the current value? - std::cout << "vm current: " << it->second.currentValue << std::endl; // FIXME: debug - // Store Available Resolutions - Ogre::StringVector::iterator iter = it->second.possibleValues.begin(); - for(; iter != it->second.possibleValues.end(); ++iter) - { - // extract x and y values - QRegExp re("^(\\d+) x (\\d+)"); - if(re.indexIn((*iter).c_str(), 0) > -1) - { - QString aspect = getAspect(re.cap(1).toInt(), re.cap(2).toInt()); - QString resolution = re.cap(1) + QString(" x ") + re.cap(2); - if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) { - resolution.append(QObject::tr("\t(Wide ") + aspect + ")"); - - } else if (aspect == QLatin1String("4:3")) { - resolution.append(QObject::tr("\t(Standard 4:3)")); - } - result.append(resolution); - } - } - } - } - result.removeDuplicates(); - qStableSort(result.begin(), result.end(), customCompare); - return result; -} - -} - -CSVSettings::SettingsDialog::SettingsDialog(QTabWidget *parent) - : QTabWidget (parent) -{ - setObjectName("User Settings"); - - setupUi(this); - - // Set the maximum res we can set in windowed mode - QRect res = getMaximumResolution(); - sbWidth->setMaximum(res.width()); - sbHeight->setMaximum(res.height()); - - // to enable mouse events on disabled widgets - cmbStdWinSize->installEventFilter(this); - sbWidth->installEventFilter(this); - sbHeight->installEventFilter(this); - - connect(cbOverride, SIGNAL(toggled(bool)), this, SLOT(slotOverrideToggled(bool))); - connect(cmbRenderSys, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(slotRendererChanged(const QString&))); - //connect(rbStdWinSize, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool))); - - // to update the checkbox on the view menu - connect(cbStatusBar, SIGNAL(toggled(bool)), this, SIGNAL (toggleStatusBar(bool))); -} - -bool CSVSettings::SettingsDialog::eventFilter(QObject *target, QEvent *event) -{ - QWidget *item = qobject_cast(target); - if (target == cmbStdWinSize) - { - if (!item->isEnabled() && (event->type() == QEvent::MouseButtonRelease)) - { - //rbCustWinSize->setChecked(false); - //rbStdWinSize->setChecked(true); - //slotStandardToggled(true); - - return false; - } - } - else if (target == sbWidth || target == sbHeight) - { - if (!item->isEnabled() && (event->type() == QEvent::MouseButtonPress)) - { - //rbStdWinSize->setChecked(false); - //rbCustWinSize->setChecked(true); - //slotStandardToggled(false); - - return false; - } - } - return QTabWidget::eventFilter(target, event); -} - -void CSVSettings::SettingsDialog::slotRendererChanged(const QString &renderer) -{ - cmbAntiAlias->clear(); - cmbAntiAlias->addItems(mModel->getOgreOptions(QString("FSAA"), renderer)); - - cmbShaderLang->clear(); - cmbShaderLang->addItems(mModel->getShaderLanguageByRenderer(renderer)); - - if(mModel->settingValue("Video/use settings.cfg") == "true") - { - labRenderSys->setEnabled(false); - cmbRenderSys->setEnabled(false); - labAntiAlias->setEnabled(false); - cmbAntiAlias->setEnabled(false); - //cbVsync->setEnabled(false); - labShaderLang->setEnabled(false); - cmbShaderLang->setEnabled(false); - } - else - cbOverride->setChecked(false); -} - -void CSVSettings::SettingsDialog::slotOverrideToggled(bool checked) -{ - if(checked) - { - labRenderSys->setEnabled(false); - cmbRenderSys->setEnabled(false); - labAntiAlias->setEnabled(false); - cmbAntiAlias->setEnabled(false); - //cbVsync->setEnabled(false); - labShaderLang->setEnabled(false); - cmbShaderLang->setEnabled(false); - } - else - { - labRenderSys->setEnabled(true); - cmbRenderSys->setEnabled(true); - labAntiAlias->setEnabled(true); - cmbAntiAlias->setEnabled(true); - //cbVsync->setEnabled(true); - labShaderLang->setEnabled(true); - cmbShaderLang->setEnabled(true); - } -} - -void CSVSettings::SettingsDialog::slotStandardToggled(bool checked) -{ - if (checked) - { - cmbStdWinSize->setEnabled(true); - sbWidth->setEnabled(false); - sbHeight->setEnabled(false); - } - else - { - cmbStdWinSize->setEnabled(false); - sbWidth->setEnabled(true); - sbHeight->setEnabled(true); - } -} - -void CSVSettings::SettingsDialog::setViewValues() -{ - int index = -1; - - // initialised in the constructor - slotOverrideToggled(cbOverride->isChecked()); - - // Ogre renderer - cmbRenderSys->clear(); - cmbRenderSys->addItems(mModel->getOgreRenderers()); - //slotRendererChanged(Ogre::Root::getSingleton().getRenderSystem()->getName().c_str()); - - // antialiasing - QString antialiasing = mModel->settingValue("Video/antialiasing"); - index = cmbAntiAlias->findData(antialiasing, Qt::DisplayRole); - if(index != -1) - cmbAntiAlias->setCurrentIndex(index); - - // vsync - //cbVsync->setChecked(mModel->settingValue("Video/vsync") == "true"); - cbVsync->setChecked(false); // disable vsync option for now - cbVsync->setEnabled(false); // disable vsync option for now - - // shader lang - QString shaderlang = mModel->settingValue("General/shader mode"); - index = cmbShaderLang->findData(shaderlang, Qt::DisplayRole); - if(index != -1) - cmbShaderLang->setCurrentIndex(index); - - if(mModel->settingValue("Window Size/Width") != "") - sbWidth->setValue(mModel->settingValue("Window Size/Width").toInt()); - - if(mModel->settingValue("Window Size/Height") != "") - sbHeight->setValue(mModel->settingValue("Window Size/Height").toInt()); - - // update display resolution combo box - cmbStdWinSize->clear(); - cmbStdWinSize->addItems(getAvailableResolutions()); - - QString currRes = mModel->settingValue("Window Size/Width") + " x " + - mModel->settingValue("Window Size/Height"); - - index = cmbStdWinSize->findData(currRes, Qt::DisplayRole, Qt::MatchStartsWith); - if(index != -1) - { - // show the values in ini file - cmbStdWinSize->setCurrentIndex(index); - slotStandardToggled(true); - } - else - { - // show what's in Ogre instead - index = cmbStdWinSize->findData(getCurrentOgreResolution(), - Qt::DisplayRole, Qt::MatchStartsWith); - if(index != -1) - cmbStdWinSize->setCurrentIndex(index); - - //rbCustWinSize->setChecked(true); - slotStandardToggled(false); - } - - // status bar - cbStatusBar->setChecked(mModel->settingValue("Display/show statusbar") == "true"); - - // display format - QString recStat = mModel->settingValue("Display Format/Record Status Display"); - index = cmbRecStatus->findData(recStat, Qt::DisplayRole); - if(index != -1) - cmbRecStatus->setCurrentIndex(index); - - QString refIdType = mModel->settingValue("Display Format/Referenceable ID Type Display"); - index = cmbRefIdType->findData(refIdType, Qt::DisplayRole); - if(index != -1) - cmbRefIdType->setCurrentIndex(index); -} - -void CSVSettings::SettingsDialog::saveSettings() -{ -#if 0 - //setting the definition in the model automatically syncs with the file - foreach (const Page *page, mPages) - { - foreach (const View *view, page->views()) - { - if (!view->serializable()) - continue; - - mModel->setDefinitions (view->viewKey(), view->selectedValues()); - } - } -#endif - std::cout << "closeEvent" << std::endl; - - // override - if(cbOverride->isChecked()) - mModel->setDefinitions("Video/use settings.cfg", QStringList("true")); - else - mModel->setDefinitions("Video/use settings.cfg", QStringList("false")); - - // render system - mModel->setDefinitions("Video/render system", - QStringList(cmbRenderSys->currentText())); - - // vsync - if(cbVsync->isChecked()) - mModel->setDefinitions("Video/vsync", QStringList("true")); - else - mModel->setDefinitions("Video/vsync", QStringList("false")); - - // antialiasing - mModel->setDefinitions("Video/antialiasing", - QStringList(cmbAntiAlias->currentText())); -#if 0 - QRegExp reAA("^\\D*(\\d+)\\D*"); - if(reAA.indexIn(cmbAntiAlias->currentText()) > -1) - mModel->setDefinitions("Video/antialiasing", QStringList(reAA.cap(1))); -#endif - - // shader lang - mModel->setDefinitions("General/shader mode", - QStringList(cmbShaderLang->currentText().toLower())); - - // window size - if(0) //rbStdWinSize->isChecked()) - { - QRegExp re("^(\\d+) x (\\d+)"); - if(re.indexIn(cmbStdWinSize->currentText()) > -1) - { - mModel->setDefinitions("Window Size/Width", QStringList(re.cap(1))); - mModel->setDefinitions("Window Size/Height", QStringList(re.cap(2))); - } - } - else - { - mModel->setDefinitions("Window Size/Width", - QStringList(QString::number(sbWidth->value()))); - mModel->setDefinitions("Window Size/Height", - QStringList(QString::number(sbHeight->value()))); - } - - // status bar - if(cbStatusBar->isChecked()) - mModel->setDefinitions("Display/show statusbar", QStringList("true")); - else - mModel->setDefinitions("Display/show statusbar", QStringList("false")); - - // display format - mModel->setDefinitions("Display Format/Record Status Display", - QStringList(cmbRecStatus->currentText())); - mModel->setDefinitions("Display Format/Referenceable ID Type Display", - QStringList(cmbRefIdType->currentText())); - - mModel->saveDefinitions(); -} - -void CSVSettings::SettingsDialog::createConnections - (const QList &list) -{ -#if 0 - foreach (const CSMSettings::Setting *setting, list) - { - View *masterView = findView (setting->page(), setting->name()); - - CSMSettings::Connector *connector = - new CSMSettings::Connector (masterView, this); - - connect (masterView, - SIGNAL (viewUpdated(const QString &, const QStringList &)), - connector, - SLOT (slotUpdateSlaves()) - ); - - const CSMSettings::ProxyValueMap &proxyMap = setting->proxyLists(); - - foreach (const QString &key, proxyMap.keys()) - { - QStringList keyPair = key.split('/'); - - if (keyPair.size() != 2) - continue; - - View *slaveView = findView (keyPair.at(0), keyPair.at(1)); - - if (!slaveView) - { - qWarning () << "Unable to create connection for view " - << key; - continue; - } - - QList proxyList = proxyMap.value (key); - connector->addSlaveView (slaveView, proxyList); - - connect (slaveView, - SIGNAL (viewUpdated(const QString &, const QStringList &)), - connector, - SLOT (slotUpdateMaster())); - } - } -#endif -} - -void CSVSettings::SettingsDialog::closeEvent (QCloseEvent *event) -{ - //SettingWindow::closeEvent() must be called first to ensure - //model is updated - //SettingWindow::closeEvent (event); - QApplication::focusWidget()->clearFocus(); - - saveSettings(); -} - -void CSVSettings::SettingsDialog::show() -{ - setViewValues(); - - // place the widget and make it visible - QWidget *currView = QApplication::activeWindow(); - if(currView) - { - // place at the center of the window with focus - QSize size = currView->size(); - move(currView->geometry().x()+(size.width() - frameGeometry().width())/2, - currView->geometry().y()+(size.height() - frameGeometry().height())/2); - } - else - { - // something's gone wrong, place at the center of the screen - QPoint screenCenter = QApplication::desktop()->screenGeometry().center(); - move(screenCenter - QPoint(frameGeometry().width()/2, - frameGeometry().height()/2)); - } - QWidget::show(); -} diff --git a/apps/opencs/view/settings/settingsdialog.hpp b/apps/opencs/view/settings/settingsdialog.hpp deleted file mode 100644 index 3dda0700c..000000000 --- a/apps/opencs/view/settings/settingsdialog.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef CSVSETTINGS_SETTINGSDIALOG_H -#define CSVSETTINGS_SETTINGSDIALOG_H - -#include - -#include "ui_settingstab.h" - -class QListWidgetItem; - -namespace CSMSettings -{ - class Setting; - class UserSettings; -} - -namespace CSVSettings { - - class SettingsDialog : public QTabWidget, private Ui::TabWidget - { - Q_OBJECT - - CSMSettings::UserSettings *mModel; - - public: - - SettingsDialog (QTabWidget *parent = 0); - - ///set the model the view uses (instance of UserSettings) - void setModel (CSMSettings::UserSettings &model) { mModel = &model; } - - protected: - - ///save settings from the GUI to file - void saveSettings(); - - /// Settings are written on close - void closeEvent (QCloseEvent *event); - - bool eventFilter(QObject *target, QEvent *event); - - private: - - ///sets the defined values for the views that have been created - void setViewValues(); - - ///create connections between settings (used for proxy settings) - void createConnections (const QList &list); - - public slots: - - void show(); - - //void slotStandardClicked(); - //void slotCustomClicked(); - void slotRendererChanged(const QString &renderer); - void slotOverrideToggled(bool checked); - void slotStandardToggled(bool checked); - - signals: - - void toggleStatusBar(bool checked); - }; -} -#endif // CSVSETTINGS_SETTINGSDIALOG_H diff --git a/apps/opencs/view/settings/settingwindow.cpp b/apps/opencs/view/settings/settingwindow.cpp index 7cdf2bded..f016f1e3d 100644 --- a/apps/opencs/view/settings/settingwindow.cpp +++ b/apps/opencs/view/settings/settingwindow.cpp @@ -1,15 +1,19 @@ +#include "settingwindow.hpp" + #include +//#include +//#include +//#include #include #include "../../model/settings/setting.hpp" #include "../../model/settings/connector.hpp" #include "../../model/settings/usersettings.hpp" -#include "settingwindow.hpp" #include "page.hpp" #include "view.hpp" -CSVSettings::SettingWindow::SettingWindow(QWidget *parent) - : QMainWindow(parent) +CSVSettings::SettingWindow::SettingWindow(QTabWidget *parent) + : QTabWidget(parent) {} void CSVSettings::SettingWindow::createPages() @@ -19,7 +23,7 @@ void CSVSettings::SettingWindow::createPages() QList connectedSettings; foreach (const QString &pageName, pageMap.keys()) - { + { QList pageSettings = pageMap.value (pageName); mPages.append (new Page (pageName, pageSettings, this)); @@ -37,6 +41,162 @@ void CSVSettings::SettingWindow::createPages() createConnections(connectedSettings); } +void CSVSettings::SettingWindow::buildTabPage(Page* tab) +{ + CSMSettings::SettingPageMap pageMap = mModel->settingPageMap(); + QList pageSettings = pageMap.value (tab->objectName()); + //tab->setupViews(pageSettings); +#if 0 + QFontMetrics fm (QApplication::font()); + //int textWidth = fm.width(pageName); // FIXME: + QString pageName = tab->objectName(); + + std::cout << "pageName: " + pageName.toStdString() << std::endl; // FIXME: + QList settingList = mModel->settingPageMap.value(pageName); + //foreach (View *view, page->views()) + //{ + //std::cout << "view key: " + view->viewKey().toStdString() << std::endl; + //if(!settingList.empty()) + //{ + QGroupBox *section = new QGroupBox(tab); + section->setGeometry(5, 5, this->width()-15, this->height()-15); // FIXME: frame thickness calculation + // FIXME: assume a single grid for now + QGridLayout *gridLayout = new QGridLayout(section); + gridLayout->setObjectName(QString::fromUtf8("gridLayout")); + gridLayout->setContentsMargins(5, 5, 5, 5); + + foreach(CSMSettings::Setting * setting, settingList) + { + // enum ViewType {ViewType_Boolean = 0, + // ViewType_List = 1, + // ViewType_Range = 2, + // ViewType_Text = 3, + // ViewType_Undefined = 4 }; + // enum SettingType {* 0 - 9 - Boolean widgets + // * 10-19 - List widgets + // * 21-29 - Range widgets + // * 31-39 - Text widgets + // * + // * Each range corresponds to a View_Type enum by a factor of 10. + // * + // * Even-numbered values are single-value widgets + // * Odd-numbered values are multi-valued widgets + // + // Type_CheckBox = 0, + // Type_RadioButton = 1, + // Type_ListView = 10, + // Type_ComboBox = 11, + // Type_SpinBox = 21, + // Type_DoubleSpinBox = 23, + // Type_Slider = 25, + // Type_Dial = 27, + // Type_TextArea = 30, + // Type_LineEdit = 31, + // Type_Undefined = 40 }; + // + std::cout << "view type: " + std::to_string(setting->viewType()) << std::endl; + std::cout << "setting type: " + std::to_string(setting->type()) << std::endl; + switch(setting->viewType()) + { + case ViewType_Boolean: + break; + case ViewType_List: + break; + case ViewType_Range: + break; + case ViewType_Text: + break; + default: + std::cerr << "ViewType_Undefined" << std::endl; + } + QLabel *lab = 0; + if(!gridLayout->itemAtPosition(setting->viewRow(), 0)) + { + lab = new QLabel(section); + lab->setText(setting->name()); + int textWidth = fm.width(setting->name()); // FIXME: + lab->setMinimumWidth(std::max(textWidth, this->width()/3)); + } + else + { + lab = dynamic_cast (gridLayout->itemAtPosition(setting->viewRow(), 0)->widget()); + QString oldLabel = lab->text(); + lab->setText(oldLabel + ", " + setting->name()); + } + switch(setting->type()) + { + case CSMSettings::SettingType::Type_RadioButton: + { + int rowNum = gridLayout->rowCount(); + if(!gridLayout->itemAtPosition(setting->viewRow(), 0)) + if(lab) gridLayout->addWidget(lab, rowNum, 0); + //lab->setStyleSheet("background-color:yellow;"); // FIXME: + int colNum = 1; + if(setting->declaredValues().size() > 1) // button group FIXME: try isMultiValue() + { + QButtonGroup * buttonGroup = new QButtonGroup(section); + //buttonGroup->setStyleSheet("background-color:red;"); // FIXME: + //gridLayout->addWidget(buttonGroup, rowNum, 1); + foreach(QString string, setting->declaredValues()) + { + QRadioButton *rb = new QRadioButton(string, section); + //rb->setStyleSheet("background-color:blue;"); // FIXME: + gridLayout->addWidget(rb, rowNum, colNum++); + buttonGroup->addButton(rb); + } + } + else // single radio button + { + std::cout << "default values size: " + std::to_string(setting->declaredValues().size()) << std::endl; + QRadioButton *rb = new QRadioButton(section); + if(rb) rb->setText(setting->declaredValues().at(0)); + gridLayout->addWidget(rb, gridLayout->rowCount(), 1); + } + break; + } + case CSMSettings::SettingType::Type_LineEdit: + { + if(!gridLayout->itemAtPosition(setting->viewRow(), 0)) + if(lab) gridLayout->addWidget(lab, setting->viewRow(), 0); + QLineEdit *item = new QLineEdit(section); + //QLabel *lab = new QLabel(section); + //lab->setText(setting->name()); // FIXME: how to put lables in proper place if many items in the same row + gridLayout->addWidget(item, setting->viewRow(), setting->viewColumn()+1, + setting->rowSpan(), setting->columnSpan()); + item->setText(setting->defaultValues().at(0)); //FIXME: check if empty first? + break; + } + case CSMSettings::SettingType::Type_ComboBox: + { + QComboBox *item = new QComboBox(section); + //QLabel *lab = new QLabel(section); + if(!gridLayout->itemAtPosition(setting->viewRow(), 0)) + if(lab) gridLayout->addWidget(lab, setting->viewRow(), 0); + //lab->setText(setting->name()); + gridLayout->addWidget(item, setting->viewRow(), setting->viewColumn()+1, + setting->rowSpan(), setting->columnSpan()); + item->clear(); + item->addItems(setting->declaredValues()); //FIXME: check if empty first? + break; + } + default: + break; + } + } + section->resize(section->width(), gridLayout->rowCount() * (fm.lineSpacing() + 10)); // 10 is extra line space + //tab->adjustSize(); + //} + //QWidget *item = new QWidget(tab); + //item->setObjectName(QString::fromUtf8("cmbAntiAlias")); + //} + + //new QListWidgetItem (pageName, mPageListWidget); + //mPageListWidget->setFixedWidth (textWidth + 50); + + //mStackedWidget->addWidget (&dynamic_cast(*(page))); +#endif +} + void CSVSettings::SettingWindow::createConnections (const QList &list) { diff --git a/apps/opencs/view/settings/settingwindow.hpp b/apps/opencs/view/settings/settingwindow.hpp index 2266f130d..5ed02681c 100644 --- a/apps/opencs/view/settings/settingwindow.hpp +++ b/apps/opencs/view/settings/settingwindow.hpp @@ -1,7 +1,7 @@ #ifndef CSVSETTINGS_SETTINGWINDOW_HPP #define CSVSETTINGS_SETTINGWINDOW_HPP -#include +#include #include #include "../../model/settings/support.hpp" @@ -18,7 +18,7 @@ namespace CSVSettings { typedef QList PageList; - class SettingWindow : public QMainWindow + class SettingWindow : public QTabWidget { Q_OBJECT @@ -26,7 +26,7 @@ namespace CSVSettings { CSMSettings::UserSettings *mModel; public: - explicit SettingWindow(QWidget *parent = 0); + explicit SettingWindow(QTabWidget *parent = 0); ///retrieve a reference to a view based on it's page and setting name View *findView (const QString &pageName, const QString &setting); @@ -50,6 +50,9 @@ namespace CSVSettings { ///sets the defined values for the views that have been created void setViewValues(); + void buildTabPage(Page* tab); + CSMSettings::UserSettings *model() { return mModel; } + private: ///create connections between settings (used for proxy settings) diff --git a/files/ui/settingstab.ui b/files/ui/settingstab.ui index f5b0e6a5b..3d9a9ed46 100644 --- a/files/ui/settingstab.ui +++ b/files/ui/settingstab.ui @@ -145,7 +145,7 @@ Display Format - + 10 @@ -223,7 +223,7 @@ Subviews - + 21 @@ -291,37 +291,73 @@ Window Size - + + + true + 10 20 171 - 22 + 21 - - - - - - 186 - 16777215 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + + 0 + + + + true + + + + + 0 + 0 + 171 + 22 + + + + + + + + 186 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + false + + + + 0 + 0 + 171 + 22 + + + + @@ -340,27 +376,9 @@ displayGroup_Window displayGroup_DisplayFormat displayGroup_Subviews - layoutWidget2 + displayGroup_WindowSize cbStatusBar - - - Misc Settings - - - - false - - - - 70 - 100 - 69 - 22 - - - -