1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303 |
- #include "mainwindow.h"
- #include <QSettings>
- #include <QApplication>
- #include <QFileInfo>
- #include <QFileDialog>
- #include <QMessageBox>
- #include <QThread>
- #include <QCursor>
- #include <QPalette>
- #include <QFontDialog>
- #include <QIcon>
- #include <QDesktopServices>
- #include <QLocale>
- #include <QInputDialog>
- #include <QMimeData>
- #include <QDesktopWidget>
- #include "callbacks_gui.h"
- #include "comtools.h"
- #include "optionsdialog.h"
- #ifdef _ANDROIDQT
- #include <QStandardPaths>
- #include "androidfiledialog.h"
- #endif
- MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
- {
- resize(600, 450);
- setMinimumSize(240, 180);
- setWindowTitle(QSP_LOGO);
- setWindowIcon(QIcon(":/gfx/logo"));
- setUnifiedTitleAndToolBarOnMac(true);
- setDockNestingEnabled(true);
- setFocusPolicy(Qt::StrongFocus);
- setObjectName(QStringLiteral("MainWindow"));
- setAcceptDrops(true);
- #ifdef _WEBBOX
- // qwuri = new QspWebEngineUrlRequestInterceptor();
- // QWebEngineProfile::defaultProfile()->setRequestInterceptor(qwuri);
- // QspWebEngineUrlSchemeHandler *qweush = new QspWebEngineUrlSchemeHandler();
- // QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(QByteArray("qsp"),qweush);
- #endif
- m_palette = palette();
- mainMenuBar = new QMenuBar(this);
- setMenuBar(mainMenuBar);
- mainMenuBar->setObjectName(QStringLiteral("mainMenuBar"));
- mainMenuBar->setVisible(true);
- mainToolBar = new QToolBar(this);
- mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
- addToolBar(mainToolBar);
- //mainStatusBar = new QStatusBar(this);
- //mainStatusBar->setObjectName(QStringLiteral("mainStatusBar"));
- //setStatusBar(mainStatusBar);
- // Set QMainWindow in the center of desktop
- //QRect rect = geometry();
- //rect.moveCenter(QApplication::desktop()->availableGeometry().center());
- //setGeometry(rect);
- //mainStatusBar->setVisible(false);
- mainToolBar->setVisible(false);
- mainToolBar->setWindowTitle(tr("ToolBar"));
- m_timer = new QTimer(this);
- m_timer->setObjectName(QStringLiteral("m_timer"));
- connect(m_timer, SIGNAL(timeout()), this, SLOT(OnTimer()));
- m_savedGamePath.clear();
- m_isQuit = false;
- m_keyPressedWhileDisabled = false;
- m_isGameOpened = false;
- showPlainText = false;
- //setCentralWidget(_mainDescWidget);
- m_linkColor = palette().color(QPalette::Link);
- m_fontColor = palette().color(QPalette::Text);
- m_backColor = QColor(224, 224, 224);
- m_isUseBackColor = false;
- m_isUseLinkColor = false;
- m_isUseFontColor = false;
- m_defaultBackColor = m_backColor;
- m_defaultLinkColor = m_linkColor;
- m_defaultFontColor = m_fontColor;
- m_font = QFont( "Sans", 12 , QFont::Normal );
- m_font.setStyle(QFont::StyleNormal);
- m_font.setStyleHint( QFont::SansSerif );
- m_defaultFont = m_font;
- m_isUseFontSize = false;
- m_isUseFont = false;
- m_fontSize = 12;
- showCaptions = true;
- m_isShowHotkeys = false;
- m_volume = 1.0f;
- disableVideo = false;
- m_videoFix = false;
- perGameConfig = false;
- autostartLastGame = false;
- m_isAllowHTML5Extras = false;
- langid = QObject::tr("__LANGID__");
- if(langid == QStringLiteral("__LANGID__"))
- langid = QLocale::system().name();
- CreateDockWindows();
- ApplyBackColor(m_backColor);
- ApplyFontColor(m_fontColor);
- ApplyLinkColor(m_linkColor);
- ApplyFont(m_font);
- LoadSettings();
- CreateMenuBar();
- m_menu = new QMenu(this);
- m_menu->setObjectName(QStringLiteral("m_menu"));
- connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(OnMenu(QAction*)) );
- QSPInit();
- QSPCallBacks::Init(this);
- QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
- if(autostartLastGame)
- OpenGameFile(lastGame);
- }
- MainWindow::~MainWindow()
- {
- }
- void MainWindow::EnableControls(bool status, bool isExtended)
- {
- if (isExtended) _fileMenu->setEnabled(status); //TODO: ???
- _fileMenu->setEnabled(status); //TODO: ???
- _gameMenu->setEnabled(status);
- _settingsMenu->setEnabled(status);
- _objectsListBox->setEnabled(status);
- _actionsListBox->setEnabled(status);
- _inputTextBox->setEnabled(status);
- m_isProcessEvents = status;
- m_keyPressedWhileDisabled = false;
- }
- void MainWindow::ApplyParams()
- {
- int numVal;
- QSP_CHAR *strVal;
- QColor setBackColor, setFontColor, setLinkColor;
- setPalette(m_palette);
- // --------------
- if(!m_isUseBackColor)
- {
- if(QSPGetVarValues(QSP_FMT("BCOLOR"), 0, &numVal, &strVal))
- {
- if(numVal == 0)
- setBackColor = m_defaultBackColor;
- else
- setBackColor = QSPTools::wxtoQColor(numVal);
- }
- else
- setBackColor = m_defaultBackColor;
- }
- else
- {
- setBackColor = m_settingsBackColor;
- }
- ApplyBackColor(setBackColor);
- // --------------
- if(!m_isUseFontColor)
- {
- if(QSPGetVarValues(QSP_FMT("FCOLOR"), 0, &numVal, &strVal))
- {
- if(numVal == 0)
- setFontColor = m_defaultFontColor;
- else
- setFontColor = QSPTools::wxtoQColor(numVal);
- }
- else
- setFontColor = m_defaultFontColor;
- }
- else
- {
- setFontColor = m_settingsFontColor;
- }
- ApplyFontColor(setFontColor);
- // --------------
- if(!m_isUseLinkColor)
- {
- if(QSPGetVarValues(QSP_FMT("LCOLOR"), 0, &numVal, &strVal))
- {
- if(numVal == 0)
- setLinkColor = m_defaultLinkColor;
- else
- setLinkColor = QSPTools::wxtoQColor(numVal);
- }
- else
- setLinkColor = m_defaultLinkColor;
- }
- else
- {
- setLinkColor = m_settingsLinkColor;
- }
- ApplyLinkColor(setLinkColor);
- // --------------
- QFont new_font = m_defaultFont;
- if(!m_isUseFont)
- {
- if(QSPGetVarValues(QSP_FMT("FNAME"), 0, &numVal, &strVal))
- if(strVal != 0)
- {
- new_font.setFamily(QSPTools::qspStrToQt(strVal));
- }
- if(!m_isUseFontSize)
- {
- if(QSPGetVarValues(QSP_FMT("FSIZE"), 0, &numVal, &strVal))
- if(numVal != 0)
- {
- new_font.setPointSize(numVal);
- }
- }
- else
- {
- new_font.setPointSize(m_fontSize);
- }
- }
- else
- {
- new_font = m_font;
- }
- ApplyFont(new_font);
- }
- void MainWindow::DeleteMenu()
- {
- m_menu->clear();
- m_menuItemId = 0;
- }
- void MainWindow::AddMenuItem(const QString &name, const QString &imgPath)
- {
- if (name == QString("-"))
- m_menu->addSeparator();
- else
- {
- bool pixmap_ok = false;
- QPixmap itemPixmap;
- QFileInfo file(m_path + imgPath);
- QString itemPath(file.absoluteFilePath());
- if (file.exists() && file.isFile())
- {
- if(itemPixmap.load(itemPath))
- pixmap_ok = true;
- }
- QAction *action;
- if(pixmap_ok)
- {
- action = m_menu->addAction(QIcon(itemPixmap), name);
- //m_menu->addAction(QIcon(itemPixmap), name, this, SLOT(OnMenu(bool)));
- }
- else
- {
- action = m_menu->addAction(name);
- //m_menu->addAction(name, this, SLOT(OnMenu(bool)));
- }
- action->setData(m_menuItemId);
- }
- m_menuItemId++;
- }
- int MainWindow::ShowMenu()
- {
- m_menuIndex = -1;
- m_menu->exec(QCursor::pos());
- return m_menuIndex;
- }
- void MainWindow::UpdateGamePath(const QString &path)
- {
- QString new_path = path;
- if(!new_path.endsWith("/"))
- new_path+="/";
- m_path = new_path;
- _mainDescTextBox->SetGamePath(new_path);
- _descTextBox->SetGamePath(new_path);
- _actionsListBox->SetGamePath(new_path);
- _objectsListBox->SetGamePath(new_path);
- m_imgView->SetGamePath(new_path);
- }
- void MainWindow::ShowError()
- {
- bool oldIsProcessEvents;
- QString errorMessage;
- QSP_CHAR *loc;
- int code, actIndex, line;
- if (m_isQuit) return;
- QSPGetLastErrorData(&code, &loc, &actIndex, &line);
- QString desc = QSPTools::qspStrToQt(QSPGetErrorDesc(code));
- if (loc)
- errorMessage = QString("Location: %1\nArea: %2\nLine: %3\nCode: %4\nDesc: %5")
- .arg(QSPTools::qspStrToQt(loc))
- .arg(actIndex < 0 ? QString("on visit") : QString("on action"))
- .arg(line)
- .arg(code)
- .arg(desc);
- else
- errorMessage = QString("Code: %1\nDesc: %2")
- .arg(code)
- .arg(desc);
- QMessageBox dialog(QMessageBox::Critical, tr("Error"), errorMessage, QMessageBox::Ok, this);
- oldIsProcessEvents = m_isProcessEvents;
- m_isProcessEvents = false;
- dialog.exec();
- m_isProcessEvents = oldIsProcessEvents;
- if (m_isGameOpened) QSPCallBacks::RefreshInt(QSP_FALSE);
- }
- void MainWindow::SetShowPlainText(bool isPlain)
- {
- showPlainText = isPlain;
- _mainDescTextBox->SetShowPlainText(showPlainText);
- _descTextBox->SetShowPlainText(showPlainText);
- _actionsListBox->SetShowPlainText(showPlainText);
- _objectsListBox->SetShowPlainText(showPlainText);
- }
- void MainWindow::RefreshUI()
- {
- _mainDescTextBox->RefreshUI();
- _objectsListBox->RefreshUI();
- _actionsListBox->RefreshUI();
- _descTextBox->RefreshUI();
- //m_input->Refresh();
- m_imgView->RefreshUI();
- }
- void MainWindow::ApplyFont(const QFont &new_font)
- {
- m_font = new_font;
- _mainDescTextBox->SetTextFont(new_font);
- _descTextBox->SetTextFont(new_font);
- _objectsListBox->SetTextFont(new_font);
- _actionsListBox->SetTextFont(new_font);
- }
- bool MainWindow::ApplyFontColor(const QColor &color)
- {
- m_fontColor = color;
- _mainDescTextBox->SetForegroundColor(color);
- _descTextBox->SetForegroundColor(color);
- _objectsListBox->SetForegroundColor(color);
- _actionsListBox->SetForegroundColor(color);
- return false;
- }
- bool MainWindow::ApplyBackColor(const QColor &color)
- {
- m_backColor = color;
- QPalette p = palette();
- p.setColor(QPalette::Base, color);
- setPalette(p);
- _mainDescTextBox->SetBackgroundColor(color);
- _descTextBox->SetBackgroundColor(color);
- _objectsListBox->SetBackgroundColor(color);
- _actionsListBox->SetBackgroundColor(color);
- m_imgView->SetBackgroundColor(color);
- return false;
- }
- bool MainWindow::ApplyLinkColor(const QColor &color)
- {
- m_linkColor = color;
- _mainDescTextBox->SetLinkColor(color);
- _descTextBox->SetLinkColor(color);
- _objectsListBox->SetLinkColor(color);
- _actionsListBox->SetLinkColor(color);
- return false;
- }
- void MainWindow::SetOverallVolume(float new_volume)
- {
- QSPCallBacks::SetOverallVolume(new_volume);
- m_volume = new_volume;
- }
- void MainWindow::SetDisableVideo(bool isDisableVideo)
- {
- disableVideo = isDisableVideo;
- #ifndef _WEBBOX_COMMON
- _mainDescTextBox->SetDisableVideo(disableVideo);
- _descTextBox->SetDisableVideo(disableVideo);
- #endif
- }
- void MainWindow::SetVideoFix(bool isFix)
- {
- m_videoFix = isFix;
- #ifdef _WEBBOX_COMMON
- _mainDescTextBox->SetVideoFix(m_videoFix);
- _descTextBox->SetVideoFix(m_videoFix);
- #endif
- }
- void MainWindow::SetAllowHTML5Extras(bool HTML5Extras)
- {
- m_isAllowHTML5Extras = HTML5Extras;
- QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
- }
- void MainWindow::LoadSettings(QString filePath)
- {
- QSettings *settings;
- if(filePath.isEmpty())
- settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName(), this);
- else
- settings = new QSettings(filePath, QSettings::IniFormat);
- restoreGeometry(settings->value("mainWindow/geometry").toByteArray());
- if ( isMaximized() )
- setGeometry( QApplication::desktop()->availableGeometry( this ) );
- restoreState(settings->value("mainWindow/windowState").toByteArray());
- if (settings->value("mainWindow/isMaximized", isMaximized()).toBool())
- showMaximized();
- if (settings->value("mainWindow/isFullScreen", isFullScreen()).toBool())
- showFullScreen();
- OnToggleCaptions(settings->value("mainWindow/showCaptions", showCaptions).toBool());
- SetShowPlainText(settings->value("application/isShowPlainText", showPlainText).toBool());
- SetLastPath(settings->value("application/lastPath", GetLastPath()).toString());
- perGameConfig = settings->value("application/perGameConfig", perGameConfig).toBool();
- m_isUseFontSize = settings->value("application/isUseFontSize", m_isUseFontSize).toBool();
- m_fontSize = settings->value("application/fontSize", m_fontSize).toInt();
- m_isUseFont = settings->value("application/isUseFont", m_isUseFont).toBool();
- if(m_isUseFont)
- ApplyFont(qvariant_cast<QFont>(settings->value("application/font", m_font)));
- m_isUseBackColor = settings->value("application/isUseBackColor", m_isUseBackColor).toBool();
- m_isUseLinkColor = settings->value("application/isUseLinkColor", m_isUseLinkColor).toBool();
- m_isUseFontColor = settings->value("application/isUseFontColor", m_isUseFontColor).toBool();
- if(m_isUseBackColor)
- ApplyBackColor(qvariant_cast<QColor>(settings->value("application/backColor", m_backColor)));
- if(m_isUseLinkColor)
- ApplyLinkColor(qvariant_cast<QColor>(settings->value("application/linkColor", m_linkColor)));
- if(m_isUseFontColor)
- ApplyFontColor(qvariant_cast<QColor>(settings->value("application/fontColor", m_fontColor)));
- m_settingsBackColor = qvariant_cast<QColor>(settings->value("application/backColor", m_backColor));
- m_settingsLinkColor = qvariant_cast<QColor>(settings->value("application/linkColor", m_linkColor));
- m_settingsFontColor = qvariant_cast<QColor>(settings->value("application/fontColor", m_fontColor));
- disableVideo = settings->value("application/disableVideo", disableVideo).toBool();
- SetDisableVideo(disableVideo);
- m_videoFix = settings->value("application/videoFix", m_videoFix).toBool();
- SetVideoFix(m_videoFix);
- lastGame = settings->value("application/lastGame", lastGame).toString();
- autostartLastGame = settings->value("application/autostartLastGame", autostartLastGame).toBool();
- m_volume = settings->value("application/volume", m_volume).toFloat();
- SetOverallVolume(m_volume);
- m_isShowHotkeys = settings->value("application/isShowHotkeys", m_isShowHotkeys).toBool();
- m_isAllowHTML5Extras = settings->value("application/isAllowHTML5Extras", m_isAllowHTML5Extras).toBool();
- langid = settings->value("application/language", langid).toString();
- RefreshUI();
- delete settings;
- }
- void MainWindow::SaveSettings(QString filePath)
- {
- QSettings *settings;
- if(filePath.isEmpty())
- settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName(), this);
- else
- settings = new QSettings(filePath, QSettings::IniFormat);
- bool maximized = isMaximized();
- bool fullscreen = isFullScreen();
- settings->setValue("mainWindow/geometry", saveGeometry());
- settings->setValue("mainWindow/windowState", saveState());
- settings->setValue("mainWindow/isMaximized", maximized);
- settings->setValue("mainWindow/isFullScreen", fullscreen);
- settings->setValue("mainWindow/showCaptions", showCaptions);
- settings->setValue("application/isShowPlainText", showPlainText);
- settings->setValue("application/lastPath", lastPath);
- settings->setValue("application/perGameConfig", perGameConfig);
- settings->setValue("application/isUseFontSize", m_isUseFontSize);
- settings->setValue("application/fontSize", m_fontSize);
- settings->setValue("application/isUseFont", m_isUseFont);
- settings->setValue("application/font", m_font);
- settings->setValue("application/isUseBackColor", m_isUseBackColor);
- settings->setValue("application/isUseLinkColor", m_isUseLinkColor);
- settings->setValue("application/isUseFontColor", m_isUseFontColor);
- settings->setValue("application/backColor", m_settingsBackColor);
- settings->setValue("application/linkColor", m_settingsLinkColor);
- settings->setValue("application/fontColor", m_settingsFontColor);
- settings->setValue("application/disableVideo", disableVideo);
- settings->setValue("application/videoFix", m_videoFix);
- settings->setValue("application/lastGame", lastGame);
- settings->setValue("application/autostartLastGame", autostartLastGame);
- settings->setValue("application/volume", m_volume);
- settings->setValue("application/isShowHotkeys", m_isShowHotkeys);
- settings->setValue("application/isAllowHTML5Extras", m_isAllowHTML5Extras);
- settings->setValue("application/language", langid);
- settings->sync();
- delete settings;
- }
- void MainWindow::CreateMenuBar()
- {
- QAction* action;
- //------------------------------------------------------------------
- // File menu
- _fileMenu = menuBar()->addMenu(tr("&Quest"));
- // Open item
- action = _fileMenu->addAction(QIcon(":/gfx/menu/open"), tr("Open game..."),
- this, SLOT(OnOpenGame()), QKeySequence(Qt::ALT + Qt::Key_O));
- mainToolBar->addAction(action);
- // New game item
- action = _fileMenu->addAction(QIcon(":/gfx/menu/new"),tr("Restart game"),
- this, SLOT(OnRestartGame()), QKeySequence(Qt::ALT + Qt::Key_N));
- mainToolBar->addAction(action);
- _fileMenu->addSeparator();
- mainToolBar->addSeparator();
- // Exit item
- action = _fileMenu->addAction(QIcon(":/gfx/menu/exit"), tr("Exit"),
- this, SLOT(close()), QKeySequence(Qt::ALT + Qt::Key_X));
- mainToolBar->addAction(action);
- //------------------------------------------------------------------
- mainToolBar->addSeparator();
- // Game menu
- _gameMenu = menuBar()->addMenu(tr("&Game"));
- // Open saved game item
- action = _gameMenu->addAction(QIcon(":/gfx/menu/statusopen"), tr("Open saved game..."),
- this, SLOT(OnOpenSavedGame()), QKeySequence(Qt::CTRL + Qt::Key_O));
- mainToolBar->addAction(action);
- // Save game item
- action = _gameMenu->addAction(QIcon(":/gfx/menu/statussave"), tr("Save game..."),
- this, SLOT(OnSaveGame()), QKeySequence(Qt::CTRL + Qt::Key_S));
- mainToolBar->addAction(action);
- // Open quicksave item
- action = _gameMenu->addAction(tr("Quick Load"),
- this, SLOT(OnOpenQuickSavedGame()), QKeySequence(Qt::Key_F9));
- mainToolBar->addAction(action);
- // Quicksave item
- action = _gameMenu->addAction(tr("Quick Save"),
- this, SLOT(OnQuickSaveGame()), QKeySequence(Qt::Key_F5));
- mainToolBar->addAction(action);
- //------------------------------------------------------------------
- mainToolBar->addSeparator();
- // Settings menu
- _settingsMenu = menuBar()->addMenu(tr("&Settings"));
- // Show / Hide submenu
- _showHideMenu = _settingsMenu->addMenu(tr("Show / Hide"));
- // Objects item
- action = _objectsWidget->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
- _showHideMenu->addAction(action);
- // Actions item
- action = _actionsWidget->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
- _showHideMenu->addAction(action);
- // Additional desc item
- action = _descWidget->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
- _showHideMenu->addAction(action);
- // Input area item
- action = _inputWidget->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_4));
- _showHideMenu->addAction(action);
- // Main desc item
- action = _mainDescWidget->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_5));
- _showHideMenu->addAction(action);
- // Image item
- action = _imgViewWidget->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6));
- _showHideMenu->addAction(action);
- _showHideMenu->addSeparator();
- // Captions item
- action = _showHideMenu->addAction(tr("Captions"));
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6));
- action->setCheckable(true);
- if(_objectsWidget->titleBarWidget() == 0)
- action->setChecked(true);
- else
- action->setChecked(false);
- connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleCaptions(bool)));
- // ToolBar
- action = mainToolBar->toggleViewAction();
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7));
- _showHideMenu->addAction(action);
- //TODO: MenuBar
- // MenuBar
- //action = _showHideMenu->addAction(tr("MenuBar"));
- //action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7));
- //action->setCheckable(true);
- //if(mainMenuBar->isVisible())
- // action->setChecked(true);
- //else
- // action->setChecked(false);
- //connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleMenuBar(bool)));
- // Hotkeys for actions item
- action = _showHideMenu->addAction(tr("Hotkeys for actions"));
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_8));
- action->setCheckable(true);
- action->setChecked(m_isShowHotkeys);
- connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleHotkeys(bool)));
- // Window / Fullscreen mode item
- action = _settingsMenu->addAction(QIcon(":/gfx/menu/windowmode"), tr("Window / Fullscreen mode"),
- this, SLOT(OnToggleWinMode()), QKeySequence(Qt::Key_F11));
- mainToolBar->addAction(action);
- _settingsMenu->addSeparator();
- mainToolBar->addSeparator();
- // Display HTML code as plain text
- action = _settingsMenu->addAction(tr("Display HTML code as plain text"));
- action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_D));
- action->setCheckable(true);
- action->setChecked(showPlainText);
- connect(action, SIGNAL(toggled(bool)), this, SLOT(OnToggleShowPlainText(bool)));
- // _settingsMenu->addAction(tr("Display HTML code as plain text"),
- // this, SLOT(OnToggleShowPlainText()), QKeySequence(Qt::ALT + Qt::Key_D))->setCheckable(true);
- _settingsMenu->addSeparator();
- // Options item
- action = _settingsMenu->addAction(tr("Options..."),
- this, SLOT(OnOptions()), QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_O));
- //mainToolBar->addAction(action);
- //------------------------------------------------------------------
- //mainToolBar->addSeparator();
- // Help menu
- QMenu* helpMenu(menuBar()->addMenu(tr("&Help")));
- // About item
- action = helpMenu->addAction(QIcon(":/gfx/menu/about"), tr("About..."),
- this, SLOT(OnAbout()), QKeySequence(Qt::CTRL + Qt::Key_H));
- mainToolBar->addAction(action);
- }
- void MainWindow::CreateDockWindows()
- {
- // "Main desc" widget
- #ifndef _WEBBOX_COMMON
- _mainDescTextBox = new QspTextBox(this);
- connect(_mainDescTextBox, SIGNAL(anchorClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
- #endif
- #ifdef _WEBBOX
- _mainDescTextBox = new QspWebBox(this);
- connect(_mainDescTextBox, SIGNAL(qspLinkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
- _mainDescTextBox->page()->load(QUrl("qsp:/"));
- {
- QEventLoop loop;
- connect(_mainDescTextBox->page(), SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
- loop.exec();
- }
- #endif
- #ifdef _WEBBOX_WEBKIT
- _mainDescTextBox = new QspWebBox(this);
- connect(_mainDescTextBox, SIGNAL(linkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
- _mainDescTextBox->load(QUrl("qsp:/"));
- {
- QEventLoop loop;
- connect(_mainDescTextBox,SIGNAL(loadFinished(bool)),&loop,SLOT(quit()));
- loop.exec();
- }
- #endif
- _mainDescTextBox->setObjectName(QStringLiteral("_mainDescTextBox"));
- _mainDescWidget = new QDockWidget(tr("Main desc"), this);
- _mainDescWidget->setObjectName(QStringLiteral("_mainDescWidget"));
- addDockWidget(Qt::TopDockWidgetArea, _mainDescWidget, Qt::Vertical);
- _mainDescWidget->setWidget(_mainDescTextBox);
- // "Objects" widget
- _objectsWidget = new QDockWidget(tr("Objects"), this);
- _objectsWidget->setObjectName(QStringLiteral("_objectsWidget"));
- addDockWidget(Qt::RightDockWidgetArea, _objectsWidget, Qt::Vertical);
- _objectsListBox = new QspListBox(this);
- _objectsListBox->setObjectName(QStringLiteral("_objectsListBox"));
- connect(_objectsListBox, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(OnObjectListBoxItemClicked(QListWidgetItem *)));
- //connect(_objectsListBox, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(OnObjectListBoxItemClicked(QListWidgetItem *)));
- connect(_objectsListBox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(OnObjectListBoxItemClicked(QListWidgetItem *)));
- //connect(_objectsListBox, SIGNAL(currentRowChanged(int)), this, SLOT(OnObjectChange(int)));
- _objectsWidget->setWidget(_objectsListBox);
- // "Actions" widget
- _actionsWidget = new QDockWidget(tr("Actions"), this);
- _actionsWidget->setObjectName(QStringLiteral("_actionsWidget"));
- addDockWidget(Qt::BottomDockWidgetArea, _actionsWidget, Qt::Vertical);
- _actionsListBox = new QspListBox(this);
- _actionsListBox->setObjectName(QStringLiteral("_actionsListBox"));
- connect(_actionsListBox, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(OnActionsListBoxItemClicked(QListWidgetItem *)));
- //connect(_actionsListBox, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(OnActionsListBoxItemClicked(QListWidgetItem *)));
- connect(_actionsListBox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(OnActionsListBoxItemClicked(QListWidgetItem *)));
- connect(_actionsListBox, SIGNAL(SelectionChange(int)), this, SLOT(OnActionChange(int)));
- _actionsListBox->SetMouseTracking(true);
- _actionsWidget->setWidget(_actionsListBox);
- // "Additional desc" widget
- _descWidget = new QDockWidget(tr("Additional desc"), this);
- _descWidget->setObjectName(QStringLiteral("_descWidget"));
- addDockWidget(Qt::BottomDockWidgetArea, _descWidget, Qt::Horizontal);
- #ifndef _WEBBOX_COMMON
- _descTextBox = new QspTextBox(this);
- connect(_descTextBox, SIGNAL(anchorClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
- #endif
- #ifdef _WEBBOX
- _descTextBox = new QspWebBox(this);
- connect(_descTextBox, SIGNAL(qspLinkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
- _descTextBox->page()->load(QUrl("qsp:/"));
- {
- QEventLoop loop;
- connect(_descTextBox->page(), SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
- loop.exec();
- }
- #endif
- #ifdef _WEBBOX_WEBKIT
- _descTextBox = new QspWebBox(this);
- connect(_descTextBox, SIGNAL(linkClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
- _descTextBox->load(QUrl("qsp:/"));
- {
- QEventLoop loop;
- connect(_descTextBox,SIGNAL(loadFinished(bool)),&loop,SLOT(quit()));
- loop.exec();
- }
- #endif
- _descTextBox->setObjectName(QStringLiteral("_descTextBox"));
- _descWidget->setWidget(_descTextBox);
- // "Input area" widget
- _inputWidget = new QDockWidget(tr("Input area"), this);
- _inputWidget->setObjectName(QStringLiteral("_inputWidget"));
- addDockWidget(Qt::BottomDockWidgetArea, _inputWidget, Qt::Vertical);
- _inputTextBox = new QspInputBox(this);
- _inputTextBox->setObjectName(QStringLiteral("_inputTextBox"));
- _inputWidget->setWidget(_inputTextBox);
- connect(_inputTextBox, SIGNAL(textChanged()), this, SLOT(OnInputTextChange()));
- connect(_inputTextBox, SIGNAL(InputTextEnter()), this, SLOT(OnInputTextEnter()));
- m_imgView = new QspImgCanvas(this);
- m_imgView->setObjectName(QStringLiteral("m_imgView"));
- _imgViewWidget = new QDockWidget(tr("Image"), this);
- _imgViewWidget->setObjectName(QStringLiteral("_imgViewWidget"));
- _imgViewWidget->setWidget(m_imgView);
- addDockWidget(Qt::BottomDockWidgetArea, _imgViewWidget, Qt::Vertical);
- splitDockWidget(_actionsWidget, _inputWidget, Qt::Vertical);
- splitDockWidget(_mainDescWidget, _objectsWidget, Qt::Horizontal);
- }
- void MainWindow::closeEvent(QCloseEvent *event)
- {
- if(!m_configPath.isEmpty())
- SaveSettings(m_configPath);
- SaveSettings();
- EnableControls(false, true);
- setVisible(false);
- m_isQuit = true;
- QSPDeInit();
- QSPCallBacks::DeInit();
- QCoreApplication::processEvents();
- QMainWindow::closeEvent(event);
- }
- void MainWindow::keyPressEvent(QKeyEvent *event)
- {
- int action = -1;
- if(event->key() == Qt::Key_1)
- if(_actionsListBox->count() >= 1)
- action = 0;
- if(event->key() == Qt::Key_2)
- if(_actionsListBox->count() >= 2)
- action = 1;
- if(event->key() == Qt::Key_3)
- if(_actionsListBox->count() >= 3)
- action = 2;
- if(event->key() == Qt::Key_4)
- if(_actionsListBox->count() >= 4)
- action = 3;
- if(event->key() == Qt::Key_5)
- if(_actionsListBox->count() >= 5)
- action = 4;
- if(event->key() == Qt::Key_6)
- if(_actionsListBox->count() >= 6)
- action = 5;
- if(event->key() == Qt::Key_7)
- if(_actionsListBox->count() >= 7)
- action = 6;
- if(event->key() == Qt::Key_8)
- if(_actionsListBox->count() >= 8)
- action = 7;
- if(event->key() == Qt::Key_9)
- if(_actionsListBox->count() >= 9)
- action = 8;
- if(event->key() == Qt::Key_0)
- if(_actionsListBox->count() >= 10)
- action = 9;
- if(action != -1)
- {
- if (!QSPSetSelActionIndex(action, QSP_TRUE))
- ShowError();
- if (!QSPExecuteSelActionCode(QSP_TRUE))
- ShowError();
- return;
- }
- if(event->key() == Qt::Key_Up)
- {
- if(_actionsListBox->count()!=0)
- {
- int newSel = _actionsListBox->GetSelection() - 1;
- if(newSel < 0)
- _actionsListBox->SetSelection(_actionsListBox->count()-1);
- else
- _actionsListBox->SetSelection(newSel);
- }
- return;
- }
- if(event->key() == Qt::Key_Down)
- {
- if(_actionsListBox->count()!=0)
- {
- int newSel = _actionsListBox->GetSelection() + 1;
- if(newSel <= 0 || newSel >= _actionsListBox->count())
- _actionsListBox->SetSelection(0);
- else
- _actionsListBox->SetSelection(newSel);
- }
- return;
- }
- if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
- if(_actionsListBox->GetSelection() != -1)
- {
- ActionsListBoxDoAction(_actionsListBox->GetSelection());
- return;
- }
- if(event->key() == Qt::Key_Escape)
- if(isFullScreen())
- showNormal();
- #ifndef _WEBBOX_COMMON
- _descTextBox->keyPressEvent(event);
- _mainDescTextBox->keyPressEvent(event);
- #endif
- QMainWindow::keyPressEvent(event);
- }
- void MainWindow::OpenGameFile(const QString &path)
- {
- if(!path.isEmpty())
- {
- QFileInfo fileName(path);
- QSPCallBacks::m_gamePath = fileName.canonicalPath();
- if(!QSPCallBacks::m_gamePath.endsWith("/")) QSPCallBacks::m_gamePath+="/";
- _mainDescTextBox->SetGamePath(QSPCallBacks::m_gamePath);
- _objectsListBox->SetGamePath(QSPCallBacks::m_gamePath);
- _actionsListBox->SetGamePath(QSPCallBacks::m_gamePath);
- _descTextBox->SetGamePath(QSPCallBacks::m_gamePath);
- if (QSPLoadGameWorld(qspStringFromQString(path)))
- {
- m_isGameOpened = true;
- lastGame = path;
- QFileInfo file(path);
- QString filePath(file.canonicalPath());
- if(!filePath.endsWith("/")) filePath+="/";
- QString configString(filePath + QSP_CONFIG);
- if (configString != m_configPath && perGameConfig)
- {
- if(m_configPath.isEmpty())
- SaveSettings();
- else
- SaveSettings(m_configPath);
- m_configPath = configString;
- QFileInfo configFile(configString);
- if(configFile.exists() && configFile.isFile())
- LoadSettings(configString);
- }
- if(!m_isUseBackColor)
- ApplyBackColor(m_defaultBackColor);
- if(!m_isUseLinkColor)
- ApplyLinkColor(m_defaultLinkColor);
- if(!m_isUseFontColor)
- ApplyFontColor(m_defaultFontColor);
- if(!m_isUseFont)
- ApplyFont(m_defaultFont);
- UpdateGamePath(filePath);
- OnNewGame();
- if (m_isQuit) return;
- //UpdateTitle();
- EnableControls(true);
- m_savedGamePath.clear();
- ApplyParams();
- }
- else
- ShowError();
- }
- }
- void MainWindow::ActionsListBoxDoAction(int action)
- {
- if(m_isProcessEvents)
- {
- if(action != -1)
- {
- if (!QSPSetSelActionIndex(action, QSP_TRUE))
- ShowError();
- if (!QSPExecuteSelActionCode(QSP_TRUE))
- ShowError();
- }
- }
- }
- void MainWindow::dropEvent(QDropEvent *event)
- {
- if (event->mimeData()->hasUrls())
- {
- if(event->mimeData()->urls().count() > 0)
- {
- if(event->mimeData()->urls().at(0).toLocalFile().endsWith(".qsp"))
- {
- OpenGameFile(event->mimeData()->urls().at(0).toLocalFile());
- event->acceptProposedAction();
- }
- if(event->mimeData()->urls().at(0).toLocalFile().endsWith(".sav"))
- {
- if(m_isGameOpened)
- {
- if (!QSPOpenSavedGame(qspStringFromQString(event->mimeData()->urls().at(0).toLocalFile()), QSP_TRUE))
- ShowError();
- else
- ApplyParams();
- }
- event->acceptProposedAction();
- }
- }
- }
- }
- void MainWindow::dragEnterEvent(QDragEnterEvent *event)
- {
- event->accept();
- }
- void MainWindow::OnOpenGame()
- {
- #ifndef _ANDROIDQT
- #ifndef _NONATIVEDIALOG
- QString path = QFileDialog::getOpenFileName(this, tr("Select game file"), GetLastPath(), tr("QSP games (*.qsp *.gam)"));
- #else
- QString path = QFileDialog::getOpenFileName(this, tr("Select game file"), GetLastPath(), tr("QSP games (*.qsp *.gam)"), nullptr, QFileDialog::DontUseNativeDialog);
- #endif
- if (!path.isEmpty())
- {
- SetLastPath(QFileInfo(path).canonicalPath());
- OpenGameFile(path);
- }
- #else
- QString path = QFileDialog::getOpenFileName(this, tr("Select game file"), QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).at(0), tr("QSP games (*.qsp *.gam)"));
- if (!path.isEmpty())
- {
- SetLastPath(QFileInfo(path).canonicalPath());
- OpenGameFile(path);
- }
- return;
- AndroidFileDialog fileDialog;
- connect(&fileDialog, SIGNAL(existingFileNameReady(QString)), this, SLOT(OpenGameFile(QString)));
- bool success = fileDialog.provideExistingFileName();
- if (!success) {
- qDebug() << "Problem with JNI or sth like that...";
- disconnect(fileDialog, SIGNAL(existingFileNameReady(QString)), this, SLOT(OpenGameFile(QString)));
- //or just delete fileDialog instead of disconnect
- }
- #endif
- }
- void MainWindow::OnRestartGame()
- {
- if(m_isGameOpened)
- {
- if (!QSPRestartGame(QSP_TRUE))
- ShowError();
- else
- ApplyParams();
- }
- }
- void MainWindow::OnOpenSavedGame()
- {
- if(!m_isGameOpened)
- return;
- #ifndef _NONATIVEDIALOG
- QString path = QFileDialog::getOpenFileName(this, tr("Select saved game file"), GetLastPath(), tr("Saved game files (*.sav)"));
- #else
- QString path = QFileDialog::getOpenFileName(this, tr("Select saved game file"), GetLastPath(), tr("Saved game files (*.sav)"), nullptr, QFileDialog::DontUseNativeDialog);
- #endif
- if (!path.isEmpty())
- {
- SetLastPath(QFileInfo(path).canonicalPath());
- if (!QSPOpenSavedGame(qspStringFromQString(path), QSP_TRUE))
- ShowError();
- else
- ApplyParams();
- }
- }
- void MainWindow::OnSaveGame()
- {
- if(!m_isGameOpened)
- return;
- #ifndef _NONATIVEDIALOG
- QString path = QFileDialog::getSaveFileName(this, tr("Select file to save"), GetLastPath(), tr("Saved game files (*.sav)"));
- #else
- QString path = QFileDialog::getSaveFileName(this, tr("Select file to save"), GetLastPath(), tr("Saved game files (*.sav)"), nullptr, QFileDialog::DontUseNativeDialog);
- #endif
- if (!path.isEmpty())
- {
- if(!path.endsWith(".sav"))
- path.append(".sav");
- QString p = GetLastPath();
- if (QSPSaveGame(qspStringFromQString(path), QSP_TRUE))
- {
- SetLastPath(QFileInfo(path).canonicalPath());
- m_savedGamePath = path;
- }
- else
- ShowError();
- }
- }
- void MainWindow::OnOpenQuickSavedGame()
- {
- if(!m_isGameOpened)
- return;
- QString path = m_path + QSP_QUICKSAVE;
- QFileInfo fileInfo(path);
- if(fileInfo.exists() && fileInfo.isFile())
- {
- if (!QSPOpenSavedGame(qspStringFromQString(path), QSP_TRUE))
- ShowError();
- else
- ApplyParams();
- }
- }
- void MainWindow::OnQuickSaveGame()
- {
- if(!m_isGameOpened)
- return;
- QString path = m_path + QSP_QUICKSAVE;
- if (QSPSaveGame(qspStringFromQString(path), QSP_TRUE))
- m_savedGamePath = path;
- else
- ShowError();
- }
- void MainWindow::OnOptions()
- {
- OptionsDialog optdlg(this);
- optdlg.exec();
- if(!m_configPath.isEmpty())
- SaveSettings(m_configPath);
- SaveSettings();
- }
- void MainWindow::OnAbout()
- {
- QPixmap icon = QPixmap(":/gfx/logo");
- icon = icon.scaledToHeight(64, Qt::SmoothTransformation);
- QString version(QSPTools::qspStrToQt(QSPGetVersion()));
- QString libCompiledDate(QSPTools::qspStrToQt(QSPGetCompiledDateTime()));
- QString guiCompiledDate(tr(__DATE__) + tr(", ") + tr(__TIME__));
- QString text = (tr("<h2>Qqsp</h2>"
- "<p>Copyright © 2017-2018, Sonnix</p>"));
- 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);
- QMessageBox dlg(QMessageBox::NoIcon, tr("About"), text, QMessageBox::Ok);
- dlg.setIconPixmap(icon);
- dlg.exec();
- }
- void MainWindow::OnToggleCaptions(bool checked)
- {
- showCaptions = checked;
- QWidget* mainTitleBarWidget = _mainDescWidget->titleBarWidget();
- QWidget* objectsTitleBarWidget = _objectsWidget->titleBarWidget();
- QWidget* actionsTitleBarWidget = _actionsWidget->titleBarWidget();
- QWidget* descTitleBarWidget = _descWidget->titleBarWidget();
- QWidget* inputTitleBarWidget = _inputWidget->titleBarWidget();
- if(checked == false)
- {
- _mainDescWidget->setTitleBarWidget(new QWidget(_mainDescWidget));
- _mainDescWidget->titleBarWidget()->hide();
- _objectsWidget->setTitleBarWidget(new QWidget(_objectsWidget));
- _objectsWidget->titleBarWidget()->hide();
- _actionsWidget->setTitleBarWidget(new QWidget(_actionsWidget));
- _actionsWidget->titleBarWidget()->hide();
- _descWidget->setTitleBarWidget(new QWidget(_descWidget));
- _descWidget->titleBarWidget()->hide();
- _inputWidget->setTitleBarWidget(new QWidget(_inputWidget));
- _inputWidget->titleBarWidget()->hide();
- }
- else
- {
- _mainDescWidget->setTitleBarWidget(0);
- _objectsWidget->setTitleBarWidget(0);
- _actionsWidget->setTitleBarWidget(0);
- _descWidget->setTitleBarWidget(0);
- _inputWidget->setTitleBarWidget(0);
- }
- if(mainTitleBarWidget)
- delete mainTitleBarWidget;
- if(objectsTitleBarWidget)
- delete objectsTitleBarWidget;
- if(actionsTitleBarWidget)
- delete actionsTitleBarWidget;
- if(descTitleBarWidget)
- delete descTitleBarWidget;
- if(inputTitleBarWidget)
- delete inputTitleBarWidget;
- }
- void MainWindow::OnToggleMenuBar(bool checked)
- {
- mainMenuBar->setVisible(checked);
- }
- void MainWindow::OnToggleHotkeys(bool checked)
- {
- m_isShowHotkeys = checked;
- RefreshUI();
- }
- void MainWindow::OnToggleWinMode()
- {
- if(isFullScreen())
- {
- showNormal();
- }
- else
- {
- showFullScreen();
- }
- }
- void MainWindow::OnToggleShowPlainText(bool checked)
- {
- SetShowPlainText(checked);
- }
- void MainWindow::OnNewGame()
- {
- if (!QSPRestartGame(QSP_TRUE))
- ShowError();
- }
- void MainWindow::OnTimer()
- {
- if (m_isProcessEvents && !QSPExecCounter(QSP_TRUE))
- ShowError();
- }
- void MainWindow::OnLinkClicked(const QUrl &url)
- {
- if(!m_isProcessEvents)
- return;
- QString href;
- href = QByteArray::fromPercentEncoding(url.toString().toUtf8());
- if (href.startsWith("#"))
- {
- QObject* obj = sender();
- if (obj == _mainDescTextBox)
- #ifndef _WEBBOX_COMMON
- _mainDescTextBox->setSource(url);
- #else
- _mainDescTextBox->setUrl(url);
- #endif
- else
- #ifndef _WEBBOX_COMMON
- _descTextBox->setSource(url);
- #else
- _descTextBox->setUrl(url);
- #endif
- }
- else if (href.startsWith("EXEC:", Qt::CaseInsensitive))
- {
- QString string = href.mid(5);
- if (m_isProcessEvents && !QSPExecString(qspStringFromQString(string), QSP_TRUE))
- ShowError();
- }
- else
- {
- QDesktopServices::openUrl(url);
- }
- }
- void MainWindow::OnObjectListBoxItemClicked(QListWidgetItem *itemClicked)
- {
- if(!m_isProcessEvents)
- return;
- int object = _objectsListBox->row(itemClicked);
- if (!QSPSetSelObjectIndex(object, QSP_TRUE))
- ShowError();
- }
- void MainWindow::OnActionsListBoxItemClicked(QListWidgetItem *itemClicked)
- {
- if(!m_isProcessEvents)
- return;
- int action = _actionsListBox->row(itemClicked);
- ActionsListBoxDoAction(action);
- }
- void MainWindow::OnObjectChange(int currentRow)
- {
- if(!m_isProcessEvents)
- return;
- //QThread::msleep(20);
- if (!QSPSetSelObjectIndex(currentRow, QSP_TRUE))
- ShowError();
- }
- void MainWindow::OnActionChange(int currentRow)
- {
- if(!m_isProcessEvents)
- return;
- if (!QSPSetSelActionIndex(currentRow, QSP_TRUE))
- ShowError();
- }
- void MainWindow::OnMenu(QAction* action)
- {
- m_menuIndex = action->data().toInt();
- }
- void MainWindow::OnInputTextChange()
- {
- QSPSetInputStrText(qspStringFromQString(_inputTextBox->GetText()));
- }
- void MainWindow::OnInputTextEnter()
- {
- if(!m_isProcessEvents)
- return;
- QSPSetInputStrText(qspStringFromQString(_inputTextBox->GetText()));
- if (!QSPExecUserInput(QSP_TRUE))
- ShowError();
- }
|