From 2db6e4f4cf3bb271faa1cf43d85580cf6591a2fd Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Fri, 29 Jun 2012 19:13:12 +0200 Subject: [PATCH] Second try: added aspect ratios to the resolution combobox --- apps/launcher/graphicspage.cpp | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index b202b1ecf3..fb798fee89 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1,11 +1,25 @@ #include +#include + #include #include #include "graphicspage.hpp" #include "naturalsort.hpp" +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)); +} + GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) , mCfgMgr(cfg) @@ -163,7 +177,7 @@ void GraphicsPage::readConfig() QString resolution = QString::number(Settings::Manager::getInt("resolution x", "Video")); resolution.append(" x " + QString::number(Settings::Manager::getInt("resolution y", "Video"))); - int resIndex = mResolutionComboBox->findText(resolution); + int resIndex = mResolutionComboBox->findText(resolution, Qt::MatchStartsWith); if (resIndex != -1) mResolutionComboBox->setCurrentIndex(resIndex); } @@ -175,8 +189,8 @@ void GraphicsPage::writeConfig() Settings::Manager::setString("antialiasing", "Video", mAntiAliasingComboBox->currentText().toStdString()); Settings::Manager::setString("render system", "Video", mRendererComboBox->currentText().toStdString()); - // parse resolution x and y from a string like "800 x 600" - QString resolution = mResolutionComboBox->currentText(); + // Get the current resolution, but with the tabs replaced with a single space + QString resolution = mResolutionComboBox->currentText().simplified(); QStringList tokens = resolution.split(" ", QString::SkipEmptyParts); int resX = tokens.at(0).toInt(); @@ -235,22 +249,31 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) Ogre::StringVector::iterator opt_it; uint idx = 0; + for (opt_it = i->second.possibleValues.begin (); - opt_it != i->second.possibleValues.end (); opt_it++, idx++) + opt_it != i->second.possibleValues.end (); opt_it++, idx++) { QString qval = QString::fromStdString(*opt_it).simplified(); // remove extra tokens after the resolution (for example bpp, can be there or not depending on rendersystem) QStringList tokens = qval.split(" ", QString::SkipEmptyParts); assert (tokens.size() >= 3); QString resolutionStr = tokens.at(0) + QString(" x ") + tokens.at(2); - { - // do not add duplicate resolutions - if (!result.contains(resolutionStr)) - result << resolutionStr; + // do not add duplicate resolutions + if (!result.contains(resolutionStr)) { + + QString aspect = getAspect(tokens.at(0).toInt(),tokens.at(2).toInt()); + + if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) { + resolutionStr.append(tr("\t(Widescreen ") + aspect + ")"); + + } else if (aspect == QLatin1String("4:3")) { + resolutionStr.append(tr("\t(Standard 4:3)")); + } + + result << resolutionStr; } } - } // Sort the resolutions in descending order