mainwindow.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. #include "mainwindow.h"
  2. #include <QSettings>
  3. #include <QApplication>
  4. #include <QFileInfo>
  5. #include <QFileDialog>
  6. #include <QMessageBox>
  7. #include <QThread>
  8. #include <QCursor>
  9. #include <QPalette>
  10. #include <QFontDialog>
  11. #include <QIcon>
  12. #include <QDesktopServices>
  13. #include <QLocale>
  14. #include <QInputDialog>
  15. #include <QMimeData>
  16. #include <QDesktopWidget>
  17. #include "callbacks_gui.h"
  18. #include "comtools.h"
  19. #include "optionsdialog.h"
  20. #ifdef _ANDROIDQT
  21. #include <QStandardPaths>
  22. #include "androidfiledialog.h"
  23. #endif
  24. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
  25. {
  26. resize(600, 450);
  27. setMinimumSize(240, 180);
  28. setWindowTitle(QSP_LOGO);
  29. setWindowIcon(QIcon(":/gfx/logo"));
  30. setUnifiedTitleAndToolBarOnMac(true);
  31. setDockNestingEnabled(true);
  32. setFocusPolicy(Qt::StrongFocus);
  33. setObjectName(QStringLiteral("MainWindow"));
  34. setAcceptDrops(true);
  35. #ifdef _WEBBOX
  36. // qwuri = new QspWebEngineUrlRequestInterceptor();
  37. // QWebEngineProfile::defaultProfile()->setRequestInterceptor(qwuri);
  38. // QspWebEngineUrlSchemeHandler *qweush = new QspWebEngineUrlSchemeHandler();
  39. // QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(QByteArray("qsp"),qweush);
  40. #endif
  41. m_palette = palette();
  42. mainMenuBar = new QMenuBar(this);
  43. setMenuBar(mainMenuBar);
  44. mainMenuBar->setObjectName(QStringLiteral("mainMenuBar"));
  45. mainMenuBar->setVisible(true);
  46. mainToolBar = new QToolBar(this);
  47. mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
  48. addToolBar(mainToolBar);
  49. //mainStatusBar = new QStatusBar(this);
  50. //mainStatusBar->setObjectName(QStringLiteral("mainStatusBar"));
  51. //setStatusBar(mainStatusBar);
  52. // Set QMainWindow in the center of desktop
  53. //QRect rect = geometry();
  54. //rect.moveCenter(QApplication::desktop()->availableGeometry().center());
  55. //setGeometry(rect);
  56. //mainStatusBar->setVisible(false);
  57. mainToolBar->setVisible(false);
  58. mainToolBar->setWindowTitle(tr("ToolBar"));
  59. m_timer = new QTimer(this);
  60. m_timer->setObjectName(QStringLiteral("m_timer"));
  61. connect(m_timer, SIGNAL(timeout()), this, SLOT(OnTimer()));
  62. m_savedGamePath.clear();
  63. m_isQuit = false;
  64. m_keyPressedWhileDisabled = false;
  65. m_isGameOpened = false;
  66. showPlainText = false;
  67. //setCentralWidget(_mainDescWidget);
  68. m_linkColor = palette().color(QPalette::Link);
  69. m_fontColor = palette().color(QPalette::Text);
  70. m_backColor = QColor(224, 224, 224);
  71. m_isUseBackColor = false;
  72. m_isUseLinkColor = false;
  73. m_isUseFontColor = false;
  74. m_defaultBackColor = m_backColor;
  75. m_defaultLinkColor = m_linkColor;
  76. m_defaultFontColor = m_fontColor;
  77. m_font = QFont( "Sans", 12 , QFont::Normal );
  78. m_font.setStyle(QFont::StyleNormal);
  79. m_font.setStyleHint( QFont::SansSerif );
  80. m_defaultFont = m_font;
  81. m_isUseFontSize = false;
  82. m_isUseFont = false;
  83. m_fontSize = 12;
  84. showCaptions = true;
  85. m_isShowHotkeys = false;
  86. m_volume = 1.0f;
  87. disableVideo = false;
  88. m_videoFix = false;
  89. perGameConfig = true;
  90. autostartLastGame = false;
  91. m_isAllowHTML5Extras = true;
  92. langid = QObject::tr("__LANGID__");
  93. if(langid == QStringLiteral("__LANGID__"))
  94. langid = QLocale::system().name();
  95. CreateDockWindows();
  96. ApplyBackColor(m_backColor);
  97. ApplyFontColor(m_fontColor);
  98. ApplyLinkColor(m_linkColor);
  99. ApplyFont(m_font, 0 , 0);
  100. QFileInfo settingsFile(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  101. if(settingsFile.exists() && settingsFile.isFile())
  102. {
  103. LoadSettings(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  104. }
  105. else
  106. {
  107. LoadSettings();
  108. }
  109. CreateMenuBar();
  110. m_menu = new QMenu(this);
  111. m_menu->setObjectName(QStringLiteral("m_menu"));
  112. connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(OnMenu(QAction*)) );
  113. QSPInit();
  114. QSPCallBacks::Init(this);
  115. QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
  116. SetOverallVolume(m_volume);
  117. QFileInfo gameFile(QApplication::applicationDirPath() + "/standalone_content/" + QSP_GAME);
  118. if(gameFile.exists() && gameFile.isFile())
  119. {
  120. OpenGameFile(QApplication::applicationDirPath() + "/standalone_content/" + QSP_GAME);
  121. }
  122. else
  123. {
  124. if(autostartLastGame)
  125. OpenGameFile(lastGame);
  126. }
  127. }
  128. MainWindow::~MainWindow()
  129. {
  130. }
  131. void MainWindow::EnableControls(bool status, bool isExtended)
  132. {
  133. if (isExtended) _fileMenu->setEnabled(status); //TODO: ???
  134. _fileMenu->setEnabled(status); //TODO: ???
  135. _gameMenu->setEnabled(status);
  136. _settingsMenu->setEnabled(status);
  137. _objectsListBox->setEnabled(status);
  138. _actionsListBox->setEnabled(status);
  139. _inputTextBox->setEnabled(status);
  140. m_isProcessEvents = status;
  141. m_keyPressedWhileDisabled = false;
  142. }
  143. void MainWindow::ApplyParams()
  144. {
  145. int numVal;
  146. QSP_CHAR *strVal;
  147. QColor setBackColor, setFontColor, setLinkColor;
  148. setPalette(m_palette);
  149. // --------------
  150. if(!m_isUseBackColor)
  151. {
  152. if(QSPGetVarValues(QSP_FMT("BCOLOR"), 0, &numVal, &strVal))
  153. {
  154. if(numVal == 0)
  155. setBackColor = m_defaultBackColor;
  156. else
  157. setBackColor = QSPTools::wxtoQColor(numVal);
  158. }
  159. else
  160. setBackColor = m_defaultBackColor;
  161. }
  162. else
  163. {
  164. setBackColor = m_settingsBackColor;
  165. }
  166. ApplyBackColor(setBackColor);
  167. // --------------
  168. if(!m_isUseFontColor)
  169. {
  170. if(QSPGetVarValues(QSP_FMT("FCOLOR"), 0, &numVal, &strVal))
  171. {
  172. if(numVal == 0)
  173. setFontColor = m_defaultFontColor;
  174. else
  175. setFontColor = QSPTools::wxtoQColor(numVal);
  176. }
  177. else
  178. setFontColor = m_defaultFontColor;
  179. }
  180. else
  181. {
  182. setFontColor = m_settingsFontColor;
  183. }
  184. ApplyFontColor(setFontColor);
  185. // --------------
  186. if(!m_isUseLinkColor)
  187. {
  188. if(QSPGetVarValues(QSP_FMT("LCOLOR"), 0, &numVal, &strVal))
  189. {
  190. if(numVal == 0)
  191. setLinkColor = m_defaultLinkColor;
  192. else
  193. setLinkColor = QSPTools::wxtoQColor(numVal);
  194. }
  195. else
  196. setLinkColor = m_defaultLinkColor;
  197. }
  198. else
  199. {
  200. setLinkColor = m_settingsLinkColor;
  201. }
  202. ApplyLinkColor(setLinkColor);
  203. // --------------
  204. QFont new_font = m_defaultFont;
  205. int fontType = 0;
  206. int sizeType = 0;
  207. if(!m_isUseFont)
  208. {
  209. if(QSPGetVarValues(QSP_FMT("FNAME"), 0, &numVal, &strVal))
  210. {
  211. if(strVal != 0)
  212. {
  213. if(!QSPTools::qspStrToQt(strVal).isEmpty())
  214. {
  215. new_font.setFamily(QSPTools::qspStrToQt(strVal));
  216. fontType = 1;
  217. }
  218. }
  219. }
  220. if(!m_isUseFontSize)
  221. {
  222. if(QSPGetVarValues(QSP_FMT("FSIZE"), 0, &numVal, &strVal))
  223. {
  224. if(numVal != 0)
  225. {
  226. new_font.setPointSize(numVal);
  227. sizeType = 1;
  228. }
  229. }
  230. }
  231. else
  232. {
  233. new_font.setPointSize(m_fontSize);
  234. sizeType = 2;
  235. }
  236. }
  237. else
  238. {
  239. new_font = m_font;
  240. fontType = 2;
  241. if(m_isUseFontSize)
  242. {
  243. new_font.setPointSize(m_fontSize);
  244. sizeType = 2;
  245. }
  246. }
  247. ApplyFont(new_font, fontType, sizeType);
  248. }
  249. void MainWindow::DeleteMenu()
  250. {
  251. m_menu->clear();
  252. m_menuItemId = 0;
  253. }
  254. void MainWindow::AddMenuItem(const QString &name, const QString &imgPath)
  255. {
  256. if (name == QString("-"))
  257. m_menu->addSeparator();
  258. else
  259. {
  260. bool pixmap_ok = false;
  261. QPixmap itemPixmap;
  262. QFileInfo file(m_path + imgPath);
  263. QString itemPath(file.absoluteFilePath());
  264. if (file.exists() && file.isFile())
  265. {
  266. if(itemPixmap.load(itemPath))
  267. pixmap_ok = true;
  268. }
  269. QAction *action;
  270. if(pixmap_ok)
  271. {
  272. action = m_menu->addAction(QIcon(itemPixmap), name);
  273. //m_menu->addAction(QIcon(itemPixmap), name, this, SLOT(OnMenu(bool)));
  274. }
  275. else
  276. {
  277. action = m_menu->addAction(name);
  278. //m_menu->addAction(name, this, SLOT(OnMenu(bool)));
  279. }
  280. action->setData(m_menuItemId);
  281. }
  282. m_menuItemId++;
  283. }
  284. int MainWindow::ShowMenu()
  285. {
  286. m_menuIndex = -1;
  287. m_menu->exec(QCursor::pos());
  288. return m_menuIndex;
  289. }
  290. void MainWindow::UpdateGamePath(const QString &path)
  291. {
  292. QString new_path = path;
  293. if(!new_path.endsWith("/"))
  294. new_path+="/";
  295. m_path = new_path;
  296. _mainDescTextBox->SetGamePath(new_path);
  297. _descTextBox->SetGamePath(new_path);
  298. _actionsListBox->SetGamePath(new_path);
  299. _objectsListBox->SetGamePath(new_path);
  300. m_imgView->SetGamePath(new_path);
  301. }
  302. void MainWindow::ShowError()
  303. {
  304. bool oldIsProcessEvents;
  305. QString errorMessage;
  306. QSP_CHAR *loc;
  307. int code, actIndex, line;
  308. if (m_isQuit) return;
  309. QSPGetLastErrorData(&code, &loc, &actIndex, &line);
  310. QString desc = QSPTools::qspStrToQt(QSPGetErrorDesc(code));
  311. if (loc)
  312. errorMessage = QString("Location: %1\nArea: %2\nLine: %3\nCode: %4\nDesc: %5")
  313. .arg(QSPTools::qspStrToQt(loc))
  314. .arg(actIndex < 0 ? QString("on visit") : QString("on action"))
  315. .arg(line)
  316. .arg(code)
  317. .arg(desc);
  318. else
  319. errorMessage = QString("Code: %1\nDesc: %2")
  320. .arg(code)
  321. .arg(desc);
  322. QMessageBox dialog(QMessageBox::Critical, tr("Error"), errorMessage, QMessageBox::Ok, this);
  323. oldIsProcessEvents = m_isProcessEvents;
  324. m_isProcessEvents = false;
  325. dialog.exec();
  326. m_isProcessEvents = oldIsProcessEvents;
  327. if (m_isGameOpened) QSPCallBacks::RefreshInt(QSP_FALSE);
  328. }
  329. void MainWindow::SetShowPlainText(bool isPlain)
  330. {
  331. showPlainText = isPlain;
  332. _mainDescTextBox->SetShowPlainText(showPlainText);
  333. _descTextBox->SetShowPlainText(showPlainText);
  334. _actionsListBox->SetShowPlainText(showPlainText);
  335. _objectsListBox->SetShowPlainText(showPlainText);
  336. }
  337. void MainWindow::RefreshUI()
  338. {
  339. _mainDescTextBox->RefreshUI();
  340. _objectsListBox->RefreshUI();
  341. _actionsListBox->RefreshUI();
  342. _descTextBox->RefreshUI();
  343. //m_input->Refresh();
  344. m_imgView->RefreshUI();
  345. }
  346. void MainWindow::ApplyFont(const QFont &new_font, int fontType, int sizeType)
  347. {
  348. m_font = new_font;
  349. _mainDescTextBox->SetTextFont(new_font);
  350. _mainDescTextBox->SetFontType(fontType);
  351. _mainDescTextBox->SetSizeType(sizeType);
  352. _descTextBox->SetTextFont(new_font);
  353. _descTextBox->SetFontType(fontType);
  354. _descTextBox->SetSizeType(sizeType);
  355. _objectsListBox->SetTextFont(new_font);
  356. _actionsListBox->SetTextFont(new_font);
  357. }
  358. bool MainWindow::ApplyFontColor(const QColor &color)
  359. {
  360. m_fontColor = color;
  361. _mainDescTextBox->SetForegroundColor(color);
  362. _descTextBox->SetForegroundColor(color);
  363. _objectsListBox->SetForegroundColor(color);
  364. _actionsListBox->SetForegroundColor(color);
  365. return false;
  366. }
  367. bool MainWindow::ApplyBackColor(const QColor &color)
  368. {
  369. m_backColor = color;
  370. QPalette p = palette();
  371. p.setColor(QPalette::Base, color);
  372. setPalette(p);
  373. _mainDescTextBox->SetBackgroundColor(color);
  374. _descTextBox->SetBackgroundColor(color);
  375. _objectsListBox->SetBackgroundColor(color);
  376. _actionsListBox->SetBackgroundColor(color);
  377. m_imgView->SetBackgroundColor(color);
  378. return false;
  379. }
  380. bool MainWindow::ApplyLinkColor(const QColor &color)
  381. {
  382. m_linkColor = color;
  383. _mainDescTextBox->SetLinkColor(color);
  384. _descTextBox->SetLinkColor(color);
  385. _objectsListBox->SetLinkColor(color);
  386. _actionsListBox->SetLinkColor(color);
  387. return false;
  388. }
  389. void MainWindow::SetOverallVolume(float new_volume)
  390. {
  391. QSPCallBacks::SetOverallVolume(new_volume);
  392. m_volume = new_volume;
  393. }
  394. void MainWindow::SetDisableVideo(bool isDisableVideo)
  395. {
  396. disableVideo = isDisableVideo;
  397. #ifndef _WEBBOX_COMMON
  398. _mainDescTextBox->SetDisableVideo(disableVideo);
  399. _descTextBox->SetDisableVideo(disableVideo);
  400. #endif
  401. }
  402. void MainWindow::SetVideoFix(bool isFix)
  403. {
  404. m_videoFix = isFix;
  405. #ifdef _WEBBOX_COMMON
  406. _mainDescTextBox->SetVideoFix(m_videoFix);
  407. _descTextBox->SetVideoFix(m_videoFix);
  408. #endif
  409. }
  410. void MainWindow::SetAllowHTML5Extras(bool HTML5Extras)
  411. {
  412. m_isAllowHTML5Extras = HTML5Extras;
  413. QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
  414. }
  415. void MainWindow::SetUseCaseInsensitiveFilePath(bool CaseInsensitiveFilePath)
  416. {
  417. QSPTools::useCaseInsensitiveFilePath = CaseInsensitiveFilePath;
  418. }
  419. bool MainWindow::GetUseCaseInsensitiveFilePath()
  420. {
  421. return QSPTools::useCaseInsensitiveFilePath;
  422. }
  423. void MainWindow::LoadSettings(QString filePath)
  424. {
  425. QSettings *settings;
  426. if(filePath.isEmpty())
  427. settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName(), this);
  428. else
  429. settings = new QSettings(filePath, QSettings::IniFormat);
  430. restoreGeometry(settings->value("mainWindow/geometry").toByteArray());
  431. if ( isMaximized() )
  432. setGeometry( QApplication::desktop()->availableGeometry( this ) );
  433. restoreState(settings->value("mainWindow/windowState").toByteArray());
  434. if (settings->value("mainWindow/isMaximized", isMaximized()).toBool())
  435. showMaximized();
  436. if (settings->value("mainWindow/isFullScreen", isFullScreen()).toBool())
  437. showFullScreen();
  438. OnToggleCaptions(settings->value("mainWindow/showCaptions", showCaptions).toBool());
  439. SetShowPlainText(settings->value("application/isShowPlainText", showPlainText).toBool());
  440. SetLastPath(settings->value("application/lastPath", GetLastPath()).toString());
  441. perGameConfig = settings->value("application/perGameConfig", perGameConfig).toBool();
  442. m_isUseFontSize = settings->value("application/isUseFontSize", m_isUseFontSize).toBool();
  443. m_fontSize = settings->value("application/fontSize", m_fontSize).toInt();
  444. m_isUseFont = settings->value("application/isUseFont", m_isUseFont).toBool();
  445. if(m_isUseFont)
  446. ApplyFont(qvariant_cast<QFont>(settings->value("application/font", m_font)), 2, 2);
  447. m_isUseBackColor = settings->value("application/isUseBackColor", m_isUseBackColor).toBool();
  448. m_isUseLinkColor = settings->value("application/isUseLinkColor", m_isUseLinkColor).toBool();
  449. m_isUseFontColor = settings->value("application/isUseFontColor", m_isUseFontColor).toBool();
  450. if(m_isUseBackColor)
  451. ApplyBackColor(qvariant_cast<QColor>(settings->value("application/backColor", m_backColor)));
  452. if(m_isUseLinkColor)
  453. ApplyLinkColor(qvariant_cast<QColor>(settings->value("application/linkColor", m_linkColor)));
  454. if(m_isUseFontColor)
  455. ApplyFontColor(qvariant_cast<QColor>(settings->value("application/fontColor", m_fontColor)));
  456. m_settingsBackColor = qvariant_cast<QColor>(settings->value("application/backColor", m_backColor));
  457. m_settingsLinkColor = qvariant_cast<QColor>(settings->value("application/linkColor", m_linkColor));
  458. m_settingsFontColor = qvariant_cast<QColor>(settings->value("application/fontColor", m_fontColor));
  459. disableVideo = settings->value("application/disableVideo", disableVideo).toBool();
  460. SetDisableVideo(disableVideo);
  461. m_videoFix = settings->value("application/videoFix", m_videoFix).toBool();
  462. SetVideoFix(m_videoFix);
  463. lastGame = settings->value("application/lastGame", lastGame).toString();
  464. autostartLastGame = settings->value("application/autostartLastGame", autostartLastGame).toBool();
  465. m_volume = settings->value("application/volume", m_volume).toFloat();
  466. SetOverallVolume(m_volume);
  467. m_isShowHotkeys = settings->value("application/isShowHotkeys", m_isShowHotkeys).toBool();
  468. m_isAllowHTML5Extras = settings->value("application/isAllowHTML5Extras", m_isAllowHTML5Extras).toBool();
  469. QSPTools::useCaseInsensitiveFilePath = settings->value("application/useCaseInsensitiveFilePath", QSPTools::useCaseInsensitiveFilePath).toBool();
  470. langid = settings->value("application/language", langid).toString();
  471. RefreshUI();
  472. delete settings;
  473. }
  474. void MainWindow::SaveSettings(QString filePath)
  475. {
  476. QSettings *settings;
  477. if(filePath.isEmpty())
  478. settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName(), this);
  479. else
  480. settings = new QSettings(filePath, QSettings::IniFormat);
  481. bool maximized = isMaximized();
  482. bool fullscreen = isFullScreen();
  483. settings->setValue("mainWindow/geometry", saveGeometry());
  484. settings->setValue("mainWindow/windowState", saveState());
  485. settings->setValue("mainWindow/isMaximized", maximized);
  486. settings->setValue("mainWindow/isFullScreen", fullscreen);
  487. settings->setValue("mainWindow/showCaptions", showCaptions);
  488. settings->setValue("application/isShowPlainText", showPlainText);
  489. settings->setValue("application/lastPath", lastPath);
  490. settings->setValue("application/perGameConfig", perGameConfig);
  491. settings->setValue("application/isUseFontSize", m_isUseFontSize);
  492. settings->setValue("application/fontSize", m_fontSize);
  493. settings->setValue("application/isUseFont", m_isUseFont);
  494. settings->setValue("application/font", m_font);
  495. settings->setValue("application/isUseBackColor", m_isUseBackColor);
  496. settings->setValue("application/isUseLinkColor", m_isUseLinkColor);
  497. settings->setValue("application/isUseFontColor", m_isUseFontColor);
  498. settings->setValue("application/backColor", m_settingsBackColor);
  499. settings->setValue("application/linkColor", m_settingsLinkColor);
  500. settings->setValue("application/fontColor", m_settingsFontColor);
  501. settings->setValue("application/disableVideo", disableVideo);
  502. settings->setValue("application/videoFix", m_videoFix);
  503. settings->setValue("application/lastGame", lastGame);
  504. settings->setValue("application/autostartLastGame", autostartLastGame);
  505. settings->setValue("application/volume", m_volume);
  506. settings->setValue("application/isShowHotkeys", m_isShowHotkeys);
  507. settings->setValue("application/isAllowHTML5Extras", m_isAllowHTML5Extras);
  508. settings->setValue("application/useCaseInsensitiveFilePath", QSPTools::useCaseInsensitiveFilePath);
  509. settings->setValue("application/language", langid);
  510. settings->sync();
  511. delete settings;
  512. }
  513. void MainWindow::CreateMenuBar()
  514. {
  515. QAction* action;
  516. //------------------------------------------------------------------
  517. // File menu
  518. _fileMenu = menuBar()->addMenu(tr("&Quest"));
  519. // Open item
  520. action = _fileMenu->addAction(QIcon(":/gfx/menu/open"), tr("Open game..."),
  521. this, SLOT(OnOpenGame()), QKeySequence(Qt::ALT + Qt::Key_O));
  522. mainToolBar->addAction(action);
  523. // New game item
  524. action = _fileMenu->addAction(QIcon(":/gfx/menu/new"),tr("Restart game"),
  525. this, SLOT(OnRestartGame()), QKeySequence(Qt::ALT + Qt::Key_N));
  526. mainToolBar->addAction(action);
  527. _fileMenu->addSeparator();
  528. mainToolBar->addSeparator();
  529. // Exit item
  530. action = _fileMenu->addAction(QIcon(":/gfx/menu/exit"), tr("Exit"),
  531. this, SLOT(close()), QKeySequence(Qt::ALT + Qt::Key_X));
  532. mainToolBar->addAction(action);
  533. //------------------------------------------------------------------
  534. mainToolBar->addSeparator();
  535. // Game menu
  536. _gameMenu = menuBar()->addMenu(tr("&Game"));
  537. // Open saved game item
  538. action = _gameMenu->addAction(QIcon(":/gfx/menu/statusopen"), tr("Open saved game..."),
  539. this, SLOT(OnOpenSavedGame()), QKeySequence(Qt::CTRL + Qt::Key_O));
  540. mainToolBar->addAction(action);
  541. // Save game item
  542. action = _gameMenu->addAction(QIcon(":/gfx/menu/statussave"), tr("Save game..."),
  543. this, SLOT(OnSaveGame()), QKeySequence(Qt::CTRL + Qt::Key_S));
  544. mainToolBar->addAction(action);
  545. // Open quicksave item
  546. action = _gameMenu->addAction(tr("Quick Load"),
  547. this, SLOT(OnOpenQuickSavedGame()), QKeySequence(Qt::Key_F9));
  548. mainToolBar->addAction(action);
  549. // Quicksave item
  550. action = _gameMenu->addAction(tr("Quick Save"),
  551. this, SLOT(OnQuickSaveGame()), QKeySequence(Qt::Key_F5));
  552. mainToolBar->addAction(action);
  553. //------------------------------------------------------------------
  554. mainToolBar->addSeparator();
  555. // Settings menu
  556. _settingsMenu = menuBar()->addMenu(tr("&Settings"));
  557. // Show / Hide submenu
  558. _showHideMenu = _settingsMenu->addMenu(tr("Show / Hide"));
  559. // Objects item
  560. action = _objectsWidget->toggleViewAction();
  561. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
  562. _showHideMenu->addAction(action);
  563. // Actions item
  564. action = _actionsWidget->toggleViewAction();
  565. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
  566. _showHideMenu->addAction(action);
  567. // Additional desc item
  568. action = _descWidget->toggleViewAction();
  569. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
  570. _showHideMenu->addAction(action);
  571. // Input area item
  572. action = _inputWidget->toggleViewAction();
  573. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_4));
  574. _showHideMenu->addAction(action);
  575. // Main desc item
  576. action = _mainDescWidget->toggleViewAction();
  577. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_5));
  578. _showHideMenu->addAction(action);
  579. // Image item
  580. action = _imgViewWidget->toggleViewAction();
  581. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6));
  582. _showHideMenu->addAction(action);
  583. _showHideMenu->addSeparator();
  584. // Captions item
  585. action = _showHideMenu->addAction(tr("Captions"));
  586. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6));
  587. action->setCheckable(true);
  588. if(_objectsWidget->titleBarWidget() == 0)
  589. action->setChecked(true);
  590. else
  591. action->setChecked(false);
  592. connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleCaptions(bool)));
  593. // ToolBar
  594. action = mainToolBar->toggleViewAction();
  595. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7));
  596. _showHideMenu->addAction(action);
  597. //TODO: MenuBar
  598. // MenuBar
  599. //action = _showHideMenu->addAction(tr("MenuBar"));
  600. //action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7));
  601. //action->setCheckable(true);
  602. //if(mainMenuBar->isVisible())
  603. // action->setChecked(true);
  604. //else
  605. // action->setChecked(false);
  606. //connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleMenuBar(bool)));
  607. // Hotkeys for actions item
  608. action = _showHideMenu->addAction(tr("Hotkeys for actions"));
  609. action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_8));
  610. action->setCheckable(true);
  611. action->setChecked(m_isShowHotkeys);
  612. connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleHotkeys(bool)));
  613. // Window / Fullscreen mode item
  614. action = _settingsMenu->addAction(QIcon(":/gfx/menu/windowmode"), tr("Window / Fullscreen mode"),
  615. this, SLOT(OnToggleWinMode()), QKeySequence(Qt::Key_F11));
  616. mainToolBar->addAction(action);
  617. _settingsMenu->addSeparator();
  618. mainToolBar->addSeparator();
  619. // Display HTML code as plain text
  620. action = _settingsMenu->addAction(tr("Display HTML code as plain text"));
  621. action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_D));
  622. action->setCheckable(true);
  623. action->setChecked(showPlainText);
  624. connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleShowPlainText(bool)));
  625. // _settingsMenu->addAction(tr("Display HTML code as plain text"),
  626. // this, SLOT(OnToggleShowPlainText()), QKeySequence(Qt::ALT + Qt::Key_D))->setCheckable(true);
  627. _settingsMenu->addSeparator();
  628. // Options item
  629. action = _settingsMenu->addAction(tr("Options..."),
  630. this, SLOT(OnOptions()), QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_O));
  631. //mainToolBar->addAction(action);
  632. //------------------------------------------------------------------
  633. //mainToolBar->addSeparator();
  634. // Help menu
  635. QMenu* helpMenu(menuBar()->addMenu(tr("&Help")));
  636. // About item
  637. action = helpMenu->addAction(QIcon(":/gfx/menu/about"), tr("About..."),
  638. this, SLOT(OnAbout()), QKeySequence(Qt::CTRL + Qt::Key_H));
  639. mainToolBar->addAction(action);
  640. }
  641. void MainWindow::CreateDockWindows()
  642. {
  643. // "Main desc" widget
  644. #ifndef _WEBBOX_COMMON
  645. _mainDescTextBox = new QspTextBox(this);
  646. connect(_mainDescTextBox, SIGNAL(anchorClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  647. #endif
  648. #ifdef _WEBBOX
  649. _mainDescTextBox = new QspWebBox(this);
  650. connect(_mainDescTextBox, SIGNAL(qspLinkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  651. #endif
  652. #ifdef _WEBBOX_WEBKIT
  653. _mainDescTextBox = new QspWebBox(this);
  654. connect(_mainDescTextBox, SIGNAL(linkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  655. _mainDescTextBox->load(QUrl("qsp:/"));
  656. {
  657. QEventLoop loop;
  658. connect(_mainDescTextBox,SIGNAL(loadFinished(bool)),&loop,SLOT(quit()));
  659. loop.exec();
  660. }
  661. #endif
  662. _mainDescTextBox->setObjectName(QStringLiteral("_mainDescTextBox"));
  663. _mainDescWidget = new QDockWidget(tr("Main desc"), this);
  664. _mainDescWidget->setObjectName(QStringLiteral("_mainDescWidget"));
  665. addDockWidget(Qt::TopDockWidgetArea, _mainDescWidget, Qt::Vertical);
  666. _mainDescWidget->setWidget(_mainDescTextBox);
  667. // "Objects" widget
  668. _objectsWidget = new QDockWidget(tr("Objects"), this);
  669. _objectsWidget->setObjectName(QStringLiteral("_objectsWidget"));
  670. addDockWidget(Qt::RightDockWidgetArea, _objectsWidget, Qt::Vertical);
  671. _objectsListBox = new QspListBox(this);
  672. _objectsListBox->setObjectName(QStringLiteral("_objectsListBox"));
  673. connect(_objectsListBox, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(OnObjectListBoxItemClicked(QListWidgetItem *)));
  674. //connect(_objectsListBox, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(OnObjectListBoxItemClicked(QListWidgetItem *)));
  675. connect(_objectsListBox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(OnObjectListBoxItemClicked(QListWidgetItem *)));
  676. //connect(_objectsListBox, SIGNAL(currentRowChanged(int)), this, SLOT(OnObjectChange(int)));
  677. _objectsWidget->setWidget(_objectsListBox);
  678. // "Actions" widget
  679. _actionsWidget = new QDockWidget(tr("Actions"), this);
  680. _actionsWidget->setObjectName(QStringLiteral("_actionsWidget"));
  681. addDockWidget(Qt::BottomDockWidgetArea, _actionsWidget, Qt::Vertical);
  682. _actionsListBox = new QspListBox(this);
  683. _actionsListBox->setObjectName(QStringLiteral("_actionsListBox"));
  684. connect(_actionsListBox, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(OnActionsListBoxItemClicked(QListWidgetItem *)));
  685. //connect(_actionsListBox, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(OnActionsListBoxItemClicked(QListWidgetItem *)));
  686. connect(_actionsListBox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(OnActionsListBoxItemClicked(QListWidgetItem *)));
  687. connect(_actionsListBox, SIGNAL(SelectionChange(int)), this, SLOT(OnActionChange(int)));
  688. _actionsListBox->SetMouseTracking(true);
  689. _actionsWidget->setWidget(_actionsListBox);
  690. // "Additional desc" widget
  691. _descWidget = new QDockWidget(tr("Additional desc"), this);
  692. _descWidget->setObjectName(QStringLiteral("_descWidget"));
  693. addDockWidget(Qt::BottomDockWidgetArea, _descWidget, Qt::Horizontal);
  694. #ifndef _WEBBOX_COMMON
  695. _descTextBox = new QspTextBox(this);
  696. connect(_descTextBox, SIGNAL(anchorClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  697. #endif
  698. #ifdef _WEBBOX
  699. _descTextBox = new QspWebBox(this);
  700. connect(_descTextBox, SIGNAL(qspLinkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  701. #endif
  702. #ifdef _WEBBOX_WEBKIT
  703. _descTextBox = new QspWebBox(this);
  704. connect(_descTextBox, SIGNAL(linkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  705. _descTextBox->load(QUrl("qsp:/"));
  706. {
  707. QEventLoop loop;
  708. connect(_descTextBox,SIGNAL(loadFinished(bool)),&loop,SLOT(quit()));
  709. loop.exec();
  710. }
  711. #endif
  712. _descTextBox->setObjectName(QStringLiteral("_descTextBox"));
  713. _descWidget->setWidget(_descTextBox);
  714. // "Input area" widget
  715. _inputWidget = new QDockWidget(tr("Input area"), this);
  716. _inputWidget->setObjectName(QStringLiteral("_inputWidget"));
  717. addDockWidget(Qt::BottomDockWidgetArea, _inputWidget, Qt::Vertical);
  718. _inputTextBox = new QspInputBox(this);
  719. _inputTextBox->setObjectName(QStringLiteral("_inputTextBox"));
  720. _inputWidget->setWidget(_inputTextBox);
  721. connect(_inputTextBox, SIGNAL(textChanged()), this, SLOT(OnInputTextChange()));
  722. connect(_inputTextBox, SIGNAL(InputTextEnter()), this, SLOT(OnInputTextEnter()));
  723. m_imgView = new QspImgCanvas(this);
  724. m_imgView->setObjectName(QStringLiteral("m_imgView"));
  725. _imgViewWidget = new QDockWidget(tr("Image"), this);
  726. _imgViewWidget->setObjectName(QStringLiteral("_imgViewWidget"));
  727. _imgViewWidget->setWidget(m_imgView);
  728. addDockWidget(Qt::BottomDockWidgetArea, _imgViewWidget, Qt::Vertical);
  729. splitDockWidget(_actionsWidget, _inputWidget, Qt::Vertical);
  730. splitDockWidget(_mainDescWidget, _objectsWidget, Qt::Horizontal);
  731. }
  732. void MainWindow::closeEvent(QCloseEvent *event)
  733. {
  734. #ifdef _WEBBOX
  735. _mainDescTextBox->Quit();
  736. _descTextBox->Quit();
  737. //delete _mainDescTextBox;
  738. //delete _descTextBox;
  739. #endif
  740. if(!m_configPath.isEmpty())
  741. SaveSettings(m_configPath);
  742. QFileInfo settingsFile(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  743. if(settingsFile.exists() && settingsFile.isFile())
  744. {
  745. SaveSettings(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  746. }
  747. else
  748. {
  749. SaveSettings();
  750. }
  751. EnableControls(false, true);
  752. setVisible(false);
  753. m_isQuit = true;
  754. QSPDeInit();
  755. QSPCallBacks::DeInit();
  756. QCoreApplication::processEvents();
  757. QMainWindow::closeEvent(event);
  758. }
  759. void MainWindow::keyPressEvent(QKeyEvent *event)
  760. {
  761. int action = -1;
  762. if(event->key() == Qt::Key_1)
  763. if(_actionsListBox->count() >= 1)
  764. action = 0;
  765. if(event->key() == Qt::Key_2)
  766. if(_actionsListBox->count() >= 2)
  767. action = 1;
  768. if(event->key() == Qt::Key_3)
  769. if(_actionsListBox->count() >= 3)
  770. action = 2;
  771. if(event->key() == Qt::Key_4)
  772. if(_actionsListBox->count() >= 4)
  773. action = 3;
  774. if(event->key() == Qt::Key_5)
  775. if(_actionsListBox->count() >= 5)
  776. action = 4;
  777. if(event->key() == Qt::Key_6)
  778. if(_actionsListBox->count() >= 6)
  779. action = 5;
  780. if(event->key() == Qt::Key_7)
  781. if(_actionsListBox->count() >= 7)
  782. action = 6;
  783. if(event->key() == Qt::Key_8)
  784. if(_actionsListBox->count() >= 8)
  785. action = 7;
  786. if(event->key() == Qt::Key_9)
  787. if(_actionsListBox->count() >= 9)
  788. action = 8;
  789. if(event->key() == Qt::Key_0)
  790. if(_actionsListBox->count() >= 10)
  791. action = 9;
  792. if(action != -1)
  793. {
  794. if (!QSPSetSelActionIndex(action, QSP_TRUE))
  795. ShowError();
  796. if (!QSPExecuteSelActionCode(QSP_TRUE))
  797. ShowError();
  798. return;
  799. }
  800. if(event->key() == Qt::Key_Up)
  801. {
  802. if(_actionsListBox->count()!=0)
  803. {
  804. int newSel = _actionsListBox->GetSelection() - 1;
  805. if(newSel < 0)
  806. _actionsListBox->SetSelection(_actionsListBox->count()-1);
  807. else
  808. _actionsListBox->SetSelection(newSel);
  809. }
  810. return;
  811. }
  812. if(event->key() == Qt::Key_Down)
  813. {
  814. if(_actionsListBox->count()!=0)
  815. {
  816. int newSel = _actionsListBox->GetSelection() + 1;
  817. if(newSel <= 0 || newSel >= _actionsListBox->count())
  818. _actionsListBox->SetSelection(0);
  819. else
  820. _actionsListBox->SetSelection(newSel);
  821. }
  822. return;
  823. }
  824. if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
  825. if(_actionsListBox->GetSelection() != -1)
  826. {
  827. ActionsListBoxDoAction(_actionsListBox->GetSelection());
  828. return;
  829. }
  830. if(event->key() == Qt::Key_Escape)
  831. if(isFullScreen())
  832. showNormal();
  833. #ifndef _WEBBOX_COMMON
  834. _descTextBox->keyPressEvent(event);
  835. _mainDescTextBox->keyPressEvent(event);
  836. #endif
  837. QMainWindow::keyPressEvent(event);
  838. }
  839. void MainWindow::OpenGameFile(const QString &path)
  840. {
  841. if(!path.isEmpty())
  842. {
  843. QFileInfo fileName(path);
  844. QSPCallBacks::m_gamePath = fileName.canonicalPath();
  845. if(!QSPCallBacks::m_gamePath.endsWith("/")) QSPCallBacks::m_gamePath+="/";
  846. _mainDescTextBox->SetGamePath(QSPCallBacks::m_gamePath);
  847. _objectsListBox->SetGamePath(QSPCallBacks::m_gamePath);
  848. _actionsListBox->SetGamePath(QSPCallBacks::m_gamePath);
  849. _descTextBox->SetGamePath(QSPCallBacks::m_gamePath);
  850. if (QSPLoadGameWorld(qspStringFromQString(path)))
  851. {
  852. m_isGameOpened = true;
  853. lastGame = path;
  854. QFileInfo file(path);
  855. QString filePath(file.canonicalPath());
  856. if(!filePath.endsWith("/")) filePath+="/";
  857. QString configString(filePath + QSP_CONFIG);
  858. if (configString != m_configPath && perGameConfig)
  859. {
  860. if(m_configPath.isEmpty())
  861. {
  862. QFileInfo settingsFile(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  863. if(settingsFile.exists() && settingsFile.isFile())
  864. {
  865. SaveSettings(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  866. }
  867. else
  868. {
  869. SaveSettings();
  870. }
  871. }
  872. else
  873. {
  874. SaveSettings(m_configPath);
  875. }
  876. m_configPath = configString;
  877. QFileInfo configFile(configString);
  878. if(configFile.exists() && configFile.isFile())
  879. LoadSettings(configString);
  880. }
  881. if(!m_isUseBackColor)
  882. ApplyBackColor(m_defaultBackColor);
  883. if(!m_isUseLinkColor)
  884. ApplyLinkColor(m_defaultLinkColor);
  885. if(!m_isUseFontColor)
  886. ApplyFontColor(m_defaultFontColor);
  887. if(!m_isUseFont)
  888. ApplyFont(m_defaultFont, 0, 0);
  889. QFileInfo cssFile(filePath + "custom.css");
  890. if(cssFile.exists() && cssFile.isFile())
  891. {
  892. _mainDescTextBox->SetCustomCSS(true);
  893. _descTextBox->SetCustomCSS(true);
  894. }
  895. else
  896. {
  897. _mainDescTextBox->SetCustomCSS(false);
  898. _descTextBox->SetCustomCSS(false);
  899. }
  900. UpdateGamePath(filePath);
  901. OnNewGame();
  902. if (m_isQuit) return;
  903. //UpdateTitle();
  904. EnableControls(true);
  905. m_savedGamePath.clear();
  906. ApplyParams();
  907. }
  908. else
  909. ShowError();
  910. }
  911. }
  912. void MainWindow::ActionsListBoxDoAction(int action)
  913. {
  914. if(m_isProcessEvents)
  915. {
  916. if(action != -1)
  917. {
  918. if (!QSPSetSelActionIndex(action, QSP_TRUE))
  919. ShowError();
  920. if (!QSPExecuteSelActionCode(QSP_TRUE))
  921. ShowError();
  922. }
  923. }
  924. }
  925. void MainWindow::dropEvent(QDropEvent *event)
  926. {
  927. if (event->mimeData()->hasUrls())
  928. {
  929. if(event->mimeData()->urls().count() > 0)
  930. {
  931. if(event->mimeData()->urls().at(0).toLocalFile().endsWith(".qsp"))
  932. {
  933. OpenGameFile(event->mimeData()->urls().at(0).toLocalFile());
  934. event->acceptProposedAction();
  935. }
  936. if(event->mimeData()->urls().at(0).toLocalFile().endsWith(".sav"))
  937. {
  938. if(m_isGameOpened)
  939. {
  940. if (!QSPOpenSavedGame(qspStringFromQString(event->mimeData()->urls().at(0).toLocalFile()), QSP_TRUE))
  941. ShowError();
  942. else
  943. ApplyParams();
  944. }
  945. event->acceptProposedAction();
  946. }
  947. }
  948. }
  949. }
  950. void MainWindow::dragEnterEvent(QDragEnterEvent *event)
  951. {
  952. event->accept();
  953. }
  954. void MainWindow::OnOpenGame()
  955. {
  956. #ifndef _ANDROIDQT
  957. #ifndef _NONATIVEDIALOG
  958. QString path = QFileDialog::getOpenFileName(this, tr("Select game file"), GetLastPath(), tr("QSP games (*.qsp *.gam)"));
  959. #else
  960. QString path = QFileDialog::getOpenFileName(this, tr("Select game file"), GetLastPath(), tr("QSP games (*.qsp *.gam)"), nullptr, QFileDialog::DontUseNativeDialog);
  961. #endif
  962. if (!path.isEmpty())
  963. {
  964. SetLastPath(QFileInfo(path).canonicalPath());
  965. OpenGameFile(path);
  966. }
  967. #else
  968. QString path = QFileDialog::getOpenFileName(this, tr("Select game file"), QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).at(0), tr("QSP games (*.qsp *.gam)"));
  969. if (!path.isEmpty())
  970. {
  971. SetLastPath(QFileInfo(path).canonicalPath());
  972. OpenGameFile(path);
  973. }
  974. return;
  975. AndroidFileDialog fileDialog;
  976. connect(&fileDialog, SIGNAL(existingFileNameReady(QString)), this, SLOT(OpenGameFile(QString)));
  977. bool success = fileDialog.provideExistingFileName();
  978. if (!success) {
  979. qDebug() << "Problem with JNI or sth like that...";
  980. disconnect(fileDialog, SIGNAL(existingFileNameReady(QString)), this, SLOT(OpenGameFile(QString)));
  981. //or just delete fileDialog instead of disconnect
  982. }
  983. #endif
  984. }
  985. void MainWindow::OnRestartGame()
  986. {
  987. if(m_isGameOpened)
  988. {
  989. if (!QSPRestartGame(QSP_TRUE))
  990. ShowError();
  991. else
  992. ApplyParams();
  993. }
  994. }
  995. void MainWindow::OnOpenSavedGame()
  996. {
  997. if(!m_isGameOpened)
  998. return;
  999. #ifndef _NONATIVEDIALOG
  1000. QString path = QFileDialog::getOpenFileName(this, tr("Select saved game file"), GetLastPath(), tr("Saved game files (*.sav)"));
  1001. #else
  1002. QString path = QFileDialog::getOpenFileName(this, tr("Select saved game file"), GetLastPath(), tr("Saved game files (*.sav)"), nullptr, QFileDialog::DontUseNativeDialog);
  1003. #endif
  1004. if (!path.isEmpty())
  1005. {
  1006. SetLastPath(QFileInfo(path).canonicalPath());
  1007. if (!QSPOpenSavedGame(qspStringFromQString(path), QSP_TRUE))
  1008. ShowError();
  1009. else
  1010. ApplyParams();
  1011. }
  1012. }
  1013. void MainWindow::OnSaveGame()
  1014. {
  1015. if(!m_isGameOpened)
  1016. return;
  1017. #ifndef _NONATIVEDIALOG
  1018. QString path = QFileDialog::getSaveFileName(this, tr("Select file to save"), GetLastPath(), tr("Saved game files (*.sav)"));
  1019. #else
  1020. QString path = QFileDialog::getSaveFileName(this, tr("Select file to save"), GetLastPath(), tr("Saved game files (*.sav)"), nullptr, QFileDialog::DontUseNativeDialog);
  1021. #endif
  1022. if (!path.isEmpty())
  1023. {
  1024. if(!path.endsWith(".sav"))
  1025. path.append(".sav");
  1026. QString p = GetLastPath();
  1027. if (QSPSaveGame(qspStringFromQString(path), QSP_TRUE))
  1028. {
  1029. SetLastPath(QFileInfo(path).canonicalPath());
  1030. m_savedGamePath = path;
  1031. }
  1032. else
  1033. ShowError();
  1034. }
  1035. }
  1036. void MainWindow::OnOpenQuickSavedGame()
  1037. {
  1038. if(!m_isGameOpened)
  1039. return;
  1040. QString path = m_path + QSP_QUICKSAVE;
  1041. QFileInfo fileInfo(path);
  1042. if(fileInfo.exists() && fileInfo.isFile())
  1043. {
  1044. if (!QSPOpenSavedGame(qspStringFromQString(path), QSP_TRUE))
  1045. ShowError();
  1046. else
  1047. ApplyParams();
  1048. }
  1049. }
  1050. void MainWindow::OnQuickSaveGame()
  1051. {
  1052. if(!m_isGameOpened)
  1053. return;
  1054. QString path = m_path + QSP_QUICKSAVE;
  1055. if (QSPSaveGame(qspStringFromQString(path), QSP_TRUE))
  1056. m_savedGamePath = path;
  1057. else
  1058. ShowError();
  1059. }
  1060. void MainWindow::OnOptions()
  1061. {
  1062. OptionsDialog optdlg(this);
  1063. optdlg.exec();
  1064. if(!m_configPath.isEmpty())
  1065. SaveSettings(m_configPath);
  1066. QFileInfo settingsFile(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  1067. if(settingsFile.exists() && settingsFile.isFile())
  1068. {
  1069. SaveSettings(QApplication::applicationDirPath() + "/" + QSP_CUSTOM_CONFIG);
  1070. }
  1071. else
  1072. {
  1073. SaveSettings();
  1074. }
  1075. }
  1076. void MainWindow::OnAbout()
  1077. {
  1078. QPixmap icon = QPixmap(":/gfx/logo");
  1079. icon = icon.scaledToHeight(64, Qt::SmoothTransformation);
  1080. QString version(QSPTools::qspStrToQt(QSPGetVersion()));
  1081. QString libCompiledDate(QSPTools::qspStrToQt(QSPGetCompiledDateTime()));
  1082. QString guiCompiledDate(tr(__DATE__) + tr(", ") + tr(__TIME__));
  1083. QString text = (tr("<h2>Qqsp</h2>"
  1084. "<p>Copyright &copy; 2017-2019, Sonnix</p>"));
  1085. text += tr("<p>Application version: %1<br>QSP library version: %2<br>Qt library version: %3<br>Application compilation date: %4<br>Library compilation date: %5</p>").arg(QApplication::applicationVersion(), version, QT_VERSION_STR, guiCompiledDate, libCompiledDate);
  1086. QMessageBox dlg(QMessageBox::NoIcon, tr("About"), text, QMessageBox::Ok);
  1087. dlg.setIconPixmap(icon);
  1088. dlg.exec();
  1089. }
  1090. void MainWindow::OnToggleCaptions(bool checked)
  1091. {
  1092. showCaptions = checked;
  1093. QWidget* mainTitleBarWidget = _mainDescWidget->titleBarWidget();
  1094. QWidget* objectsTitleBarWidget = _objectsWidget->titleBarWidget();
  1095. QWidget* actionsTitleBarWidget = _actionsWidget->titleBarWidget();
  1096. QWidget* descTitleBarWidget = _descWidget->titleBarWidget();
  1097. QWidget* inputTitleBarWidget = _inputWidget->titleBarWidget();
  1098. if(checked == false)
  1099. {
  1100. _mainDescWidget->setTitleBarWidget(new QWidget(_mainDescWidget));
  1101. _mainDescWidget->titleBarWidget()->hide();
  1102. _objectsWidget->setTitleBarWidget(new QWidget(_objectsWidget));
  1103. _objectsWidget->titleBarWidget()->hide();
  1104. _actionsWidget->setTitleBarWidget(new QWidget(_actionsWidget));
  1105. _actionsWidget->titleBarWidget()->hide();
  1106. _descWidget->setTitleBarWidget(new QWidget(_descWidget));
  1107. _descWidget->titleBarWidget()->hide();
  1108. _inputWidget->setTitleBarWidget(new QWidget(_inputWidget));
  1109. _inputWidget->titleBarWidget()->hide();
  1110. }
  1111. else
  1112. {
  1113. _mainDescWidget->setTitleBarWidget(0);
  1114. _objectsWidget->setTitleBarWidget(0);
  1115. _actionsWidget->setTitleBarWidget(0);
  1116. _descWidget->setTitleBarWidget(0);
  1117. _inputWidget->setTitleBarWidget(0);
  1118. }
  1119. if(mainTitleBarWidget)
  1120. delete mainTitleBarWidget;
  1121. if(objectsTitleBarWidget)
  1122. delete objectsTitleBarWidget;
  1123. if(actionsTitleBarWidget)
  1124. delete actionsTitleBarWidget;
  1125. if(descTitleBarWidget)
  1126. delete descTitleBarWidget;
  1127. if(inputTitleBarWidget)
  1128. delete inputTitleBarWidget;
  1129. }
  1130. void MainWindow::OnToggleMenuBar(bool checked)
  1131. {
  1132. mainMenuBar->setVisible(checked);
  1133. }
  1134. void MainWindow::OnToggleHotkeys(bool checked)
  1135. {
  1136. m_isShowHotkeys = checked;
  1137. RefreshUI();
  1138. }
  1139. void MainWindow::OnToggleWinMode()
  1140. {
  1141. if(isFullScreen())
  1142. {
  1143. showNormal();
  1144. }
  1145. else
  1146. {
  1147. showFullScreen();
  1148. }
  1149. }
  1150. void MainWindow::OnToggleShowPlainText(bool checked)
  1151. {
  1152. SetShowPlainText(checked);
  1153. }
  1154. void MainWindow::OnNewGame()
  1155. {
  1156. if (!QSPRestartGame(QSP_TRUE))
  1157. ShowError();
  1158. }
  1159. void MainWindow::OnTimer()
  1160. {
  1161. if (m_isProcessEvents && !QSPExecCounter(QSP_TRUE))
  1162. ShowError();
  1163. }
  1164. void MainWindow::OnLinkClicked(const QUrl &url)
  1165. {
  1166. if(!m_isProcessEvents)
  1167. return;
  1168. QString href;
  1169. href = QByteArray::fromPercentEncoding(url.toString().toUtf8());
  1170. if (href.startsWith("#"))
  1171. {
  1172. QObject* obj = sender();
  1173. if (obj == _mainDescTextBox)
  1174. #ifndef _WEBBOX_COMMON
  1175. _mainDescTextBox->setSource(url);
  1176. #else
  1177. _mainDescTextBox->setUrl(url);
  1178. #endif
  1179. else
  1180. #ifndef _WEBBOX_COMMON
  1181. _descTextBox->setSource(url);
  1182. #else
  1183. _descTextBox->setUrl(url);
  1184. #endif
  1185. }
  1186. else if (href.startsWith("EXEC:", Qt::CaseInsensitive))
  1187. {
  1188. QString string = href.mid(5);
  1189. if (m_isProcessEvents && !QSPExecString(qspStringFromQString(string), QSP_TRUE))
  1190. ShowError();
  1191. }
  1192. else
  1193. {
  1194. QDesktopServices::openUrl(url);
  1195. }
  1196. }
  1197. void MainWindow::OnObjectListBoxItemClicked(QListWidgetItem *itemClicked)
  1198. {
  1199. if(!m_isProcessEvents)
  1200. return;
  1201. int object = _objectsListBox->row(itemClicked);
  1202. if (!QSPSetSelObjectIndex(object, QSP_TRUE))
  1203. ShowError();
  1204. }
  1205. void MainWindow::OnActionsListBoxItemClicked(QListWidgetItem *itemClicked)
  1206. {
  1207. if(!m_isProcessEvents)
  1208. return;
  1209. int action = _actionsListBox->row(itemClicked);
  1210. ActionsListBoxDoAction(action);
  1211. }
  1212. void MainWindow::OnObjectChange(int currentRow)
  1213. {
  1214. if(!m_isProcessEvents)
  1215. return;
  1216. //QThread::msleep(20);
  1217. if (!QSPSetSelObjectIndex(currentRow, QSP_TRUE))
  1218. ShowError();
  1219. }
  1220. void MainWindow::OnActionChange(int currentRow)
  1221. {
  1222. if(!m_isProcessEvents)
  1223. return;
  1224. if (!QSPSetSelActionIndex(currentRow, QSP_TRUE))
  1225. ShowError();
  1226. }
  1227. void MainWindow::OnMenu(QAction* action)
  1228. {
  1229. m_menuIndex = action->data().toInt();
  1230. }
  1231. void MainWindow::OnInputTextChange()
  1232. {
  1233. QSPSetInputStrText(qspStringFromQString(_inputTextBox->GetText()));
  1234. }
  1235. void MainWindow::OnInputTextEnter()
  1236. {
  1237. if(!m_isProcessEvents)
  1238. return;
  1239. QSPSetInputStrText(qspStringFromQString(_inputTextBox->GetText()));
  1240. if (!QSPExecUserInput(QSP_TRUE))
  1241. ShowError();
  1242. }