From 58bc0f72726c519ccae58058723cf30bec79d9d9 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 30 Aug 2016 20:54:37 +0200 Subject: [PATCH] Allow choosing the display from the launcher This adds another combobox for choosing the display. To ease the display choice we try to roughly describe the display (its resolution and location). The combobox is hidden for single display setups. --- launcher/CMakeLists.txt | 6 ++- launcher/main.cpp | 4 +- launcher/mainwindow_moc.cpp | 3 +- launcher/mainwindow_moc.h | 3 +- launcher/mainwindow_moc.ui | 2 +- launcher/sdldisplayquery.cpp | 32 ++++++++++++ launcher/sdldisplayquery.h | 5 ++ launcher/settingsView/csettingsview_moc.cpp | 22 ++++++++- launcher/settingsView/csettingsview_moc.h | 3 ++ launcher/settingsView/csettingsview_moc.ui | 54 +++++++++++++-------- 10 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 launcher/sdldisplayquery.cpp create mode 100644 launcher/sdldisplayquery.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index c58d62828..597a6a0c5 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.7) include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${ZLIB_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) +include_directories(${SDL_INCLUDE_DIR}) set(launcher_modmanager_SRCS modManager/cdownloadmanager_moc.cpp @@ -25,6 +26,7 @@ set(launcher_SRCS mainwindow_moc.cpp launcherdirs.cpp jsonutils.cpp + sdldisplayquery.cpp ) set(launcher_FORMS @@ -60,10 +62,10 @@ endif() if(MSVC) # Fix _WinMain@16 linking error - target_link_libraries(vcmilauncher vcmi ${Qt5Core_QTMAIN_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) + target_link_libraries(vcmilauncher vcmi ${Qt5Core_QTMAIN_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${SDL_LIBRARY}) else() # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore - target_link_libraries(vcmilauncher vcmi ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) + target_link_libraries(vcmilauncher vcmi ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${SDL_LIBRARY}) endif() # temporary(?) disabled - generation of PCH takes too much time since cotire is trying to collect all Qt headers diff --git a/launcher/main.cpp b/launcher/main.cpp index e9fd317b5..cb3ed80bb 100644 --- a/launcher/main.cpp +++ b/launcher/main.cpp @@ -1,11 +1,13 @@ #include "StdInc.h" #include "mainwindow_moc.h" #include +#include "sdldisplayquery.h" int main(int argc, char *argv[]) { + auto displayList = getDisplays(); QApplication a(argc, argv); - MainWindow w; + MainWindow w(displayList); w.show(); return a.exec(); diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index 3536e925a..1656f94b3 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -26,7 +26,7 @@ void MainWindow::load() settings.init(); } -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(const QStringList& displayList, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -34,6 +34,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); ui->tabListWidget->setCurrentIndex(0); + ui->settingsView->setDisplayList(displayList); connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)), ui->tabListWidget, SLOT(setCurrentIndex(int))); diff --git a/launcher/mainwindow_moc.h b/launcher/mainwindow_moc.h index e1c994c99..1584c9e4e 100644 --- a/launcher/mainwindow_moc.h +++ b/launcher/mainwindow_moc.h @@ -1,5 +1,6 @@ #pragma once #include +#include namespace Ui { class MainWindow; @@ -14,7 +15,7 @@ class MainWindow : public QMainWindow void load(); void startExecutable(QString name); public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(const QStringList& displayList, QWidget *parent = 0); ~MainWindow(); private slots: diff --git a/launcher/mainwindow_moc.ui b/launcher/mainwindow_moc.ui index 2aa753c8b..a63de44a9 100644 --- a/launcher/mainwindow_moc.ui +++ b/launcher/mainwindow_moc.ui @@ -176,7 +176,7 @@ 1 - + diff --git a/launcher/sdldisplayquery.cpp b/launcher/sdldisplayquery.cpp new file mode 100644 index 000000000..aaaf24bb1 --- /dev/null +++ b/launcher/sdldisplayquery.cpp @@ -0,0 +1,32 @@ +#include "sdldisplayquery.h" + +#include +#include + +#include +#include + +QStringList getDisplays() +{ + if(SDL_Init(SDL_INIT_VIDEO)) + return QStringList("default display"); + + const int displays = SDL_GetNumVideoDisplays(); + QStringList list; + + for (int display = 0; display < displays; ++display) + { + SDL_Rect rect; + + if (SDL_GetDisplayBounds (display, &rect)) + continue; + + QString string; + QTextStream(&string) << display << " - " << rect.w << "x" << rect.h << " (at " << rect.x << ", " << rect.y << ")"; + + list << string; + } + + SDL_Quit(); + return list; +} diff --git a/launcher/sdldisplayquery.h b/launcher/sdldisplayquery.h new file mode 100644 index 000000000..e2c7dcaa1 --- /dev/null +++ b/launcher/sdldisplayquery.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +QStringList getDisplays(); diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 6c1722287..bdfc967c3 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -20,11 +20,25 @@ static const std::string knownEncodingsList[] = //TODO: remove hardcode "GB2312" // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts }; +void CSettingsView::setDisplayList(const QStringList& displayList) +{ + if (displayList.count() < 2) + { + ui->comboBoxDisplayIndex->hide (); + ui->labelDisplayIndex->hide (); + } + else + { + ui->comboBoxDisplayIndex->clear(); + ui->comboBoxDisplayIndex->addItems(displayList); + ui->comboBoxDisplayIndex->setCurrentIndex(settings["video"]["displayIndex"].Float()); + } +} + void CSettingsView::loadSettings() { int resX = settings["video"]["screenRes"]["width"].Float(); int resY = settings["video"]["screenRes"]["height"].Float(); - int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY)); ui->comboBoxResolution->setCurrentIndex(resIndex); @@ -92,6 +106,12 @@ void CSettingsView::on_comboBoxAutoCheck_currentIndexChanged(int index) node->Bool() = index; } +void CSettingsView::on_comboBoxDisplayIndex_currentIndexChanged(int index) +{ + Settings node = settings.write["video"]; + node["displayIndex"].Float() = index; +} + void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString &arg1) { Settings node = settings.write["server"]["playerAI"]; diff --git a/launcher/settingsView/csettingsview_moc.h b/launcher/settingsView/csettingsview_moc.h index 5aca831fe..5ee782c96 100644 --- a/launcher/settingsView/csettingsview_moc.h +++ b/launcher/settingsView/csettingsview_moc.h @@ -15,6 +15,7 @@ public: ~CSettingsView(); void loadSettings(); + void setDisplayList(const QStringList& displayList); private slots: void on_comboBoxResolution_currentIndexChanged(const QString &arg1); @@ -43,6 +44,8 @@ private slots: void on_comboBoxAutoCheck_currentIndexChanged(int index); + void on_comboBoxDisplayIndex_currentIndexChanged(int index); + private: Ui::CSettingsView *ui; }; diff --git a/launcher/settingsView/csettingsview_moc.ui b/launcher/settingsView/csettingsview_moc.ui index 98d431510..bf9d73c65 100644 --- a/launcher/settingsView/csettingsview_moc.ui +++ b/launcher/settingsView/csettingsview_moc.ui @@ -6,8 +6,8 @@ 0 0 - 700 - 420 + 714 + 429 @@ -26,7 +26,7 @@ 0 - + @@ -39,7 +39,7 @@ - + @@ -59,7 +59,7 @@ - + 1024 @@ -99,7 +99,7 @@ - + @@ -192,7 +192,7 @@ - + QPlainTextEdit::NoWrap @@ -222,7 +222,7 @@ - + @@ -250,21 +250,21 @@ - + Neutral AI - + Heroes III character set - + @@ -273,14 +273,14 @@ - + Player AI - + @@ -309,7 +309,7 @@ - + Network port @@ -329,7 +329,7 @@ - + @@ -411,7 +411,7 @@ - + Qt::Vertical @@ -427,7 +427,7 @@ - + Qt::Vertical @@ -472,7 +472,7 @@ - + 1 @@ -489,13 +489,29 @@ - + Check repositories on startup + + + + Display index + + + + + + + + 0 + + + +