mainwindow_moc.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * mainwindow_moc.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "mainwindow_moc.h"
  12. #include "ui_mainwindow_moc.h"
  13. #include <QProcess>
  14. #include <QDir>
  15. #include "../lib/CConfigHandler.h"
  16. #include "../lib/VCMIDirs.h"
  17. #include "../lib/filesystem/Filesystem.h"
  18. #include "../lib/logging/CBasicLogConfigurator.h"
  19. void MainWindow::load()
  20. {
  21. console = new CConsoleHandler();
  22. CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Launcher_log.txt", console);
  23. logConfig.configureDefault();
  24. CResourceHandler::initialize();
  25. CResourceHandler::load("config/filesystem.json");
  26. for(auto & string : VCMIDirs::get().dataPaths())
  27. QDir::addSearchPath("icons", pathToQString(string / "launcher" / "icons"));
  28. QDir::addSearchPath("icons", pathToQString(VCMIDirs::get().userDataPath() / "launcher" / "icons"));
  29. settings.init();
  30. }
  31. MainWindow::MainWindow(const QStringList & displayList, QWidget * parent)
  32. : QMainWindow(parent), ui(new Ui::MainWindow)
  33. {
  34. load(); // load FS before UI
  35. ui->setupUi(this);
  36. auto width = ui->startGameTitle->fontMetrics().boundingRect(ui->startGameTitle->text()).width();
  37. if(ui->startGameButton->iconSize().width() < width)
  38. {
  39. ui->startGameButton->setIconSize(QSize(width, width));
  40. }
  41. auto tab_icon_size = ui->tabSelectList->iconSize();
  42. if(tab_icon_size.width() < width)
  43. {
  44. ui->tabSelectList->setIconSize(QSize(
  45. width,
  46. width + tab_icon_size.height() - tab_icon_size.width()));
  47. ui->tabSelectList->setGridSize(QSize(width, width));
  48. // 4 is a dirty hack to make it look right
  49. ui->tabSelectList->setMaximumWidth(width + 4);
  50. }
  51. ui->tabListWidget->setCurrentIndex(0);
  52. ui->settingsView->setDisplayList(displayList);
  53. connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
  54. ui->tabListWidget, SLOT(setCurrentIndex(int)));
  55. }
  56. MainWindow::~MainWindow()
  57. {
  58. delete ui;
  59. }
  60. void MainWindow::on_startGameButton_clicked()
  61. {
  62. startExecutable(pathToQString(VCMIDirs::get().clientPath()));
  63. }
  64. void MainWindow::startExecutable(QString name)
  65. {
  66. QProcess process;
  67. // Start the executable
  68. if(process.startDetached(name))
  69. {
  70. close(); // exit launcher
  71. }
  72. else
  73. {
  74. QMessageBox::critical(this,
  75. "Error starting executable",
  76. "Failed to start " + name + "\n"
  77. "Reason: " + process.errorString(),
  78. QMessageBox::Ok,
  79. QMessageBox::Ok);
  80. return;
  81. }
  82. }