bool QSPApp::OnInit() { wxLog::EnableLogging(true); log_stream.open("log_qspgui.txt"); logger = new wxLogStream(&log_stream); //logger->SetTimestamp("%Y-%m-%d %H:%M:%S"); //formatter = logger->SetFormatter(new wxLogFormatter()); wxHandleFatalExceptions(true); wxInitAllImageHandlers(); QSPInit(); logger->LogText("qsp initialized"); try { InitUI(); } catch (...) { logger->LogText("exception during ui initialization."); } logger->LogText("ui initialized"); return true; }
FastQSPWindow::FastQSPWindow(QWidget *parent) : QMainWindow(parent), gameWidth(800), gameHeight(600), aspectRatio(qreal(gameWidth) / qreal(gameHeight)), scaleFactor(1), gameIsOpen(false), netManager(), settings (QSettings::IniFormat, QSettings::UserScope, "FastQSP", "config") { // Init audio #if QT_VERSION < 0x050000 media = new Phonon::MediaObject(this); audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); Phonon::createPath(media, audioOutput); #else player = new QMediaPlayer(); #endif // Start timer timer.start(); // Init view scene = new QGraphicsScene(this); graphicsView = new QGraphicsView(scene, this); graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); graphicsView->setUpdatesEnabled(true); graphicsView->setFrameStyle(QFrame::NoFrame); webView = new QGraphicsWebView(); webView->page()->setNetworkAccessManager(&netManager); webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); webView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); scene->addItem(webView); scene->setBackgroundBrush(QBrush(QColor(0, 0, 0))); webView->setRenderHints( QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::NonCosmeticDefaultPen); webView->settings()->setAttribute(QWebSettings::AutoLoadImages, true); webView->setAutoFillBackground(false); videoPlayer = new QMediaPlayer(); videoItem = new QGraphicsVideoItem(); videoItem->setSize(QSize(gameWidth + 4, gameHeight + 4)); videoItem->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); videoPlayer->setVideoOutput(videoItem); videoPlayer->setMuted(true); videoPlayer->setNotifyInterval(500); scene->addItem(videoItem); videoItem->hide(); savestatus = new QGraphicsTextItem; savestatus->setDefaultTextColor(Qt::yellow); QFont f; f.setBold(true); f.setPixelSize(20); savestatus->setFont(f); savestatus->setVisible(false); scene->addItem(savestatus); connect(videoPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(replayVideo(qint64))); // Filter context menu event graphicsView->viewport()->installEventFilter(this); // Creating menu //-File menu-------------------------------------------------------- QMenu *fileMenu = new QMenu("File"); fileMenu->addAction("Open file\tCtrl+O", this, SLOT(openFileDialog())); QShortcut *openFile = new QShortcut(QKeySequence("Ctrl+O"), this); connect(openFile, SIGNAL(activated()), SLOT(openFileDialog())); // fileMenu->addAction("Reload QSP file\tc", this, SLOT(openFileDialog())); //for powerairmax // QShortcut *reloadFile = new QShortcut(QKeySequence("c"), this); //for powerairmax fileMenu->addAction("Reload QSP file\tF3", this, SLOT(reloadQSP())); QShortcut *reloadFile = new QShortcut(QKeySequence("F3"), this); connect(reloadFile, SIGNAL(activated()), SLOT(reloadQSP())); fileMenu->addAction("Exit\tCtrl+Q", this, SLOT(close())); QShortcut *exit = new QShortcut(QKeySequence("Ctrl+Q"), this); connect(exit, SIGNAL(activated()), SLOT(close())); menuBar()->addMenu(fileMenu); //-Game menu-------------------------------------------------------- gameMenu = new QMenu("Game"); gameMenu->addAction("Save\tCtrl+S", this, SLOT(saveGameDialog())); QShortcut *save = new QShortcut(QKeySequence("Ctrl+S"), this); connect(save, SIGNAL(activated()), SLOT(saveGameDialog())); gameMenu->addAction("Load\tCtrl+L", this, SLOT(loadGameDialog())); QShortcut *load = new QShortcut(QKeySequence("Ctrl+L"), this); connect(load, SIGNAL(activated()), SLOT(loadGameDialog())); // gameMenu->addAction("Quicksave\tz", this, SLOT(saveGameDialog())); //for powerairmax // QShortcut *quicksave = new QShortcut(QKeySequence("z"), this); //for powerairmax gameMenu->addAction("Quicksave\tF5", this, SLOT(quicksave())); QShortcut *quicksave = new QShortcut(QKeySequence("F5"), this); connect(quicksave, SIGNAL(activated()), SLOT(quicksave())); // gameMenu->addAction("Quickload\tx", this, SLOT(loadGameDialog())); //for powerairmax // QShortcut *quickload = new QShortcut(QKeySequence("x"), this); //for powerairmax gameMenu->addAction("Quickload\tF2", this, SLOT(quickload())); QShortcut *quickload = new QShortcut(QKeySequence("F2"), this); connect(quickload, SIGNAL(activated()), SLOT(quickload())); gameMenu->addAction("Restart\tCtrl+R", this, SLOT(restartGame())); QShortcut *restart = new QShortcut(QKeySequence("Ctrl+R"), this); connect(restart, SIGNAL(activated()), SLOT(restartGame())); //Game shortcuts QShortcut *next = new QShortcut(QKeySequence("space"), this); connect(next, SIGNAL(activated()), SLOT(nextScreen())); QShortcut *prev= new QShortcut(QKeySequence("backspace"), this); connect(prev, SIGNAL(activated()), SLOT(prevScreen())); QShortcut *main_screen= new QShortcut(QKeySequence("escape"), this); connect(main_screen, SIGNAL(activated()), SLOT(gotoMainScreen())); ignoreCRCAction = new QAction("Ignore version check when loading", this); ignoreCRCAction->setCheckable(true); ignoreCRCAction->setChecked(settings.value("ignoreCRC", false).toBool()); connect(ignoreCRCAction, SIGNAL(toggled(bool)), this, SLOT(saveIgnoreCRCState())); gameMenu->addAction(ignoreCRCAction); // TODO: slows the game, move saving to diffrent thread autosaveAction = new QAction("Autosave", this); autosaveAction->setCheckable(true); autosaveAction->setChecked(false); // gameMenu->addAction(autosave); menuBar()->addMenu(gameMenu); gameMenu->setDisabled(true); //-Other menu------------------------------------------------------- QMenu *otherMenu = new QMenu("Other"); otherMenu->addAction("Fullscreen\tAlt+Enter", this, SLOT(toggleFullscreen())); QShortcut *fullscreen = new QShortcut(QKeySequence(Qt::Key_Return + Qt::AltModifier), this); otherMenu->addAction("Show html", this, SLOT(showHtml())); connect(fullscreen, SIGNAL(activated()), SLOT(toggleFullscreen())); muteAction = new QAction("Mute sound", this); muteAction ->setCheckable(true); muteAction ->setChecked(settings.value("mutedState", false).toBool()); connect(muteAction, SIGNAL(toggled(bool)), this, SLOT(saveMutedState())); otherMenu->addAction(muteAction); menuBar()->addMenu(otherMenu); //-Help menu-------------------------------------------------------- QMenu *helpMenu = new QMenu("Help"); helpMenu->addAction("About", this, SLOT(about())); menuBar()->addMenu(helpMenu); //------------------------------------------------------------------ connect(webView, SIGNAL(linkClicked(const QUrl &)), SLOT(linkClicked(const QUrl &)), Qt::DirectConnection); connect(webView, SIGNAL(loadFinished(bool)), SLOT(toggleUpdate()), Qt::DirectConnection); connect(webView, SIGNAL(loadStarted()), SLOT(toggleUpdate()), Qt::DirectConnection); setCentralWidget(graphicsView); // Initializing QSP QSPInit(); QSPCallback::QSPCallback(); // qDebug() << "QSP init finished"; }