src/platform/qt/Window.cpp (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "Window.h"
7
8#include <QFileDialog>
9#include <QKeyEvent>
10#include <QKeySequence>
11#include <QMenuBar>
12#include <QMessageBox>
13#include <QStackedLayout>
14
15#include "ConfigController.h"
16#include "GameController.h"
17#include "GBAKeyEditor.h"
18#include "GDBController.h"
19#include "GDBWindow.h"
20#include "GIFView.h"
21#include "LoadSaveState.h"
22#include "LogView.h"
23#include "SettingsView.h"
24#include "VideoView.h"
25
26extern "C" {
27#include "platform/commandline.h"
28}
29
30using namespace QGBA;
31
32Window::Window(ConfigController* config, QWidget* parent)
33 : QMainWindow(parent)
34 , m_logView(new LogView())
35 , m_stateWindow(nullptr)
36 , m_screenWidget(new WindowBackground())
37 , m_logo(":/res/mgba-1024.png")
38 , m_config(config)
39#ifdef USE_FFMPEG
40 , m_videoView(nullptr)
41#endif
42#ifdef USE_MAGICK
43 , m_gifView(nullptr)
44#endif
45#ifdef USE_GDB_STUB
46 , m_gdbController(nullptr)
47#endif
48{
49 setWindowTitle(PROJECT_NAME);
50 setFocusPolicy(Qt::StrongFocus);
51 m_controller = new GameController(this);
52 m_controller->setInputController(&m_inputController);
53
54 QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
55 format.setSwapInterval(1);
56 m_display = new Display(format);
57
58 m_screenWidget->setMinimumSize(m_display->minimumSize());
59 m_screenWidget->setSizePolicy(m_display->sizePolicy());
60 m_screenWidget->setSizeHint(m_display->minimumSize() * 2);
61 setCentralWidget(m_screenWidget);
62
63 connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*)));
64 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing()));
65 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
66 connect(m_controller, SIGNAL(stateLoaded(GBAThread*)), m_display, SLOT(forceDraw()));
67 connect(m_controller, SIGNAL(gamePaused(GBAThread*)), m_display, SLOT(pauseDrawing()));
68#ifndef Q_OS_MAC
69 connect(m_controller, SIGNAL(gamePaused(GBAThread*)), menuBar(), SLOT(show()));
70 connect(m_controller, &GameController::gameUnpaused, [this]() {
71 if(isFullScreen()) {
72 menuBar()->hide();
73 }
74 });
75#endif
76 connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), m_display, SLOT(unpauseDrawing()));
77 connect(m_controller, SIGNAL(postLog(int, const QString&)), m_logView, SLOT(postLog(int, const QString&)));
78 connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(recordFrame()));
79 connect(m_controller, SIGNAL(gameCrashed(const QString&)), this, SLOT(gameCrashed(const QString&)));
80 connect(m_logView, SIGNAL(levelsSet(int)), m_controller, SLOT(setLogLevel(int)));
81 connect(m_logView, SIGNAL(levelsEnabled(int)), m_controller, SLOT(enableLogLevel(int)));
82 connect(m_logView, SIGNAL(levelsDisabled(int)), m_controller, SLOT(disableLogLevel(int)));
83 connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection);
84 connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing()));
85 connect(this, SIGNAL(shutdown()), m_controller, SLOT(closeGame()));
86 connect(this, SIGNAL(shutdown()), m_logView, SLOT(hide()));
87 connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int)));
88 connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float)));
89 connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS()));
90
91 m_logView->setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL);
92 m_fpsTimer.setInterval(FPS_TIMER_INTERVAL);
93
94 setupMenu(menuBar());
95}
96
97Window::~Window() {
98 delete m_logView;
99
100#ifdef USE_FFMPEG
101 delete m_videoView;
102#endif
103
104#ifdef USE_MAGICK
105 delete m_gifView;
106#endif
107}
108
109void Window::argumentsPassed(GBAArguments* args) {
110 loadConfig();
111
112 if (args->patch) {
113 m_controller->loadPatch(args->patch);
114 }
115
116 if (args->fname) {
117 m_controller->loadGame(args->fname, args->dirmode);
118 }
119}
120
121void Window::resizeFrame(int width, int height) {
122 QSize newSize(width, height);
123 newSize -= m_screenWidget->size();
124 newSize += size();
125 resize(newSize);
126}
127
128void Window::setConfig(ConfigController* config) {
129 m_config = config;
130}
131
132void Window::loadConfig() {
133 const GBAOptions* opts = m_config->options();
134
135 m_logView->setLevels(opts->logLevel);
136
137 m_controller->setFrameskip(opts->frameskip);
138 m_controller->setAudioSync(opts->audioSync);
139 m_controller->setVideoSync(opts->videoSync);
140 m_display->lockAspectRatio(opts->lockAspectRatio);
141 m_display->filter(opts->resampleVideo);
142
143 if (opts->bios) {
144 m_controller->loadBIOS(opts->bios);
145 }
146
147 if (opts->fpsTarget) {
148 emit fpsTargetChanged(opts->fpsTarget);
149 }
150
151 if (opts->audioBuffers) {
152 emit audioBufferSamplesChanged(opts->audioBuffers);
153 }
154
155 if (opts->width && opts->height) {
156 m_screenWidget->setSizeHint(QSize(opts->width, opts->height));
157 }
158
159 m_inputController.setConfiguration(m_config);
160}
161
162void Window::saveConfig() {
163 m_config->write();
164}
165
166void Window::selectROM() {
167 QString filename = QFileDialog::getOpenFileName(this, tr("Select ROM"));
168 if (!filename.isEmpty()) {
169 m_controller->loadGame(filename);
170 }
171}
172
173void Window::selectBIOS() {
174 QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS"));
175 if (!filename.isEmpty()) {
176 m_config->setOption("bios", filename);
177 m_config->updateOption("bios");
178 m_controller->loadBIOS(filename);
179 }
180}
181
182void Window::selectPatch() {
183 QString filename = QFileDialog::getOpenFileName(this, tr("Select patch"), QString(), tr("Patches (*.ips *.ups)"));
184 if (!filename.isEmpty()) {
185 m_controller->loadPatch(filename);
186 }
187}
188
189void Window::openKeymapWindow() {
190 GBAKeyEditor* keyEditor = new GBAKeyEditor(&m_inputController, InputController::KEYBOARD);
191 connect(this, SIGNAL(shutdown()), keyEditor, SLOT(close()));
192 keyEditor->setAttribute(Qt::WA_DeleteOnClose);
193 keyEditor->show();
194}
195
196void Window::openSettingsWindow() {
197 SettingsView* settingsWindow = new SettingsView(m_config);
198 connect(this, SIGNAL(shutdown()), settingsWindow, SLOT(close()));
199 connect(settingsWindow, SIGNAL(biosLoaded(const QString&)), m_controller, SLOT(loadBIOS(const QString&)));
200 settingsWindow->setAttribute(Qt::WA_DeleteOnClose);
201 settingsWindow->show();
202}
203
204#ifdef BUILD_SDL
205void Window::openGamepadWindow() {
206 GBAKeyEditor* keyEditor = new GBAKeyEditor(&m_inputController, SDL_BINDING_BUTTON);
207 connect(this, SIGNAL(shutdown()), keyEditor, SLOT(close()));
208 keyEditor->setAttribute(Qt::WA_DeleteOnClose);
209 keyEditor->show();
210}
211#endif
212
213#ifdef USE_FFMPEG
214void Window::openVideoWindow() {
215 if (!m_videoView) {
216 m_videoView = new VideoView();
217 connect(m_videoView, SIGNAL(recordingStarted(GBAAVStream*)), m_controller, SLOT(setAVStream(GBAAVStream*)));
218 connect(m_videoView, SIGNAL(recordingStopped()), m_controller, SLOT(clearAVStream()), Qt::DirectConnection);
219 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_videoView, SLOT(stopRecording()));
220 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_videoView, SLOT(close()));
221 connect(this, SIGNAL(shutdown()), m_videoView, SLOT(close()));
222 }
223 m_videoView->show();
224}
225#endif
226
227#ifdef USE_MAGICK
228void Window::openGIFWindow() {
229 if (!m_gifView) {
230 m_gifView = new GIFView();
231 connect(m_gifView, SIGNAL(recordingStarted(GBAAVStream*)), m_controller, SLOT(setAVStream(GBAAVStream*)));
232 connect(m_gifView, SIGNAL(recordingStopped()), m_controller, SLOT(clearAVStream()), Qt::DirectConnection);
233 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_gifView, SLOT(stopRecording()));
234 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_gifView, SLOT(close()));
235 connect(this, SIGNAL(shutdown()), m_gifView, SLOT(close()));
236 }
237 m_gifView->show();
238}
239#endif
240
241#ifdef USE_GDB_STUB
242void Window::gdbOpen() {
243 if (!m_gdbController) {
244 m_gdbController = new GDBController(m_controller, this);
245 }
246 GDBWindow* window = new GDBWindow(m_gdbController);
247 window->show();
248}
249#endif
250
251void Window::keyPressEvent(QKeyEvent* event) {
252 if (event->isAutoRepeat()) {
253 QWidget::keyPressEvent(event);
254 return;
255 }
256 if (event->key() == Qt::Key_Tab) {
257 m_controller->setTurbo(true, false);
258 }
259 GBAKey key = m_inputController.mapKeyboard(event->key());
260 if (key == GBA_KEY_NONE) {
261 QWidget::keyPressEvent(event);
262 return;
263 }
264 m_controller->keyPressed(key);
265 event->accept();
266}
267
268void Window::keyReleaseEvent(QKeyEvent* event) {
269 if (event->isAutoRepeat()) {
270 QWidget::keyReleaseEvent(event);
271 return;
272 }
273 if (event->key() == Qt::Key_Tab) {
274 m_controller->setTurbo(false, false);
275 }
276 GBAKey key = m_inputController.mapKeyboard(event->key());
277 if (key == GBA_KEY_NONE) {
278 QWidget::keyPressEvent(event);
279 return;
280 }
281 m_controller->keyReleased(key);
282 event->accept();
283}
284
285void Window::resizeEvent(QResizeEvent*) {
286 redoLogo();
287 m_config->setOption("height", m_screenWidget->height());
288 m_config->setOption("width", m_screenWidget->width());
289}
290
291void Window::closeEvent(QCloseEvent* event) {
292 emit shutdown();
293 QMainWindow::closeEvent(event);
294}
295
296void Window::toggleFullScreen() {
297 if (isFullScreen()) {
298 showNormal();
299 menuBar()->show();
300 } else {
301 showFullScreen();
302#ifndef Q_OS_MAC
303 if (m_controller->isLoaded() && !m_controller->isPaused()) {
304 menuBar()->hide();
305 }
306#endif
307 }
308}
309
310void Window::gameStarted(GBAThread* context) {
311 emit startDrawing(m_controller->drawContext(), context);
312 foreach (QAction* action, m_gameActions) {
313 action->setDisabled(false);
314 }
315 char title[13] = { '\0' };
316 GBAGetGameTitle(context->gba, title);
317 setWindowTitle(tr(PROJECT_NAME " - %1").arg(title));
318 attachWidget(m_display);
319 m_screenWidget->setScaledContents(true);
320
321#ifndef Q_OS_MAC
322 if(isFullScreen()) {
323 menuBar()->hide();
324 }
325#endif
326
327 m_fpsTimer.start();
328}
329
330void Window::gameStopped() {
331 foreach (QAction* action, m_gameActions) {
332 action->setDisabled(true);
333 }
334 setWindowTitle(tr(PROJECT_NAME));
335 detachWidget(m_display);
336 m_screenWidget->setScaledContents(false);
337 redoLogo();
338
339 m_fpsTimer.stop();
340}
341
342void Window::gameCrashed(const QString& errorMessage) {
343 QMessageBox* crash = new QMessageBox(QMessageBox::Critical, tr("Crash"),
344 tr("The game has crashed with the following error:\n\n%1").arg(errorMessage),
345 QMessageBox::Ok, this, Qt::Sheet);
346 crash->setAttribute(Qt::WA_DeleteOnClose);
347 crash->show();
348}
349
350void Window::redoLogo() {
351 if (m_controller->isLoaded()) {
352 return;
353 }
354 QPixmap logo(m_logo.scaled(m_screenWidget->size() * m_screenWidget->devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
355 logo.setDevicePixelRatio(m_screenWidget->devicePixelRatio());
356 m_screenWidget->setPixmap(logo);
357}
358
359void Window::recordFrame() {
360 m_frameList.append(QDateTime::currentDateTime());
361 while (m_frameList.count() > FRAME_LIST_SIZE) {
362 m_frameList.removeFirst();
363 }
364}
365
366void Window::showFPS() {
367 qint64 interval = m_frameList.first().msecsTo(m_frameList.last());
368 float fps = (m_frameList.count() - 1) * 10000.f / interval;
369 fps = round(fps) / 10.f;
370 char title[13] = { '\0' };
371 GBAGetGameTitle(m_controller->thread()->gba, title);
372 setWindowTitle(tr(PROJECT_NAME " - %1 (%2 fps)").arg(title).arg(fps));
373}
374
375void Window::openStateWindow(LoadSave ls) {
376 if (m_stateWindow) {
377 return;
378 }
379 bool wasPaused = m_controller->isPaused();
380 m_stateWindow = new LoadSaveState(m_controller);
381 connect(this, SIGNAL(shutdown()), m_stateWindow, SLOT(close()));
382 connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_stateWindow, SLOT(close()));
383 connect(m_stateWindow, &LoadSaveState::closed, [this]() {
384 m_screenWidget->layout()->removeWidget(m_stateWindow);
385 m_stateWindow = nullptr;
386 setFocus();
387 });
388 if (!wasPaused) {
389 m_controller->setPaused(true);
390 connect(m_stateWindow, &LoadSaveState::closed, [this]() { m_controller->setPaused(false); });
391 }
392 m_stateWindow->setAttribute(Qt::WA_DeleteOnClose);
393 m_stateWindow->setMode(ls);
394 attachWidget(m_stateWindow);
395}
396
397void Window::setupMenu(QMenuBar* menubar) {
398 menubar->clear();
399 QMenu* fileMenu = menubar->addMenu(tr("&File"));
400 addAction(fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open));
401 fileMenu->addAction(tr("Load &BIOS..."), this, SLOT(selectBIOS()));
402 fileMenu->addAction(tr("Load &patch..."), this, SLOT(selectPatch()));
403
404 fileMenu->addSeparator();
405
406 QAction* loadState = new QAction(tr("&Load state"), fileMenu);
407 loadState->setShortcut(tr("F10"));
408 connect(loadState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::LOAD); });
409 m_gameActions.append(loadState);
410 addAction(loadState);
411 fileMenu->addAction(loadState);
412
413 QAction* saveState = new QAction(tr("&Save state"), fileMenu);
414 saveState->setShortcut(tr("Shift+F10"));
415 connect(saveState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::SAVE); });
416 m_gameActions.append(saveState);
417 addAction(saveState);
418 fileMenu->addAction(saveState);
419
420 QMenu* quickLoadMenu = fileMenu->addMenu(tr("Quick load"));
421 QMenu* quickSaveMenu = fileMenu->addMenu(tr("Quick save"));
422 int i;
423 for (i = 1; i < 10; ++i) {
424 QAction* quickLoad = new QAction(tr("State &%1").arg(i), quickLoadMenu);
425 quickLoad->setShortcut(tr("F%1").arg(i));
426 connect(quickLoad, &QAction::triggered, [this, i]() { m_controller->loadState(i); });
427 m_gameActions.append(quickLoad);
428 addAction(quickLoad);
429 quickLoadMenu->addAction(quickLoad);
430
431 QAction* quickSave = new QAction(tr("State &%1").arg(i), quickSaveMenu);
432 quickSave->setShortcut(tr("Shift+F%1").arg(i));
433 connect(quickSave, &QAction::triggered, [this, i]() { m_controller->saveState(i); });
434 m_gameActions.append(quickSave);
435 addAction(quickSave);
436 quickSaveMenu->addAction(quickSave);
437 }
438
439#ifndef Q_OS_MAC
440 fileMenu->addSeparator();
441#endif
442 fileMenu->addAction(tr("Settings"), this, SLOT(openSettingsWindow()));
443
444#ifndef Q_OS_MAC
445 fileMenu->addSeparator();
446 fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit);
447#endif
448
449 QMenu* emulationMenu = menubar->addMenu(tr("&Emulation"));
450 QAction* reset = new QAction(tr("&Reset"), emulationMenu);
451 reset->setShortcut(tr("Ctrl+R"));
452 connect(reset, SIGNAL(triggered()), m_controller, SLOT(reset()));
453 m_gameActions.append(reset);
454 addAction(reset);
455 emulationMenu->addAction(reset);
456
457 QAction* shutdown = new QAction(tr("Sh&utdown"), emulationMenu);
458 connect(shutdown, SIGNAL(triggered()), m_controller, SLOT(closeGame()));
459 m_gameActions.append(shutdown);
460 emulationMenu->addAction(shutdown);
461 emulationMenu->addSeparator();
462
463 QAction* pause = new QAction(tr("&Pause"), emulationMenu);
464 pause->setChecked(false);
465 pause->setCheckable(true);
466 pause->setShortcut(tr("Ctrl+P"));
467 connect(pause, SIGNAL(triggered(bool)), m_controller, SLOT(setPaused(bool)));
468 connect(m_controller, &GameController::gamePaused, [this, pause]() {
469 pause->setChecked(true);
470
471 QImage currentImage(reinterpret_cast<const uchar*>(m_controller->drawContext()), VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 1024, QImage::Format_RGB32);
472 QPixmap pixmap;
473 pixmap.convertFromImage(currentImage.rgbSwapped());
474 m_screenWidget->setPixmap(pixmap);
475 });
476 connect(m_controller, &GameController::gameUnpaused, [pause]() { pause->setChecked(false); });
477 m_gameActions.append(pause);
478 addAction(pause);
479 emulationMenu->addAction(pause);
480
481 QAction* frameAdvance = new QAction(tr("&Next frame"), emulationMenu);
482 frameAdvance->setShortcut(tr("Ctrl+N"));
483 connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance()));
484 m_gameActions.append(frameAdvance);
485 addAction(frameAdvance);
486 emulationMenu->addAction(frameAdvance);
487
488 emulationMenu->addSeparator();
489
490 QAction* turbo = new QAction(tr("T&urbo"), emulationMenu);
491 turbo->setCheckable(true);
492 turbo->setChecked(false);
493 turbo->setShortcut(tr("Shift+Tab"));
494 connect(turbo, SIGNAL(triggered(bool)), m_controller, SLOT(setTurbo(bool)));
495 addAction(turbo);
496 emulationMenu->addAction(turbo);
497
498 ConfigOption* videoSync = m_config->addOption("videoSync");
499 videoSync->addBoolean(tr("Sync to &video"), emulationMenu);
500 videoSync->connect([this](const QVariant& value) { m_controller->setVideoSync(value.toBool()); });
501 m_config->updateOption("videoSync");
502
503 ConfigOption* audioSync = m_config->addOption("audioSync");
504 audioSync->addBoolean(tr("Sync to &audio"), emulationMenu);
505 audioSync->connect([this](const QVariant& value) { m_controller->setAudioSync(value.toBool()); });
506 m_config->updateOption("audioSync");
507
508 emulationMenu->addSeparator();
509 QAction* keymap = new QAction(tr("Remap keyboard..."), emulationMenu);
510 connect(keymap, SIGNAL(triggered()), this, SLOT(openKeymapWindow()));
511 emulationMenu->addAction(keymap);
512
513#ifdef BUILD_SDL
514 QAction* gamepad = new QAction(tr("Remap gamepad..."), emulationMenu);
515 connect(gamepad, SIGNAL(triggered()), this, SLOT(openGamepadWindow()));
516 emulationMenu->addAction(gamepad);
517#endif
518
519 QMenu* avMenu = menubar->addMenu(tr("Audio/&Video"));
520 QMenu* frameMenu = avMenu->addMenu(tr("Frame size"));
521 for (int i = 1; i <= 6; ++i) {
522 QAction* setSize = new QAction(tr("%1x").arg(QString::number(i)), avMenu);
523 connect(setSize, &QAction::triggered, [this, i]() {
524 showNormal();
525 resizeFrame(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i);
526 });
527 frameMenu->addAction(setSize);
528 }
529 addAction(frameMenu->addAction(tr("Fullscreen"), this, SLOT(toggleFullScreen()), QKeySequence("Ctrl+F")));
530
531 ConfigOption* lockAspectRatio = m_config->addOption("lockAspectRatio");
532 lockAspectRatio->addBoolean(tr("Lock aspect ratio"), avMenu);
533 lockAspectRatio->connect([this](const QVariant& value) { m_display->lockAspectRatio(value.toBool()); });
534 m_config->updateOption("lockAspectRatio");
535
536 ConfigOption* resampleVideo = m_config->addOption("resampleVideo");
537 resampleVideo->addBoolean(tr("Resample video"), avMenu);
538 resampleVideo->connect([this](const QVariant& value) { m_display->filter(value.toBool()); });
539 m_config->updateOption("resampleVideo");
540
541 QMenu* skipMenu = avMenu->addMenu(tr("Frame&skip"));
542 ConfigOption* skip = m_config->addOption("frameskip");
543 skip->connect([this](const QVariant& value) { m_controller->setFrameskip(value.toInt()); });
544 for (int i = 0; i <= 10; ++i) {
545 skip->addValue(QString::number(i), i, skipMenu);
546 }
547 m_config->updateOption("frameskip");
548
549 avMenu->addSeparator();
550
551 QMenu* buffersMenu = avMenu->addMenu(tr("Audio buffer &size"));
552 ConfigOption* buffers = m_config->addOption("audioBuffers");
553 buffers->connect([this](const QVariant& value) { emit audioBufferSamplesChanged(value.toInt()); });
554 buffers->addValue(tr("512"), 512, buffersMenu);
555 buffers->addValue(tr("768"), 768, buffersMenu);
556 buffers->addValue(tr("1024"), 1024, buffersMenu);
557 buffers->addValue(tr("2048"), 2048, buffersMenu);
558 buffers->addValue(tr("4096"), 4096, buffersMenu);
559 m_config->updateOption("audioBuffers");
560
561 avMenu->addSeparator();
562
563 QMenu* target = avMenu->addMenu("FPS target");
564 ConfigOption* fpsTargetOption = m_config->addOption("fpsTarget");
565 fpsTargetOption->connect([this](const QVariant& value) { emit fpsTargetChanged(value.toInt()); });
566 fpsTargetOption->addValue(tr("15"), 15, target);
567 fpsTargetOption->addValue(tr("30"), 30, target);
568 fpsTargetOption->addValue(tr("45"), 45, target);
569 fpsTargetOption->addValue(tr("60"), 60, target);
570 fpsTargetOption->addValue(tr("90"), 90, target);
571 fpsTargetOption->addValue(tr("120"), 120, target);
572 fpsTargetOption->addValue(tr("240"), 240, target);
573 m_config->updateOption("fpsTarget");
574
575#if defined(USE_PNG) || defined(USE_FFMPEG) || defined(USE_MAGICK)
576 avMenu->addSeparator();
577#endif
578
579#ifdef USE_PNG
580 QAction* screenshot = new QAction(tr("Take &screenshot"), avMenu);
581 screenshot->setShortcut(tr("F12"));
582 connect(screenshot, SIGNAL(triggered()), m_display, SLOT(screenshot()));
583 m_gameActions.append(screenshot);
584 addAction(screenshot);
585 avMenu->addAction(screenshot);
586#endif
587
588#ifdef USE_FFMPEG
589 QAction* recordOutput = new QAction(tr("Record output..."), avMenu);
590 recordOutput->setShortcut(tr("F11"));
591 connect(recordOutput, SIGNAL(triggered()), this, SLOT(openVideoWindow()));
592 addAction(recordOutput);
593 avMenu->addAction(recordOutput);
594#endif
595
596#ifdef USE_MAGICK
597 QAction* recordGIF = new QAction(tr("Record GIF..."), avMenu);
598 recordGIF->setShortcut(tr("Shift+F11"));
599 connect(recordGIF, SIGNAL(triggered()), this, SLOT(openGIFWindow()));
600 addAction(recordGIF);
601 avMenu->addAction(recordGIF);
602#endif
603
604 QMenu* debuggingMenu = menubar->addMenu(tr("&Debugging"));
605 QAction* viewLogs = new QAction(tr("View &logs..."), debuggingMenu);
606 connect(viewLogs, SIGNAL(triggered()), m_logView, SLOT(show()));
607 debuggingMenu->addAction(viewLogs);
608#ifdef USE_GDB_STUB
609 QAction* gdbWindow = new QAction(tr("Start &GDB server..."), debuggingMenu);
610 connect(gdbWindow, SIGNAL(triggered()), this, SLOT(gdbOpen()));
611 debuggingMenu->addAction(gdbWindow);
612#endif
613
614 foreach (QAction* action, m_gameActions) {
615 action->setDisabled(true);
616 }
617}
618
619void Window::attachWidget(QWidget* widget) {
620 m_screenWidget->layout()->addWidget(widget);
621 static_cast<QStackedLayout*>(m_screenWidget->layout())->setCurrentWidget(widget);
622}
623
624void Window::detachWidget(QWidget* widget) {
625 m_screenWidget->layout()->removeWidget(widget);
626}
627
628WindowBackground::WindowBackground(QWidget* parent)
629 : QLabel(parent)
630{
631 setLayout(new QStackedLayout());
632 layout()->setContentsMargins(0, 0, 0, 0);
633 setAlignment(Qt::AlignCenter);
634 QPalette p = palette();
635 p.setColor(backgroundRole(), Qt::black);
636 setPalette(p);
637 setAutoFillBackground(true);
638}
639
640void WindowBackground::setSizeHint(const QSize& hint) {
641 m_sizeHint = hint;
642}
643
644QSize WindowBackground::sizeHint() const {
645 return m_sizeHint;
646}