mainwindow.cpp 42 KB

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