2014-09-15 21:44:07 +00:00
|
|
|
#include "settingsdialog.hpp"
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
#include <boost/math/common_factor.hpp>
|
2014-09-16 09:50:25 +00:00
|
|
|
#include <OgreRoot.h>
|
|
|
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
#include <components/contentselector/model/naturalsort.hpp>
|
|
|
|
#include "../../model/settings/usersettings.hpp"
|
|
|
|
|
2014-09-16 09:50:25 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
// copied from the launcher & adapted
|
|
|
|
|
2014-09-16 09:50:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
QString getCurrentOgreResolution()
|
2014-09-16 09:50:25 +00:00
|
|
|
{
|
|
|
|
Ogre::ConfigOptionMap& renderOpt =
|
|
|
|
Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions();
|
|
|
|
Ogre::ConfigOptionMap::iterator it = renderOpt.begin();
|
2014-09-16 20:11:41 +00:00
|
|
|
for(; it != renderOpt.end(); ++it)
|
2014-09-16 09:50:25 +00:00
|
|
|
{
|
|
|
|
if(it->first == "Video Mode" )
|
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
QRegExp re("^(\\d+ x \\d+)");
|
2014-09-16 09:50:25 +00:00
|
|
|
int pos = re.indexIn(it->second.currentValue.c_str(), 0);
|
|
|
|
if (pos > -1)
|
2014-09-16 20:11:41 +00:00
|
|
|
return re.cap(1);
|
2014-09-16 09:50:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-16 20:11:41 +00:00
|
|
|
return QString(); // found nothing
|
2014-09-16 09:50:25 +00:00
|
|
|
}
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 09:50:25 +00:00
|
|
|
QStringList getAvailableResolutions()
|
2014-09-15 21:44:07 +00:00
|
|
|
{
|
2014-09-16 09:50:25 +00:00
|
|
|
// 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())
|
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
return result; // FIXME: add error message
|
2014-09-16 09:50:25 +00:00
|
|
|
}
|
|
|
|
// Store Available Rendering Devices
|
|
|
|
std::vector<std::string>::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())
|
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
return result; // FIXME: add error message
|
2014-09-16 09:50:25 +00:00
|
|
|
}
|
|
|
|
// FIXME: how to default to the current value?
|
|
|
|
std::cout << "vm current: " << it->second.currentValue << std::endl; // FIXME: debug
|
|
|
|
// Store Available Resolutions
|
|
|
|
std::vector<std::string>::iterator iter = it->second.possibleValues.begin();
|
2014-09-16 20:11:41 +00:00
|
|
|
for(; iter != it->second.possibleValues.end(); ++iter)
|
2014-09-16 09:50:25 +00:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
QStringList getAvailableOptions(const QString &key)
|
2014-09-16 09:50:25 +00:00
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
QStringList result;
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
Ogre::ConfigOptionMap& renderOpt =
|
|
|
|
Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions();
|
|
|
|
Ogre::ConfigOptionMap::iterator it = renderOpt.begin();
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
uint row = 0;
|
|
|
|
for(; it != renderOpt.end(); ++it, ++row)
|
|
|
|
{
|
|
|
|
Ogre::StringVector::iterator opt_it = it->second.possibleValues.begin();
|
|
|
|
uint idx = 0;
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
for(; opt_it != it->second.possibleValues.end(); ++opt_it, ++idx)
|
|
|
|
{
|
|
|
|
if(strcmp (key.toStdString().c_str(), it->first.c_str()) == 0)
|
|
|
|
{
|
|
|
|
result << ((key == "FSAA") ? QString("MSAA ") : QString(""))
|
|
|
|
+ QString::fromStdString((*opt_it).c_str()).simplified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
// Sort ascending
|
|
|
|
qSort(result.begin(), result.end(), naturalSortLessThanCI);
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
// Replace the zero option with Off
|
|
|
|
int index = result.indexOf("MSAA 0");
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
if(index != -1)
|
|
|
|
result.replace(index, QObject::tr("Off"));
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
2014-09-15 21:44:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
CSVSettings::SettingsDialog::SettingsDialog(QTabWidget *parent)
|
2014-09-17 07:13:21 +00:00
|
|
|
: QTabWidget (parent)
|
2014-09-15 21:44:07 +00:00
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
setObjectName("User Settings");
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
setupUi(this);
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
// Set the maximum res we can set in windowed mode
|
|
|
|
QRect res = getMaximumResolution();
|
|
|
|
spinBox_x->setMaximum(res.width());
|
|
|
|
spinBox_y->setMaximum(res.height());
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
connect(comboBox_rendersystem, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged()));
|
2014-09-16 20:11:41 +00:00
|
|
|
connect(radioButton_standard_res, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool)));
|
2014-09-15 21:44:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
void CSVSettings::SettingsDialog::rendererChanged()
|
2014-09-15 21:44:07 +00:00
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
comboBox_antialiasing->clear();
|
|
|
|
comboBox_antialiasing->addItems(getAvailableOptions(QString("FSAA")));
|
2014-09-15 21:44:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
// FIXME: what to do with updating window size
|
|
|
|
void CSVSettings::SettingsDialog::slotStandardToggled(bool checked)
|
2014-09-15 21:44:07 +00:00
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
if (checked)
|
|
|
|
{
|
|
|
|
comboBox_std_window_size->setEnabled(true);
|
|
|
|
spinBox_x->setEnabled(false);
|
|
|
|
spinBox_y->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
comboBox_std_window_size->setEnabled(false);
|
|
|
|
spinBox_x->setEnabled(true);
|
|
|
|
spinBox_y->setEnabled(true);
|
|
|
|
}
|
2014-09-15 21:44:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:11:41 +00:00
|
|
|
void CSVSettings::SettingsDialog::setViewValues()
|
2014-09-15 21:44:07 +00:00
|
|
|
{
|
2014-09-16 20:11:41 +00:00
|
|
|
//rendererChanged(Ogre::Root::getSingleton().getRenderSystemByName(renderer.toStdString()));
|
|
|
|
rendererChanged(); // setup antialiasing options
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
if(mModel->settingValue("Video/use settings.cfg") == "true")
|
2014-09-16 09:50:25 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
checkBox_override->setChecked(false);
|
2014-09-15 21:44:07 +00:00
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
if(mModel->settingValue("Window Size/Width") != "")
|
|
|
|
spinBox_x->setValue(mModel->settingValue("Window Size/Width").toInt());
|
2014-09-16 20:11:41 +00:00
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
if(mModel->settingValue("Window Size/Height") != "")
|
|
|
|
spinBox_y->setValue(mModel->settingValue("Window Size/Height").toInt());
|
2014-09-16 09:50:25 +00:00
|
|
|
|
|
|
|
// update display resolution combo box
|
|
|
|
comboBox_std_window_size->clear();
|
|
|
|
comboBox_std_window_size->addItems(getAvailableResolutions());
|
2014-09-17 07:13:21 +00:00
|
|
|
|
|
|
|
QString currRes = mModel->settingValue("Window Size/Width") + " x " +
|
|
|
|
mModel->settingValue("Window Size/Height");
|
|
|
|
|
|
|
|
int index = comboBox_std_window_size->findData(currRes,
|
2014-09-16 09:50:25 +00:00
|
|
|
Qt::DisplayRole,
|
|
|
|
Qt::MatchStartsWith);
|
|
|
|
if(index != -1)
|
2014-09-17 07:13:21 +00:00
|
|
|
{
|
|
|
|
// show the values in ini file
|
2014-09-16 09:50:25 +00:00
|
|
|
comboBox_std_window_size->setCurrentIndex(index);
|
2014-09-17 07:13:21 +00:00
|
|
|
slotStandardToggled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// show what's in Ogre instead
|
|
|
|
index = comboBox_std_window_size->findData(getCurrentOgreResolution(),
|
|
|
|
Qt::DisplayRole,
|
|
|
|
Qt::MatchStartsWith);
|
|
|
|
if(index != -1)
|
|
|
|
comboBox_std_window_size->setCurrentIndex(index);
|
|
|
|
|
|
|
|
radioButton_custom_res->setChecked(true);
|
|
|
|
slotStandardToggled(false);
|
|
|
|
}
|
|
|
|
}
|
2014-09-16 09:50:25 +00:00
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
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
|
|
|
|
mModel->saveDefinitions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVSettings::SettingsDialog::createConnections
|
|
|
|
(const QList <CSMSettings::Setting *> &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 <QStringList> proxyList = proxyMap.value (key);
|
|
|
|
connector->addSlaveView (slaveView, proxyList);
|
|
|
|
|
|
|
|
connect (slaveView,
|
|
|
|
SIGNAL (viewUpdated(const QString &, const QStringList &)),
|
|
|
|
connector,
|
|
|
|
SLOT (slotUpdateMaster()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-16 20:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVSettings::SettingsDialog::closeEvent (QCloseEvent *event)
|
|
|
|
{
|
|
|
|
//SettingWindow::closeEvent() must be called first to ensure
|
|
|
|
//model is updated
|
|
|
|
//SettingWindow::closeEvent (event);
|
2014-09-17 07:13:21 +00:00
|
|
|
QApplication::focusWidget()->clearFocus();
|
2014-09-16 20:11:41 +00:00
|
|
|
|
2014-09-17 07:13:21 +00:00
|
|
|
saveSettings();
|
2014-09-16 20:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVSettings::SettingsDialog::show()
|
|
|
|
{
|
|
|
|
setViewValues();
|
|
|
|
|
2014-09-16 09:50:25 +00:00
|
|
|
// 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));
|
|
|
|
}
|
2014-09-15 21:44:07 +00:00
|
|
|
QWidget::show();
|
|
|
|
}
|