2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* mainwindow_moc.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2013-08-22 17:22:49 +03:00
|
|
|
#include "StdInc.h"
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "mainwindow_moc.h"
|
|
|
|
#include "ui_mainwindow_moc.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
#include "../lib/CConfigHandler.h"
|
|
|
|
#include "../lib/VCMIDirs.h"
|
|
|
|
#include "../lib/filesystem/Filesystem.h"
|
|
|
|
#include "../lib/logging/CBasicLogConfigurator.h"
|
|
|
|
|
|
|
|
void MainWindow::load()
|
|
|
|
{
|
2017-08-09 00:09:29 +02:00
|
|
|
// Set current working dir to executable folder.
|
|
|
|
// This is important on Mac for relative paths to work inside DMG.
|
|
|
|
QDir::setCurrent(QApplication::applicationDirPath());
|
|
|
|
|
2017-07-16 11:58:05 +02:00
|
|
|
console = new CConsoleHandler();
|
2014-08-21 23:26:28 +03:00
|
|
|
CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Launcher_log.txt", console);
|
2013-08-22 17:22:49 +03:00
|
|
|
logConfig.configureDefault();
|
|
|
|
|
|
|
|
CResourceHandler::initialize();
|
2013-11-08 23:36:26 +03:00
|
|
|
CResourceHandler::load("config/filesystem.json");
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto & string : VCMIDirs::get().dataPaths())
|
2014-08-21 23:26:28 +03:00
|
|
|
QDir::addSearchPath("icons", pathToQString(string / "launcher" / "icons"));
|
|
|
|
QDir::addSearchPath("icons", pathToQString(VCMIDirs::get().userDataPath() / "launcher" / "icons"));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-07-16 22:05:42 +02:00
|
|
|
settings.init();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
MainWindow::MainWindow(QWidget * parent)
|
|
|
|
: QMainWindow(parent), ui(new Ui::MainWindow)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
load(); // load FS before UI
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
2019-07-30 08:32:35 +02:00
|
|
|
|
|
|
|
//load window settings
|
|
|
|
QSettings s(Ui::teamName, Ui::appName);
|
|
|
|
|
|
|
|
auto size = s.value("MainWindow/Size").toSize();
|
2019-07-30 11:00:44 +02:00
|
|
|
if(size.isValid())
|
2019-07-30 08:32:35 +02:00
|
|
|
{
|
|
|
|
resize(size);
|
|
|
|
}
|
|
|
|
auto position = s.value("MainWindow/Position").toPoint();
|
2019-07-30 11:00:44 +02:00
|
|
|
if(!position.isNull())
|
2019-07-30 08:32:35 +02:00
|
|
|
{
|
|
|
|
move(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
//set default margins
|
|
|
|
|
2016-10-02 00:27:45 +02:00
|
|
|
auto width = ui->startGameTitle->fontMetrics().boundingRect(ui->startGameTitle->text()).width();
|
2018-04-13 07:34:58 +02:00
|
|
|
if(ui->startGameButton->iconSize().width() < width)
|
2016-10-02 00:27:45 +02:00
|
|
|
{
|
|
|
|
ui->startGameButton->setIconSize(QSize(width, width));
|
|
|
|
}
|
|
|
|
auto tab_icon_size = ui->tabSelectList->iconSize();
|
2018-04-13 07:34:58 +02:00
|
|
|
if(tab_icon_size.width() < width)
|
2016-10-02 00:27:45 +02:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
ui->tabSelectList->setIconSize(QSize(width, width + tab_icon_size.height() - tab_icon_size.width()));
|
2016-10-02 00:27:45 +02:00
|
|
|
ui->tabSelectList->setGridSize(QSize(width, width));
|
|
|
|
// 4 is a dirty hack to make it look right
|
|
|
|
ui->tabSelectList->setMaximumWidth(width + 4);
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->tabListWidget->setCurrentIndex(0);
|
2017-08-24 03:52:02 +02:00
|
|
|
ui->settingsView->setDisplayList();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
|
2018-04-13 07:34:58 +02:00
|
|
|
ui->tabListWidget, SLOT(setCurrentIndex(int)));
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2019-07-30 08:32:35 +02:00
|
|
|
//save window settings
|
|
|
|
QSettings s(Ui::teamName, Ui::appName);
|
|
|
|
s.setValue("MainWindow/Size", size());
|
|
|
|
s.setValue("MainWindow/Position", pos());
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2016-10-02 00:27:45 +02:00
|
|
|
void MainWindow::on_startGameButton_clicked()
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-08-21 23:26:28 +03:00
|
|
|
startExecutable(pathToQString(VCMIDirs::get().clientPath()));
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::startExecutable(QString name)
|
|
|
|
{
|
|
|
|
QProcess process;
|
|
|
|
|
|
|
|
// Start the executable
|
2022-05-28 15:32:20 +02:00
|
|
|
if(process.startDetached(name, {}))
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
close(); // exit launcher
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this,
|
|
|
|
"Error starting executable",
|
2013-08-24 23:11:51 +03:00
|
|
|
"Failed to start " + name + "\n"
|
|
|
|
"Reason: " + process.errorString(),
|
2013-08-22 17:22:49 +03:00
|
|
|
QMessageBox::Ok,
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|