2013-02-25 21:22:07 +01:00
|
|
|
#include "graphicspage.hpp"
|
|
|
|
|
2013-03-12 01:29:13 +01:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QDir>
|
2013-09-01 23:17:41 +04:00
|
|
|
|
2013-11-10 20:58:57 +04:00
|
|
|
#ifdef MAC_OS_X_VERSION_MIN_REQUIRED
|
|
|
|
#undef MAC_OS_X_VERSION_MIN_REQUIRED
|
2013-09-01 23:17:41 +04:00
|
|
|
// We need to do this because of Qt: https://bugreports.qt-project.org/browse/QTBUG-22154
|
|
|
|
#define MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
|
2013-11-10 20:58:57 +04:00
|
|
|
#endif // MAC_OS_X_VERSION_MIN_REQUIRED
|
|
|
|
|
2015-01-31 23:27:34 +01:00
|
|
|
#include <SDL_video.h>
|
2011-04-24 21:42:56 +02:00
|
|
|
|
2012-06-29 19:13:12 +02:00
|
|
|
#include <boost/math/common_factor.hpp>
|
|
|
|
|
2012-01-21 01:14:35 +01:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
2011-05-02 22:21:42 +02:00
|
|
|
|
2013-09-21 23:06:29 -05:00
|
|
|
#include <components/contentselector/model/naturalsort.hpp>
|
2012-10-12 02:25:14 +02:00
|
|
|
|
2013-02-15 15:21:14 +01:00
|
|
|
#include "settings/graphicssettings.hpp"
|
2012-06-26 02:41:54 +02:00
|
|
|
|
2012-06-29 19:13:12 +02: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));
|
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
Launcher::GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSetting, QWidget *parent)
|
2015-04-30 19:24:27 -05:00
|
|
|
: QWidget(parent)
|
2014-10-10 23:47:27 +02:00
|
|
|
, mCfgMgr(cfg)
|
2013-01-27 16:39:51 +01:00
|
|
|
, mGraphicsSettings(graphicsSetting)
|
2011-05-02 22:21:42 +02:00
|
|
|
{
|
2013-10-06 21:13:47 -05:00
|
|
|
setObjectName ("GraphicsPage");
|
2013-03-05 02:17:28 +01:00
|
|
|
setupUi(this);
|
2011-05-11 01:12:25 +02:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
// Set the maximum res we can set in windowed mode
|
2013-06-22 19:15:13 +02:00
|
|
|
QRect res = getMaximumResolution();
|
2013-03-05 02:17:28 +01:00
|
|
|
customWidthSpinBox->setMaximum(res.width());
|
|
|
|
customHeightSpinBox->setMaximum(res.height());
|
2011-05-11 01:12:25 +02:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int)));
|
|
|
|
connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool)));
|
2013-06-23 21:56:27 +02:00
|
|
|
connect(screenComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(screenChanged(int)));
|
2011-05-11 01:12:25 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
bool Launcher::GraphicsPage::setupSDL()
|
2011-05-11 01:12:25 +02:00
|
|
|
{
|
2013-06-23 20:45:24 +02:00
|
|
|
int displays = SDL_GetNumVideoDisplays();
|
2013-06-23 03:49:30 +02:00
|
|
|
|
2013-06-23 20:53:50 +02:00
|
|
|
if (displays < 0)
|
2013-06-23 03:49:30 +02:00
|
|
|
{
|
2013-06-23 21:16:51 +02:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Error receiving number of screens"));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2015-02-06 18:05:02 +01:00
|
|
|
msgBox.setText(tr("<br><b>SDL_GetNumDisplayModes failed:</b><br><br>") + QString::fromUtf8(SDL_GetError()) + "<br>");
|
2013-06-23 21:16:51 +02:00
|
|
|
msgBox.exec();
|
2013-06-23 03:49:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-19 13:19:02 +01:00
|
|
|
screenComboBox->clear();
|
2013-06-23 20:45:24 +02:00
|
|
|
for (int i = 0; i < displays; i++)
|
2013-06-23 03:49:30 +02:00
|
|
|
{
|
2013-06-23 21:56:27 +02:00
|
|
|
screenComboBox->addItem(QString(tr("Screen ")) + QString::number(i + 1));
|
2013-06-23 03:49:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
bool Launcher::GraphicsPage::loadSettings()
|
2013-06-23 03:49:30 +02:00
|
|
|
{
|
|
|
|
if (!setupSDL())
|
|
|
|
return false;
|
|
|
|
|
2013-01-27 16:39:51 +01:00
|
|
|
if (mGraphicsSettings.value(QString("Video/vsync")) == QLatin1String("true"))
|
2013-03-05 02:17:28 +01:00
|
|
|
vSyncCheckBox->setCheckState(Qt::Checked);
|
2011-06-26 23:35:23 +02:00
|
|
|
|
2013-02-25 21:22:07 +01:00
|
|
|
if (mGraphicsSettings.value(QString("Video/fullscreen")) == QLatin1String("true"))
|
2013-03-05 02:17:28 +01:00
|
|
|
fullScreenCheckBox->setCheckState(Qt::Checked);
|
2011-05-11 01:12:25 +02:00
|
|
|
|
2014-12-24 15:09:50 +01:00
|
|
|
if (mGraphicsSettings.value(QString("Video/window border")) == QLatin1String("true"))
|
|
|
|
windowBorderCheckBox->setCheckState(Qt::Checked);
|
2014-12-22 02:44:20 +01:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
int aaIndex = antiAliasingComboBox->findText(mGraphicsSettings.value(QString("Video/antialiasing")));
|
2013-02-25 21:22:07 +01:00
|
|
|
if (aaIndex != -1)
|
2013-03-05 02:17:28 +01:00
|
|
|
antiAliasingComboBox->setCurrentIndex(aaIndex);
|
2011-05-11 01:12:25 +02:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
QString width = mGraphicsSettings.value(QString("Video/resolution x"));
|
|
|
|
QString height = mGraphicsSettings.value(QString("Video/resolution y"));
|
|
|
|
QString resolution = width + QString(" x ") + height;
|
2013-06-23 03:49:30 +02:00
|
|
|
QString screen = mGraphicsSettings.value(QString("Video/screen"));
|
|
|
|
|
2013-06-23 21:56:27 +02:00
|
|
|
screenComboBox->setCurrentIndex(screen.toInt());
|
2012-06-26 15:37:40 +02:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith);
|
2013-02-25 00:56:04 +01:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
if (resIndex != -1) {
|
|
|
|
standardRadioButton->toggle();
|
|
|
|
resolutionComboBox->setCurrentIndex(resIndex);
|
|
|
|
} else {
|
|
|
|
customRadioButton->toggle();
|
|
|
|
customWidthSpinBox->setValue(width.toInt());
|
|
|
|
customHeightSpinBox->setValue(height.toInt());
|
|
|
|
|
|
|
|
}
|
2013-06-23 03:49:30 +02:00
|
|
|
|
|
|
|
return true;
|
2011-05-11 01:12:25 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
void Launcher::GraphicsPage::saveSettings()
|
2011-05-11 01:12:25 +02:00
|
|
|
{
|
2013-03-05 02:17:28 +01:00
|
|
|
vSyncCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/vsync"), QString("true"))
|
2013-01-27 16:39:51 +01:00
|
|
|
: mGraphicsSettings.setValue(QString("Video/vsync"), QString("false"));
|
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
fullScreenCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/fullscreen"), QString("true"))
|
2013-01-27 16:39:51 +01:00
|
|
|
: mGraphicsSettings.setValue(QString("Video/fullscreen"), QString("false"));
|
|
|
|
|
2014-12-24 15:09:50 +01:00
|
|
|
windowBorderCheckBox->checkState() ? mGraphicsSettings.setValue(QString("Video/window border"), QString("true"))
|
|
|
|
: mGraphicsSettings.setValue(QString("Video/window border"), QString("false"));
|
2014-12-22 02:44:20 +01:00
|
|
|
|
2013-03-05 02:17:28 +01:00
|
|
|
mGraphicsSettings.setValue(QString("Video/antialiasing"), antiAliasingComboBox->currentText());
|
2013-01-27 16:39:51 +01:00
|
|
|
|
|
|
|
|
2013-03-06 01:35:32 +01:00
|
|
|
if (standardRadioButton->isChecked()) {
|
|
|
|
QRegExp resolutionRe(QString("(\\d+) x (\\d+).*"));
|
|
|
|
|
|
|
|
if (resolutionRe.exactMatch(resolutionComboBox->currentText().simplified())) {
|
|
|
|
mGraphicsSettings.setValue(QString("Video/resolution x"), resolutionRe.cap(1));
|
|
|
|
mGraphicsSettings.setValue(QString("Video/resolution y"), resolutionRe.cap(2));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mGraphicsSettings.setValue(QString("Video/resolution x"), QString::number(customWidthSpinBox->value()));
|
|
|
|
mGraphicsSettings.setValue(QString("Video/resolution y"), QString::number(customHeightSpinBox->value()));
|
2013-01-27 16:39:51 +01:00
|
|
|
}
|
2013-06-23 03:49:30 +02:00
|
|
|
|
2013-06-23 21:56:27 +02:00
|
|
|
mGraphicsSettings.setValue(QString("Video/screen"), QString::number(screenComboBox->currentIndex()));
|
2011-05-11 01:12:25 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)
|
2012-06-19 15:57:58 +02:00
|
|
|
{
|
|
|
|
QStringList result;
|
2013-06-23 20:45:24 +02:00
|
|
|
SDL_DisplayMode mode;
|
|
|
|
int modeIndex, modes = SDL_GetNumDisplayModes(screen);
|
|
|
|
|
2013-06-23 20:53:50 +02:00
|
|
|
if (modes < 0)
|
2013-06-23 20:45:24 +02:00
|
|
|
{
|
2013-06-23 21:16:51 +02:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Error receiving resolutions"));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2015-02-06 18:05:02 +01:00
|
|
|
msgBox.setText(tr("<br><b>SDL_GetNumDisplayModes failed:</b><br><br>") + QString::fromUtf8(SDL_GetError()) + "<br>");
|
2013-06-23 21:16:51 +02:00
|
|
|
msgBox.exec();
|
2013-06-23 20:45:24 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (modeIndex = 0; modeIndex < modes; modeIndex++)
|
2012-06-19 15:57:58 +02:00
|
|
|
{
|
2013-06-23 20:45:24 +02:00
|
|
|
if (SDL_GetDisplayMode(screen, modeIndex, &mode) < 0)
|
|
|
|
{
|
2013-06-23 21:16:51 +02:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Error receiving resolutions"));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2015-02-06 18:05:02 +01:00
|
|
|
msgBox.setText(tr("<br><b>SDL_GetDisplayMode failed:</b><br><br>") + QString::fromUtf8(SDL_GetError()) + "<br>");
|
2013-06-23 21:16:51 +02:00
|
|
|
msgBox.exec();
|
2013-06-23 20:45:24 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-23 03:49:30 +02:00
|
|
|
QString aspect = getAspect(mode.w, mode.h);
|
|
|
|
QString resolution = QString::number(mode.w) + QString(" x ") + QString::number(mode.h);
|
2012-06-19 16:02:28 +02:00
|
|
|
|
2013-06-23 03:49:30 +02:00
|
|
|
if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) {
|
|
|
|
resolution.append(tr("\t(Wide ") + aspect + ")");
|
2012-06-29 19:13:12 +02:00
|
|
|
|
2013-06-23 03:49:30 +02:00
|
|
|
} else if (aspect == QLatin1String("4:3")) {
|
|
|
|
resolution.append(tr("\t(Standard 4:3)"));
|
2012-06-19 15:57:58 +02:00
|
|
|
}
|
2012-06-26 15:37:40 +02:00
|
|
|
|
2013-06-23 03:49:30 +02:00
|
|
|
result.append(resolution);
|
|
|
|
}
|
2013-06-23 20:45:24 +02:00
|
|
|
|
2013-06-23 21:04:49 +02:00
|
|
|
result.removeDuplicates();
|
2012-06-19 15:57:58 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
QRect Launcher::GraphicsPage::getMaximumResolution()
|
2013-06-22 19:15:13 +02:00
|
|
|
{
|
2013-06-22 20:32:11 +02:00
|
|
|
QRect max;
|
|
|
|
int screens = QApplication::desktop()->screenCount();
|
|
|
|
for (int i = 0; i < screens; ++i)
|
2013-06-22 19:15:13 +02:00
|
|
|
{
|
2013-06-22 20:32:11 +02:00
|
|
|
QRect res = QApplication::desktop()->screenGeometry(i);
|
2013-06-22 19:15:13 +02:00
|
|
|
if (res.width() > max.width())
|
|
|
|
max.setWidth(res.width());
|
|
|
|
if (res.height() > max.height())
|
|
|
|
max.setHeight(res.height());
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
void Launcher::GraphicsPage::screenChanged(int screen)
|
2013-06-23 03:49:30 +02:00
|
|
|
{
|
2013-06-23 21:56:27 +02:00
|
|
|
if (screen >= 0) {
|
2013-06-23 03:49:30 +02:00
|
|
|
resolutionComboBox->clear();
|
2013-06-23 21:56:27 +02:00
|
|
|
resolutionComboBox->addItems(getAvailableResolutions(screen));
|
2013-06-23 03:49:30 +02:00
|
|
|
}
|
2013-03-05 02:17:28 +01:00
|
|
|
}
|
2011-05-02 22:21:42 +02:00
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
void Launcher::GraphicsPage::slotFullScreenChanged(int state)
|
2013-03-05 02:17:28 +01:00
|
|
|
{
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
standardRadioButton->toggle();
|
|
|
|
customRadioButton->setEnabled(false);
|
|
|
|
customWidthSpinBox->setEnabled(false);
|
|
|
|
customHeightSpinBox->setEnabled(false);
|
2014-12-24 15:09:50 +01:00
|
|
|
windowBorderCheckBox->setEnabled(false);
|
2013-03-05 02:17:28 +01:00
|
|
|
} else {
|
|
|
|
customRadioButton->setEnabled(true);
|
|
|
|
customWidthSpinBox->setEnabled(true);
|
|
|
|
customHeightSpinBox->setEnabled(true);
|
2014-12-24 15:09:50 +01:00
|
|
|
windowBorderCheckBox->setEnabled(true);
|
2013-03-05 02:17:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 11:17:26 -05:00
|
|
|
void Launcher::GraphicsPage::slotStandardToggled(bool checked)
|
2013-03-05 02:17:28 +01:00
|
|
|
{
|
|
|
|
if (checked) {
|
|
|
|
resolutionComboBox->setEnabled(true);
|
|
|
|
customWidthSpinBox->setEnabled(false);
|
|
|
|
customHeightSpinBox->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
resolutionComboBox->setEnabled(false);
|
|
|
|
customWidthSpinBox->setEnabled(true);
|
|
|
|
customHeightSpinBox->setEnabled(true);
|
|
|
|
}
|
2011-09-02 20:01:24 +02:00
|
|
|
}
|