From 8a231f0b0b70e66e6c348b049560c7db9b2e103d Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 12:21:42 +1000 Subject: [PATCH 1/8] Save Quake 3 path to settings on Windows. QSettings is wrapped to keep error-prone stringly typed code in one place (QSettings uses string keys). --- launch.pro | 6 ++++-- mainwindow.cpp | 27 ++++++++++++++++++++++++--- mainwindow.h | 5 ++--- settings.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ settings.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 settings.cpp create mode 100644 settings.h diff --git a/launch.pro b/launch.pro index 502ce84..59f0d32 100644 --- a/launch.pro +++ b/launch.pro @@ -13,9 +13,11 @@ TEMPLATE = app SOURCES += main.cpp\ - mainwindow.cpp + mainwindow.cpp \ + settings.cpp -HEADERS += mainwindow.h +HEADERS += mainwindow.h \ + settings.h FORMS += mainwindow.ui diff --git a/mainwindow.cpp b/mainwindow.cpp index 17ccca3..e5f4c8c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,14 +20,35 @@ ioLaunch::~ioLaunch() void ioLaunch::on_btnLaunch_clicked() { + QString ioq3; + #ifdef Q_OS_WIN32 - if(ioq3 == NULL) + // Prompt the user to set the ioq3 path if the settings value either doesn't exist or is invalid. + bool promptForPath = true; + + if (settings.containsQuakePath()) + { + const QString path = settings.getQuakePath(); + const QDir dir(path); + + if (!path.isEmpty() && dir.exists()) + promptForPath = false; + } + + if(promptForPath) { msg.setText("Please select your Quake3 directory"); msg.exec(); - QString path = QFileDialog::getExistingDirectory (this, tr("Directory"), directory.path()); - ioq3 = QString("\"") + path + QDir::separator() + "ioquake3.x86.exe\" +set r_mode -1"; + + const QString path = QFileDialog::getExistingDirectory (this, tr("Directory")); + + if (path.isEmpty()) + return; + + settings.setQuakePath(path); } + + ioq3 = QString("\"") + settings.getQuakePath() + QDir::separator() + "ioquake3.x86.exe\" +set r_mode -1"; #elif defined Q_OS_MAC ioq3 = "open -a ioquake3 --args +set r_mode -1"; #elif defined Q_OS_UNIX diff --git a/mainwindow.h b/mainwindow.h index 5d1bc8a..ad924d6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,6 +8,7 @@ #include #include #include +#include "settings.h" namespace Ui { class ioLaunch; @@ -41,17 +42,15 @@ private slots: private: Ui::ioLaunch *ui; - QString ioq3; QString resOption; QString screenOption; QMessageBox msg; QMessageBox ioq3Failed; - QDir directory; int ioWidth; int ioHeight; bool ioWedited; bool ioHedited; - + Settings settings; }; #endif // MAINWINDOW_H diff --git a/settings.cpp b/settings.cpp new file mode 100644 index 0000000..c91f20f --- /dev/null +++ b/settings.cpp @@ -0,0 +1,44 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 The ioquake Group + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#include +#include "settings.h" + +Settings::Settings() : + settings("ioquake", "launch") +{ +} + +QString Settings::getQuakePath() const +{ + return settings.value("quakePath").toString(); +} + +bool Settings::containsQuakePath() const +{ + return settings.contains("quakePath"); +} + +void Settings::setQuakePath(const QString &path) +{ + settings.setValue("quakePath", path); +} diff --git a/settings.h b/settings.h new file mode 100644 index 0000000..7a6099c --- /dev/null +++ b/settings.h @@ -0,0 +1,43 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 The ioquake Group + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include + +class QString; + +class Settings +{ +public: + Settings(); + + QString getQuakePath() const; + bool containsQuakePath() const; + void setQuakePath(const QString &path); + +private: + QSettings settings; +}; + +#endif // SETTINGS_H From 701ddd5c10fc7a9ff7855dbdb798d00aa86bec22 Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 12:56:11 +1000 Subject: [PATCH 2/8] Calculate the ioquake3 home path on startup. --- mainwindow.cpp | 28 +++++++++++++++++++++++++++- mainwindow.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e5f4c8c..74da1ab 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,4 +1,12 @@ +#include #include + +#ifdef Q_OS_WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#include +#endif + #include "mainwindow.h" #include "ui_mainwindow.h" @@ -11,6 +19,24 @@ ioLaunch::ioLaunch(QWidget *parent) : resOption = ""; screenOption = ""; + // Calculate ioquake3 home path. +#ifdef Q_OS_WIN32 + wchar_t path[MAX_PATH]; + + if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path))) + { + homePath = QString::fromWCharArray(path) + "/Quake3"; + } +#elif defined(Q_OS_MAC) || defined(Q_OS_UNIX) + const QByteArray homeEnvRaw = qgetenv("HOME"); + const QString homeEnv(homeEnvRaw.constData()); + + #if defined Q_OS_MAC + homePath = homeEnv + "/Library/Application Support/Quake3"; + #elif defined Q_OS_UNIX + homePath = homeEnv + "/.q3a"; + #endif +#endif } ioLaunch::~ioLaunch() @@ -48,7 +74,7 @@ void ioLaunch::on_btnLaunch_clicked() settings.setQuakePath(path); } - ioq3 = QString("\"") + settings.getQuakePath() + QDir::separator() + "ioquake3.x86.exe\" +set r_mode -1"; + ioq3 = QString("\"") + settings.getQuakePath() + "/ioquake3.x86.exe\" +set r_mode -1"; #elif defined Q_OS_MAC ioq3 = "open -a ioquake3 --args +set r_mode -1"; #elif defined Q_OS_UNIX diff --git a/mainwindow.h b/mainwindow.h index ad924d6..1eacc7d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,6 +51,7 @@ private: bool ioWedited; bool ioHedited; Settings settings; + QString homePath; }; #endif // MAINWINDOW_H From 6686a5579fd908d6eb061a214e452ebc9172c358 Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 15:17:33 +1000 Subject: [PATCH 3/8] Parse q3config.cfg in the home directory when first run to get setting defaults. --- mainwindow.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 2 + settings.cpp | 10 +++++ settings.h | 3 ++ 4 files changed, 126 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index 74da1ab..2fbce5a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,5 +1,6 @@ #include #include +#include #ifdef Q_OS_WIN32 #define WIN32_LEAN_AND_MEAN @@ -37,6 +38,16 @@ ioLaunch::ioLaunch(QWidget *parent) : homePath = homeEnv + "/.q3a"; #endif #endif + + QDir homeDir(homePath); + + // Try to parse q3config.cfg to get default settings if this is the first time the program has run. + if (!homePath.isEmpty() && homeDir.exists() && !settings.getHaveRun()) + { + parseQuake3Config(); + } + + settings.setHaveRun(true); } ioLaunch::~ioLaunch() @@ -264,3 +275,103 @@ void ioLaunch::on_sbHeight_valueChanged(int arg1) ioHedited = false; } } + +// Since q3config.cfg is generated it's nice and clean and shouldn't need a full parser. +static QString ParseToken(const QString &s, int &offset) +{ + // Skip whitespace. + while (offset < s.length() && s[offset] == ' ') + { + offset++; + } + + if (offset >= s.length()) + return QString(); + + // Check for quoted token. + bool quoted = s[offset] == '\"'; + + if (quoted) + offset++; + + // Parse token. + int start = offset; + + while (offset < s.length() && ((quoted && s[offset] != '\"') || (!quoted && s[offset] != ' '))) + { + offset++; + } + + // Get token substring. + int end = offset; + + if (quoted && s[offset] == '\"') + { + offset++; + } + + if (end - start <= 0) + return QString(); + + return s.mid(start, end - start); +} + +void ioLaunch::parseQuake3Config() +{ + QFile file(homePath + "/baseq3/q3config.cfg"); + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream stream(&file); + + // These may occur in any order, so process them after parsing the entire file. + QString r_mode, r_customwidth, r_customheight; + + while (!stream.atEnd()) + { + const QString line(stream.readLine()); + + // Skip comments. + if (line.startsWith("//")) + continue; + + int offset = 0; + + if (ParseToken(line, offset) == "seta") + { + const QString cvar(ParseToken(line, offset)); + + if (cvar == "r_mode") + { + r_mode = ParseToken(line, offset); + } + else if (cvar == "r_customwidth") + { + r_customwidth = ParseToken(line, offset); + } + else if (cvar == "r_customheight") + { + r_customheight = ParseToken(line, offset); + } + else if (cvar == "r_fullscreen") + { + // Set fullscreen/windows radio buttons. + const QString value(ParseToken(line, offset)); + + if (value == "0") + ui->rbWin->setChecked(true); + else if (value == "1") + ui->rbFull->setChecked(true); + } + } + } + + // Populate resolution spinboxes. + if (r_mode == "-1" && !r_customwidth.isEmpty() && !r_customheight.isEmpty()) + { + ui->sbWidth->setValue(r_customwidth.toInt()); + ui->sbHeight->setValue(r_customheight.toInt()); + ioWedited = ioHedited = true; + } +} diff --git a/mainwindow.h b/mainwindow.h index 1eacc7d..7b89c44 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -41,6 +41,8 @@ private slots: void on_sbHeight_valueChanged(int arg1); private: + void parseQuake3Config(); + Ui::ioLaunch *ui; QString resOption; QString screenOption; diff --git a/settings.cpp b/settings.cpp index c91f20f..5a85b76 100644 --- a/settings.cpp +++ b/settings.cpp @@ -28,6 +28,16 @@ Settings::Settings() : { } +bool Settings::getHaveRun() const +{ + return settings.value("haveRun").toBool(); +} + +void Settings::setHaveRun(bool value) +{ + settings.setValue("haveRun", value); +} + QString Settings::getQuakePath() const { return settings.value("quakePath").toString(); diff --git a/settings.h b/settings.h index 7a6099c..4e709c8 100644 --- a/settings.h +++ b/settings.h @@ -32,6 +32,9 @@ class Settings public: Settings(); + bool getHaveRun() const; + void setHaveRun(bool value); + QString getQuakePath() const; bool containsQuakePath() const; void setQuakePath(const QString &path); From 19d1d5698392768ae54ccc4c897bd7b4d8d3811a Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 16:17:35 +1000 Subject: [PATCH 4/8] Save/load resolution settings. --- mainwindow.cpp | 77 ++++++++++++++++++++++++++++++++++++-------------- settings.cpp | 40 ++++++++++++++++++++++++++ settings.h | 12 ++++++++ 3 files changed, 108 insertions(+), 21 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 2fbce5a..a9b4570 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -48,6 +48,36 @@ ioLaunch::ioLaunch(QWidget *parent) : } settings.setHaveRun(true); + + // Populate the GUI with values read from settings. + if (settings.getResolutionMode() >= 0) + { + // Predefined. + ui->cbResolution->setCurrentIndex(2 + settings.getResolutionMode()); + } + else if (settings.getResolutionMode() == -1) + { + // Custom. + ui->cbResolution->setCurrentIndex(0); + } + else if (settings.getResolutionMode() == -2) + { + // Desktop. + ui->cbResolution->setCurrentIndex(1); + } + + ui->sbWidth->setValue(settings.getResolutionWidth()); + ui->sbHeight->setValue(settings.getResolutionHeight()); + ioWedited = ioHedited = true; + + if (settings.getResolutionFullscreen()) + { + ui->rbFull->setChecked(true); + } + else + { + ui->rbWin->setChecked(true); + } } ioLaunch::~ioLaunch() @@ -223,6 +253,22 @@ void ioLaunch::on_cbResolution_currentIndexChanged(int index) break; } } + + if (index == 0) + { + // Custom. + settings.setResolutionMode(-1); + } + else if (index == 1) + { + // Desktop. + settings.setResolutionMode(-2); + } + else + { + // Predefined. + settings.setResolutionMode(index - 2); + } } void ioLaunch::on_rbFull_toggled(bool checked) @@ -230,6 +276,7 @@ void ioLaunch::on_rbFull_toggled(bool checked) if(checked) { screenOption = " +set r_fullscreen 1"; + settings.setResolutionFullscreen(true); } } @@ -238,6 +285,7 @@ void ioLaunch::on_rbWin_toggled(bool checked) if(checked) { screenOption = " +set r_fullscreen 0"; + settings.setResolutionFullscreen(false); } } @@ -261,6 +309,8 @@ void ioLaunch::on_sbWidth_valueChanged(int arg1) else{ ioWedited = false; } + + settings.setResolutionWidth(arg1); } void ioLaunch::on_sbHeight_valueChanged(int arg1) @@ -274,6 +324,8 @@ void ioLaunch::on_sbHeight_valueChanged(int arg1) else{ ioHedited = false; } + + settings.setResolutionHeight(arg1); } // Since q3config.cfg is generated it's nice and clean and shouldn't need a full parser. @@ -325,9 +377,6 @@ void ioLaunch::parseQuake3Config() QTextStream stream(&file); - // These may occur in any order, so process them after parsing the entire file. - QString r_mode, r_customwidth, r_customheight; - while (!stream.atEnd()) { const QString line(stream.readLine()); @@ -344,34 +393,20 @@ void ioLaunch::parseQuake3Config() if (cvar == "r_mode") { - r_mode = ParseToken(line, offset); + settings.setResolutionMode(ParseToken(line, offset).toInt()); } else if (cvar == "r_customwidth") { - r_customwidth = ParseToken(line, offset); + settings.setResolutionWidth(ParseToken(line, offset).toInt()); } else if (cvar == "r_customheight") { - r_customheight = ParseToken(line, offset); + settings.setResolutionHeight(ParseToken(line, offset).toInt()); } else if (cvar == "r_fullscreen") { - // Set fullscreen/windows radio buttons. - const QString value(ParseToken(line, offset)); - - if (value == "0") - ui->rbWin->setChecked(true); - else if (value == "1") - ui->rbFull->setChecked(true); + settings.setResolutionFullscreen(ParseToken(line, offset).toInt() != 0); } } } - - // Populate resolution spinboxes. - if (r_mode == "-1" && !r_customwidth.isEmpty() && !r_customheight.isEmpty()) - { - ui->sbWidth->setValue(r_customwidth.toInt()); - ui->sbHeight->setValue(r_customheight.toInt()); - ioWedited = ioHedited = true; - } } diff --git a/settings.cpp b/settings.cpp index 5a85b76..e7a5f62 100644 --- a/settings.cpp +++ b/settings.cpp @@ -52,3 +52,43 @@ void Settings::setQuakePath(const QString &path) { settings.setValue("quakePath", path); } + +int Settings::getResolutionMode() const +{ + return settings.value("resolution/mode", 3).toInt(); +} + +void Settings::setResolutionMode(int mode) +{ + settings.setValue("resolution/mode", mode); +} + +int Settings::getResolutionWidth() const +{ + return settings.value("resolution/width", 1600).toInt(); +} + +void Settings::setResolutionWidth(int width) +{ + settings.setValue("resolution/width", width); +} + +int Settings::getResolutionHeight() const +{ + return settings.value("resolution/height", 1024).toInt(); +} + +void Settings::setResolutionHeight(int height) +{ + settings.setValue("resolution/height", height); +} + +bool Settings::getResolutionFullscreen() const +{ + return settings.value("resolution/fullscreen", 1).toBool(); +} + +void Settings::setResolutionFullscreen(bool value) +{ + settings.setValue("resolution/fullscreen", value); +} diff --git a/settings.h b/settings.h index 4e709c8..15f35ce 100644 --- a/settings.h +++ b/settings.h @@ -39,6 +39,18 @@ public: bool containsQuakePath() const; void setQuakePath(const QString &path); + int getResolutionMode() const; + void setResolutionMode(int mode); + + int getResolutionWidth() const; + void setResolutionWidth(int width); + + int getResolutionHeight() const; + void setResolutionHeight(int height); + + bool getResolutionFullscreen() const; + void setResolutionFullscreen(bool value); + private: QSettings settings; }; From 81787fb72e5858ce7efdf2daeb425f9e9dd1662b Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 17:06:21 +1000 Subject: [PATCH 5/8] Don't need default GUI settings anymore, since defaults are read from q3config.cfg. This simplifies things quite a bit. --- mainwindow.cpp | 187 +++++++------------------------------------------ mainwindow.h | 13 ---- mainwindow.ui | 28 ++------ 3 files changed, 31 insertions(+), 197 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index a9b4570..38d33e8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,12 +13,9 @@ ioLaunch::ioLaunch(QWidget *parent) : QMainWindow(parent), - ui(new Ui::ioLaunch), - ioWidth(0), ioHeight(0), ioWedited(false), ioHedited(false) + ui(new Ui::ioLaunch) { ui->setupUi(this); - resOption = ""; - screenOption = ""; // Calculate ioquake3 home path. #ifdef Q_OS_WIN32 @@ -58,17 +55,16 @@ ioLaunch::ioLaunch(QWidget *parent) : else if (settings.getResolutionMode() == -1) { // Custom. - ui->cbResolution->setCurrentIndex(0); + ui->cbResolution->setCurrentIndex(1); } else if (settings.getResolutionMode() == -2) { // Desktop. - ui->cbResolution->setCurrentIndex(1); + ui->cbResolution->setCurrentIndex(0); } ui->sbWidth->setValue(settings.getResolutionWidth()); ui->sbHeight->setValue(settings.getResolutionHeight()); - ioWedited = ioHedited = true; if (settings.getResolutionFullscreen()) { @@ -104,6 +100,7 @@ void ioLaunch::on_btnLaunch_clicked() if(promptForPath) { + QMessageBox msg; msg.setText("Please select your Quake3 directory"); msg.exec(); @@ -115,156 +112,53 @@ void ioLaunch::on_btnLaunch_clicked() settings.setQuakePath(path); } - ioq3 = QString("\"") + settings.getQuakePath() + "/ioquake3.x86.exe\" +set r_mode -1"; + ioq3 = QString("\"") + settings.getQuakePath() + "/ioquake3.x86.exe\""; #elif defined Q_OS_MAC - ioq3 = "open -a ioquake3 --args +set r_mode -1"; + ioq3 = "open -a ioquake3 --args"; #elif defined Q_OS_UNIX - ioq3 = "ioquake3 +set r_mode -1"; + ioq3 = "ioquake3"; #else #error "Unsupported platform" #endif + ioq3 += QString(" +set r_mode \"%1\"").arg(settings.getResolutionMode()); - if(ioWedited == true && ioHedited == true) + if(settings.getResolutionMode() == -2) { - - resOption = " +set r_customwidth " + QString::number(ioWidth) + " +set r_customheight " + QString::number(ioHeight); + // Desktop/native. + const QRect rect(QApplication::desktop()->screenGeometry()); + ioq3 += QString(" +set r_customwidth %1").arg(rect.width()) + QString(" +set r_customheight %1").arg(rect.height()); } - if(resOption == NULL) + else if (settings.getResolutionMode() == -1) { - resOption = ""; - } - if(screenOption == NULL) - { - screenOption = ""; + // Custom. + ioq3 += QString(" +set r_customwidth %1").arg(settings.getResolutionWidth()) + QString(" +set r_customheight %1").arg(settings.getResolutionHeight()); } - if(!QProcess::startDetached(ioq3+resOption+screenOption)) + ioq3 += QString(" +set r_fullscreen %1").arg(settings.getResolutionFullscreen() ? "1" : "0"); + + if(!QProcess::startDetached(ioq3)) { + QMessageBox ioq3Failed; ioq3Failed.setText("ioquake3 failed to start!\nIs it installed?\n"); ioq3Failed.exec(); } } -void ioLaunch::on_cbResolution_highlighted(int /*index*/) -{ - ioWedited = false; - ioHedited = false; -} - void ioLaunch::on_cbResolution_currentIndexChanged(int index) { - ioWedited = false; - ioHedited = false; - switch(index) - { - case 0: - { - resOption = ""; - break; - } - case 1: - { - ioWidth = QApplication::desktop()->screenGeometry().width(); - ioHeight = QApplication::desktop()->screenGeometry().height(); - - resOption = " +set r_customwidth " + QString::number(ioWidth) + " +set r_customheight " + QString::number(ioHeight); - break; - } - case 2: - { - resOption = " +set r_customwidth 320 +set r_customheight 240"; - break; - } - case 3: - { - resOption = " +set r_customwidth 400 +set r_customheight 300"; - break; - } - case 4: - { - resOption = " +set r_customwidth 512 +set r_customheight 384"; - break; - } - case 5: - { - resOption = " +set r_customwidth 640 +set r_customheight 480"; - break; - } - case 6: - { - resOption = " +set r_customwidth 800 +set r_customheight 600"; - break; - } - case 7: - { - resOption = " +set r_customwidth 960 +set r_customheight 720"; - break; - } - case 8: - { - resOption = " +set r_customwidth 1024 +set r_customheight 768"; - break; - } - case 9: - { - resOption = " +set r_customwidth 1152 +set r_customheight 864"; - break; - } - case 10: - { - resOption = " +set r_customwidth 1280 +set r_customheight 1024"; - break; - } - case 11: - { - resOption = " +set r_customwidth 1600 +set r_customheight 1200"; - break; - } - case 12: - { - resOption = " +set r_customwidth 2048 +set r_customheight 1536"; - break; - } - case 13: - { - resOption = " +set r_customwidth 856 +set r_customheight 480"; - break; - } - case 14: - { - resOption = " +set r_customwidth 1280 +set r_customheight 720"; - break; - } - case 15: - { - resOption = " +set r_customwidth 1920 +set r_customheight 1080"; - break; - } - case 16: - { - resOption = " +set r_customwidth 1280 +set r_customheight 800"; - break; - } - default: - { - resOption = ""; - break; - } - } - if (index == 0) - { - // Custom. - settings.setResolutionMode(-1); - } - else if (index == 1) { // Desktop. settings.setResolutionMode(-2); } - else + else if (index == 1) + { + // Custom. + settings.setResolutionMode(-1); + } + else if (index >= 2) { // Predefined. settings.setResolutionMode(index - 2); @@ -275,7 +169,6 @@ void ioLaunch::on_rbFull_toggled(bool checked) { if(checked) { - screenOption = " +set r_fullscreen 1"; settings.setResolutionFullscreen(true); } } @@ -284,47 +177,17 @@ void ioLaunch::on_rbWin_toggled(bool checked) { if(checked) { - screenOption = " +set r_fullscreen 0"; settings.setResolutionFullscreen(false); } } -void ioLaunch::on_rbDefault_toggled(bool checked) -{ - if(checked) - { - screenOption = ""; - } -} - - void ioLaunch::on_sbWidth_valueChanged(int arg1) { - ioWidth = 0; - if(arg1 >= 0) - { - ioWidth = arg1; - ioWedited = true; - } - else{ - ioWedited = false; - } - settings.setResolutionWidth(arg1); } void ioLaunch::on_sbHeight_valueChanged(int arg1) { - ioHeight = 0; - if(arg1 >= 0) - { - ioHeight = arg1; - ioHedited = true; - } - else{ - ioHedited = false; - } - settings.setResolutionHeight(arg1); } diff --git a/mainwindow.h b/mainwindow.h index 7b89c44..ad2dfde 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -25,17 +25,12 @@ public: private slots: void on_btnLaunch_clicked(); - - void on_cbResolution_highlighted(int index); - void on_cbResolution_currentIndexChanged(int index); void on_rbFull_toggled(bool checked); void on_rbWin_toggled(bool checked); - void on_rbDefault_toggled(bool checked); - void on_sbWidth_valueChanged(int arg1); void on_sbHeight_valueChanged(int arg1); @@ -44,14 +39,6 @@ private: void parseQuake3Config(); Ui::ioLaunch *ui; - QString resOption; - QString screenOption; - QMessageBox msg; - QMessageBox ioq3Failed; - int ioWidth; - int ioHeight; - bool ioWedited; - bool ioHedited; Settings settings; QString homePath; }; diff --git a/mainwindow.ui b/mainwindow.ui index a6ca48c..d645d02 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -117,7 +117,7 @@ QTabWidget::tab-bar{ } - 0 + 1 @@ -137,22 +137,6 @@ QTabWidget::tab-bar{ Settings - - - - 110 - 40 - 91 - 21 - - - - Default - - - true - - @@ -164,12 +148,12 @@ QTabWidget::tab-bar{ - Default + Native - Native + Custom @@ -264,7 +248,7 @@ QTabWidget::tab-bar{ - 310 + 200 40 121 21 @@ -329,7 +313,7 @@ QTabWidget::tab-bar{ - 200 + 90 40 111 21 @@ -339,7 +323,7 @@ QTabWidget::tab-bar{ FullScreen - false + true From 3ea451a168046c140d66807066430a55f890c795 Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 17:38:28 +1000 Subject: [PATCH 6/8] Handle r_modes outside what ioquake3 recognize. --- mainwindow.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 38d33e8..a9cd1b5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -121,19 +121,35 @@ void ioLaunch::on_btnLaunch_clicked() #error "Unsupported platform" #endif - ioq3 += QString(" +set r_mode \"%1\"").arg(settings.getResolutionMode()); + int r_mode = settings.getResolutionMode(); + int r_width = settings.getResolutionWidth(); + int r_height = settings.getResolutionHeight(); - if(settings.getResolutionMode() == -2) + // Handle modes outside what ioquake3 recognize. + if (r_mode == 12) { - // Desktop/native. - const QRect rect(QApplication::desktop()->screenGeometry()); - ioq3 += QString(" +set r_customwidth %1").arg(rect.width()) + QString(" +set r_customheight %1").arg(rect.height()); - + r_mode = -1; + r_width = 1280; + r_height = 720; } - else if (settings.getResolutionMode() == -1) + else if (r_mode == 13) { - // Custom. - ioq3 += QString(" +set r_customwidth %1").arg(settings.getResolutionWidth()) + QString(" +set r_customheight %1").arg(settings.getResolutionHeight()); + r_mode = -1; + r_width = 1920; + r_height = 1080; + } + else if (r_mode == 14) + { + r_mode = -1; + r_width = 1280; + r_height = 800; + } + + ioq3 += QString(" +set r_mode \"%1\"").arg(r_mode); + + if (r_mode == -1) + { + ioq3 += QString(" +set r_customwidth %1").arg(r_width) + QString(" +set r_customheight %1").arg(r_height); } ioq3 += QString(" +set r_fullscreen %1").arg(settings.getResolutionFullscreen() ? "1" : "0"); From 78d3bd02c33fd0f58ad3c0461e08abd7899e0396 Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 17:41:45 +1000 Subject: [PATCH 7/8] Disable resolution spinboxes when "Custom" resolution is not set. --- mainwindow.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index a9cd1b5..8328117 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -179,6 +179,17 @@ void ioLaunch::on_cbResolution_currentIndexChanged(int index) // Predefined. settings.setResolutionMode(index - 2); } + + if (index == 1) + { + ui->sbWidth->setEnabled(true); + ui->sbHeight->setEnabled(true); + } + else + { + ui->sbWidth->setEnabled(false); + ui->sbHeight->setEnabled(false); + } } void ioLaunch::on_rbFull_toggled(bool checked) From a3a9d199e990e51904855082b8ad136ed09df76e Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Fri, 9 May 2014 17:45:38 +1000 Subject: [PATCH 8/8] Accidentally changed default tab to settings instead of main. --- mainwindow.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainwindow.ui b/mainwindow.ui index d645d02..4ae9d84 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -117,7 +117,7 @@ QTabWidget::tab-bar{ } - 1 + 0