diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index be536535e..a58c1a614 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -98,9 +98,7 @@ opencs_units_noqt (view/tools ) opencs_units (view/settings - settingwindow settingsdialog - page view booleanview textview diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 1887629f9..77921a335 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -283,8 +283,10 @@ std::auto_ptr CS::Editor::setupGraphics() #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE params.insert(std::make_pair("macAPI", "cocoa")); #endif + // FIXME: don't apply the fullscreen here, apply to the editor window bool fullscreen = mUserSettings.settingValue("Video/fullscreen").toStdString() == "true" ? true : false; - Ogre::RenderWindow* hiddenWindow = Ogre::Root::getSingleton().createRenderWindow("InactiveHidden", 1, 1, fullscreen, ¶ms); + //Ogre::RenderWindow* hiddenWindow = Ogre::Root::getSingleton().createRenderWindow("InactiveHidden", 1, 1, fullscreen, ¶ms); + Ogre::RenderWindow* hiddenWindow = Ogre::Root::getSingleton().createRenderWindow("InactiveHidden", 1, 1, false, ¶ms); hiddenWindow->setActive(false); sh::OgrePlatform* platform = diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index e655a66a3..cd9bf6a33 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -377,8 +377,9 @@ QString CSMSettings::UserSettings::settingValue (const QString &settingKey) QStringList defs; // check if video settings are overriden - if(settingKey.contains(QRegExp("^\\b(Video)", Qt::CaseInsensitive)) && - mSettingDefinitions->value("Video/use settings.cfg") == "true") + if(settingKey.contains(QRegExp("^Video\\b", Qt::CaseInsensitive)) && + mSettingDefinitions->value("Video/use settings.cfg") == "true" && + settingKey.contains(QRegExp("^Video/\\brender|antialiasing|vsync|fullscreen\\b", Qt::CaseInsensitive))) { if (!mSettingCfgDefinitions->contains (settingKey)) return QString(); diff --git a/apps/opencs/view/settings/settingsdialog.cpp b/apps/opencs/view/settings/settingsdialog.cpp index db7b49a54..973a60e2c 100644 --- a/apps/opencs/view/settings/settingsdialog.cpp +++ b/apps/opencs/view/settings/settingsdialog.cpp @@ -8,6 +8,8 @@ #include "../../model/settings/usersettings.hpp" +//#include "ui_settingstab.h" + #include "page.hpp" #include @@ -20,15 +22,157 @@ #include #include +#include -CSVSettings::SettingsDialog::SettingsDialog(QMainWindow *parent) - : /*mStackedWidget (0),*/ mDebugMode (false), SettingWindow (parent) +#include +#include +//#include +#include + +namespace { - setWindowTitle(QString::fromUtf8 ("User Settings")); +// copied from launcher +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 getCurrentResolution() +{ + QString result; + + 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+)"); + int pos = re.indexIn(it->second.currentValue.c_str(), 0); + if (pos > -1) + { + QString aspect = getAspect(re.cap(1).toInt(), re.cap(2).toInt()); + result = re.cap(1) + QString(" x ") + re.cap(2); + if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) + { + //result.append(QObject::tr("\t(Wide ") + aspect + ")"); + + } + else if (aspect == QLatin1String("4:3")) + { + //result.append(QObject::tr("\t(Standard 4:3)")); + } + } + } + } + return result; +} + +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()) + { + QMessageBox msgBox; + msgBox.setWindowTitle(QObject::tr("Error retrieving rendering device")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(QObject::tr("
Ogre Rendering Device empty<./b>

")); + msgBox.exec(); + return result; + } + //std::cout << "rd current: " << it->second.currentValue << std::endl; // FIXME: debug + // Store Available Rendering Devices + std::vector::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()) + { + QMessageBox msgBox; + msgBox.setWindowTitle(QObject::tr("Error receiving resolutions")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(QObject::tr("
Ogre Video Modes empty.

")); + msgBox.exec(); + return result; + } + // FIXME: how to default to the current value? + std::cout << "vm current: " << it->second.currentValue << std::endl; // FIXME: debug + // Store Available Resolutions + std::vector::iterator iter = it->second.possibleValues.begin(); + for(;iter != it->second.possibleValues.end(); ++iter) + { + // extract x and y values + QRegExp re("^(\\d+) x (\\d+)"); + int pos = re.indexIn((*iter).c_str(), 0); + if (pos > -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(); + return result; +} + +} + +CSVSettings::SettingsDialog::SettingsDialog(QTabWidget *parent) + : /*mStackedWidget (0), mDebugMode (false),*/ QTabWidget (parent) +{ + setObjectName("User Settings"); setupUi(this); - //setupDialog(); + // Set the maximum res we can set in windowed mode + QRect res = getMaximumResolution(); + spinBox_x->setMaximum(res.width()); + spinBox_y->setMaximum(res.height()); //connect (mPageListWidget, //SIGNAL (currentItemChanged(QListWidgetItem*, QListWidgetItem*)), @@ -36,6 +180,7 @@ CSVSettings::SettingsDialog::SettingsDialog(QMainWindow *parent) //SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*))); } +// FIXME: don't need this one, as we don't use pages void CSVSettings::SettingsDialog::slotChangePage (QListWidgetItem *cur, QListWidgetItem *prev) { @@ -46,6 +191,7 @@ void CSVSettings::SettingsDialog::slotChangePage setFixedSize(minimumSizeHint()); } +// FIXME: don't need this one since we use setupUi void CSVSettings::SettingsDialog::setupDialog() { //create central widget with it's layout and immediate children @@ -62,8 +208,8 @@ void CSVSettings::SettingsDialog::setupDialog() void CSVSettings::SettingsDialog::buildPages() { - SettingWindow::createPages (); #if 0 + SettingWindow::createPages (); QFontMetrics fm (QApplication::font()); @@ -117,10 +263,62 @@ void CSVSettings::SettingsDialog::show() //buildPages(); //setViewValues(); } - //if( - QPoint screenCenter = QApplication::desktop()->screenGeometry().center(); + if(CSMSettings::UserSettings::instance().settingValue("Video/use settings.cfg").toStdString() == "true") + { + label_RenderingSubsystem->setEnabled(false); + comboBox_rendersystem->setEnabled(false); + label_Antialiasing->setEnabled(false); + comboBox_antialiasing->setEnabled(false); + checkBox_vsync->setEnabled(false); + label_ShaderLanguage->setEnabled(false); + comboBox_shaderlanguage->setEnabled(false); - move (screenCenter - geometry().center()); + } + else + checkBox_override->setChecked(false); + + if(CSMSettings::UserSettings::instance().settingValue("Video/fullscreen").toStdString() == "true") + { + checkBox_fullscreen->setChecked(true); + + label_Resolution->setEnabled(false); + radioButton_standard_res->setEnabled(false); + radioButton_custom_res->setEnabled(false); + comboBox_std_window_size->setEnabled(false); + spinBox_x->setEnabled(false); + spinBox_y->setEnabled(false); + } + else + { + checkBox_fullscreen->setChecked(false); + } + + // update display resolution combo box + // FIXME: update opencs window size + comboBox_std_window_size->clear(); + comboBox_std_window_size->addItems(getAvailableResolutions()); + int index = comboBox_std_window_size->findData(getCurrentResolution(), + Qt::DisplayRole, + Qt::MatchStartsWith); + if(index != -1) + comboBox_std_window_size->setCurrentIndex(index); + + // 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 index e9bd2d043..2d16efe34 100644 --- a/apps/opencs/view/settings/settingsdialog.hpp +++ b/apps/opencs/view/settings/settingsdialog.hpp @@ -1,7 +1,7 @@ #ifndef CSVSETTINGS_SETTINGSDIALOG_H #define CSVSETTINGS_SETTINGSDIALOG_H -#include "settingwindow.hpp" +//#include "settingwindow.hpp" //#include "resizeablestackedwidget.hpp" #include @@ -11,11 +11,17 @@ //class QListWidget; class QListWidgetItem; +#if 0 +namespace Ui { + class TabWidget; +} +#endif + namespace CSVSettings { //class Page; - class SettingsDialog : public SettingWindow, private Ui::TabWidget + class SettingsDialog : public QTabWidget, private Ui::TabWidget { Q_OBJECT @@ -25,7 +31,7 @@ namespace CSVSettings { public: - /*explicit*/ SettingsDialog (QMainWindow *parent = 0); + /*explicit*/ SettingsDialog (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. diff --git a/apps/opencs/view/settings/settingwindow.cpp b/apps/opencs/view/settings/settingwindow.cpp index c70418553..7cdf2bded 100644 --- a/apps/opencs/view/settings/settingwindow.cpp +++ b/apps/opencs/view/settings/settingwindow.cpp @@ -9,7 +9,7 @@ #include "view.hpp" CSVSettings::SettingWindow::SettingWindow(QWidget *parent) - : QTabWidget(parent) + : QMainWindow(parent) {} void CSVSettings::SettingWindow::createPages() diff --git a/apps/opencs/view/settings/settingwindow.hpp b/apps/opencs/view/settings/settingwindow.hpp index b1f55d67f..2266f130d 100644 --- a/apps/opencs/view/settings/settingwindow.hpp +++ b/apps/opencs/view/settings/settingwindow.hpp @@ -18,7 +18,7 @@ namespace CSVSettings { typedef QList PageList; - class SettingWindow : public QTabWidget + class SettingWindow : public QMainWindow { Q_OBJECT diff --git a/files/ui/settingstab.ui b/files/ui/settingstab.ui index 620e8d0c5..b75db685f 100644 --- a/files/ui/settingstab.ui +++ b/files/ui/settingstab.ui @@ -7,7 +7,7 @@ 0 0 400 - 300 + 313 @@ -24,13 +24,13 @@ 20 - 181 + 188 351 - 71 + 81 - + Standard: @@ -43,7 +43,7 @@ - + Resolution @@ -57,7 +57,7 @@ - + Custom; @@ -67,17 +67,7 @@ - - - - - 180 - 0 - - - - - + @@ -87,9 +77,32 @@ - + + + + + + 180 + 0 + + + + + + + + + 16777215 + 2 + + + + Qt::Horizontal + + + @@ -98,7 +111,7 @@ 10 8 371 - 153 + 156 @@ -109,9 +122,9 @@ 10 - 165 + 170 371 - 99 + 108 @@ -121,21 +134,15 @@ - 21 + 20 26 351 - 125 + 129 - - - 0 - 22 - - Use Render System Settings from OpenMW @@ -144,14 +151,14 @@ - + Rendering Subsystem - + false @@ -168,21 +175,42 @@ - - - - Vertical Sync - - - - + Antialiasing - + + + + Vertical Sync + + + + + + + Shader Language + + + + + + + + HLSL + + + + + CG + + + + + @@ -211,25 +239,20 @@ - - - - Shader Language + + + + + 16777215 + 2 + + + + color: rgb(215, 215, 215); + + + Qt::Horizontal - - - - - - - HLSL - - - - - CG - -