all repos — mgba @ 458df43d1890b3918e5e19f2b319d11a524eb0de

mGBA Game Boy Advance Emulator

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_controller->setSkipBIOS(opts->skipBios);
141	m_display->lockAspectRatio(opts->lockAspectRatio);
142	m_display->filter(opts->resampleVideo);
143
144	if (opts->bios) {
145		m_controller->loadBIOS(opts->bios);
146	}
147
148	if (opts->fpsTarget) {
149		emit fpsTargetChanged(opts->fpsTarget);
150	}
151
152	if (opts->audioBuffers) {
153		emit audioBufferSamplesChanged(opts->audioBuffers);
154	}
155
156	if (opts->width && opts->height) {
157		m_screenWidget->setSizeHint(QSize(opts->width, opts->height));
158	}
159
160	m_inputController.setConfiguration(m_config);
161}
162
163void Window::saveConfig() {
164	m_config->write();
165}
166
167void Window::selectROM() {
168	QString filename = QFileDialog::getOpenFileName(this, tr("Select ROM"));
169	if (!filename.isEmpty()) {
170		m_controller->loadGame(filename);
171	}
172}
173
174void Window::selectBIOS() {
175	QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS"));
176	if (!filename.isEmpty()) {
177		m_config->setOption("bios", filename);
178		m_config->updateOption("bios");
179		m_controller->loadBIOS(filename);
180	}
181}
182
183void Window::selectPatch() {
184	QString filename = QFileDialog::getOpenFileName(this, tr("Select patch"), QString(), tr("Patches (*.ips *.ups)"));
185	if (!filename.isEmpty()) {
186		m_controller->loadPatch(filename);
187	}
188}
189
190void Window::openKeymapWindow() {
191	GBAKeyEditor* keyEditor = new GBAKeyEditor(&m_inputController, InputController::KEYBOARD);
192	connect(this, SIGNAL(shutdown()), keyEditor, SLOT(close()));
193	keyEditor->setAttribute(Qt::WA_DeleteOnClose);
194	keyEditor->show();
195}
196
197void Window::openSettingsWindow() {
198	SettingsView* settingsWindow = new SettingsView(m_config);
199	connect(this, SIGNAL(shutdown()), settingsWindow, SLOT(close()));
200	connect(settingsWindow, SIGNAL(biosLoaded(const QString&)), m_controller, SLOT(loadBIOS(const QString&)));
201	settingsWindow->setAttribute(Qt::WA_DeleteOnClose);
202	settingsWindow->show();
203}
204
205#ifdef BUILD_SDL
206void Window::openGamepadWindow() {
207	GBAKeyEditor* keyEditor = new GBAKeyEditor(&m_inputController, SDL_BINDING_BUTTON);
208	connect(this, SIGNAL(shutdown()), keyEditor, SLOT(close()));
209	keyEditor->setAttribute(Qt::WA_DeleteOnClose);
210	keyEditor->show();
211}
212#endif
213
214#ifdef USE_FFMPEG
215void Window::openVideoWindow() {
216	if (!m_videoView) {
217		m_videoView = new VideoView();
218		connect(m_videoView, SIGNAL(recordingStarted(GBAAVStream*)), m_controller, SLOT(setAVStream(GBAAVStream*)));
219		connect(m_videoView, SIGNAL(recordingStopped()), m_controller, SLOT(clearAVStream()), Qt::DirectConnection);
220		connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_videoView, SLOT(stopRecording()));
221		connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_videoView, SLOT(close()));
222		connect(this, SIGNAL(shutdown()), m_videoView, SLOT(close()));
223	}
224	m_videoView->show();
225}
226#endif
227
228#ifdef USE_MAGICK
229void Window::openGIFWindow() {
230	if (!m_gifView) {
231		m_gifView = new GIFView();
232		connect(m_gifView, SIGNAL(recordingStarted(GBAAVStream*)), m_controller, SLOT(setAVStream(GBAAVStream*)));
233		connect(m_gifView, SIGNAL(recordingStopped()), m_controller, SLOT(clearAVStream()), Qt::DirectConnection);
234		connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_gifView, SLOT(stopRecording()));
235		connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_gifView, SLOT(close()));
236		connect(this, SIGNAL(shutdown()), m_gifView, SLOT(close()));
237	}
238	m_gifView->show();
239}
240#endif
241
242#ifdef USE_GDB_STUB
243void Window::gdbOpen() {
244	if (!m_gdbController) {
245		m_gdbController = new GDBController(m_controller, this);
246	}
247	GDBWindow* window = new GDBWindow(m_gdbController);
248	window->show();
249}
250#endif
251
252void Window::keyPressEvent(QKeyEvent* event) {
253	if (event->isAutoRepeat()) {
254		QWidget::keyPressEvent(event);
255		return;
256	}
257	if (event->key() == Qt::Key_Tab) {
258		m_controller->setTurbo(true, false);
259	}
260	GBAKey key = m_inputController.mapKeyboard(event->key());
261	if (key == GBA_KEY_NONE) {
262		QWidget::keyPressEvent(event);
263		return;
264	}
265	m_controller->keyPressed(key);
266	event->accept();
267}
268
269void Window::keyReleaseEvent(QKeyEvent* event) {
270	if (event->isAutoRepeat()) {
271		QWidget::keyReleaseEvent(event);
272		return;
273	}
274	if (event->key() == Qt::Key_Tab) {
275		m_controller->setTurbo(false, false);
276	}
277	GBAKey key = m_inputController.mapKeyboard(event->key());
278	if (key == GBA_KEY_NONE) {
279		QWidget::keyPressEvent(event);
280		return;
281	}
282	m_controller->keyReleased(key);
283	event->accept();
284}
285
286void Window::resizeEvent(QResizeEvent*) {
287	redoLogo();
288	m_config->setOption("height", m_screenWidget->height());
289	m_config->setOption("width", m_screenWidget->width());
290}
291
292void Window::closeEvent(QCloseEvent* event) {
293	emit shutdown();
294	QMainWindow::closeEvent(event);
295}
296
297void Window::toggleFullScreen() {
298	if (isFullScreen()) {
299		showNormal();
300		menuBar()->show();
301	} else {
302		showFullScreen();
303#ifndef Q_OS_MAC
304		if (m_controller->isLoaded() && !m_controller->isPaused()) {
305			menuBar()->hide();
306		}
307#endif
308	}
309}
310
311void Window::gameStarted(GBAThread* context) {
312	emit startDrawing(m_controller->drawContext(), context);
313	foreach (QAction* action, m_gameActions) {
314		action->setDisabled(false);
315	}
316	char title[13] = { '\0' };
317	GBAGetGameTitle(context->gba, title);
318	setWindowTitle(tr(PROJECT_NAME " - %1").arg(title));
319	attachWidget(m_display);
320	m_screenWidget->setScaledContents(true);
321
322#ifndef Q_OS_MAC
323	if(isFullScreen()) {
324		menuBar()->hide();
325	}
326#endif
327
328	m_fpsTimer.start();
329}
330
331void Window::gameStopped() {
332	foreach (QAction* action, m_gameActions) {
333		action->setDisabled(true);
334	}
335	setWindowTitle(tr(PROJECT_NAME));
336	detachWidget(m_display);
337	m_screenWidget->setScaledContents(false);
338	redoLogo();
339
340	m_fpsTimer.stop();
341}
342
343void Window::gameCrashed(const QString& errorMessage) {
344	QMessageBox* crash = new QMessageBox(QMessageBox::Critical, tr("Crash"),
345		tr("The game has crashed with the following error:\n\n%1").arg(errorMessage),
346		QMessageBox::Ok, this,  Qt::Sheet);
347	crash->setAttribute(Qt::WA_DeleteOnClose);
348	crash->show();
349}
350
351void Window::redoLogo() {
352	if (m_controller->isLoaded()) {
353		return;
354	}
355	QPixmap logo(m_logo.scaled(m_screenWidget->size() * m_screenWidget->devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
356	logo.setDevicePixelRatio(m_screenWidget->devicePixelRatio());
357	m_screenWidget->setPixmap(logo);
358}
359
360void Window::recordFrame() {
361	m_frameList.append(QDateTime::currentDateTime());
362	while (m_frameList.count() > FRAME_LIST_SIZE) {
363		m_frameList.removeFirst();
364	}
365}
366
367void Window::showFPS() {
368	qint64 interval = m_frameList.first().msecsTo(m_frameList.last());
369	float fps = (m_frameList.count() - 1) * 10000.f / interval;
370	fps = round(fps) / 10.f;
371	char title[13] = { '\0' };
372	GBAGetGameTitle(m_controller->thread()->gba, title);
373	setWindowTitle(tr(PROJECT_NAME " - %1 (%2 fps)").arg(title).arg(fps));
374}
375
376void Window::openStateWindow(LoadSave ls) {
377	if (m_stateWindow) {
378		return;
379	}
380	bool wasPaused = m_controller->isPaused();
381	m_stateWindow = new LoadSaveState(m_controller);
382	connect(this, SIGNAL(shutdown()), m_stateWindow, SLOT(close()));
383	connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_stateWindow, SLOT(close()));
384	connect(m_stateWindow, &LoadSaveState::closed, [this]() {
385		m_screenWidget->layout()->removeWidget(m_stateWindow);
386		m_stateWindow = nullptr;
387		setFocus();
388	});
389	if (!wasPaused) {
390		m_controller->setPaused(true);
391		connect(m_stateWindow, &LoadSaveState::closed, [this]() { m_controller->setPaused(false); });
392	}
393	m_stateWindow->setAttribute(Qt::WA_DeleteOnClose);
394	m_stateWindow->setMode(ls);
395	attachWidget(m_stateWindow);
396}
397
398void Window::setupMenu(QMenuBar* menubar) {
399	menubar->clear();
400	QMenu* fileMenu = menubar->addMenu(tr("&File"));
401	addAction(fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open));
402	fileMenu->addAction(tr("Load &BIOS..."), this, SLOT(selectBIOS()));
403	fileMenu->addAction(tr("Load &patch..."), this, SLOT(selectPatch()));
404
405	fileMenu->addSeparator();
406
407	QAction* loadState = new QAction(tr("&Load state"), fileMenu);
408	loadState->setShortcut(tr("F10"));
409	connect(loadState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::LOAD); });
410	m_gameActions.append(loadState);
411	addAction(loadState);
412	fileMenu->addAction(loadState);
413
414	QAction* saveState = new QAction(tr("&Save state"), fileMenu);
415	saveState->setShortcut(tr("Shift+F10"));
416	connect(saveState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::SAVE); });
417	m_gameActions.append(saveState);
418	addAction(saveState);
419	fileMenu->addAction(saveState);
420
421	QMenu* quickLoadMenu = fileMenu->addMenu(tr("Quick load"));
422	QMenu* quickSaveMenu = fileMenu->addMenu(tr("Quick save"));
423	int i;
424	for (i = 1; i < 10; ++i) {
425		QAction* quickLoad = new QAction(tr("State &%1").arg(i), quickLoadMenu);
426		quickLoad->setShortcut(tr("F%1").arg(i));
427		connect(quickLoad, &QAction::triggered, [this, i]() { m_controller->loadState(i); });
428		m_gameActions.append(quickLoad);
429		addAction(quickLoad);
430		quickLoadMenu->addAction(quickLoad);
431
432		QAction* quickSave = new QAction(tr("State &%1").arg(i), quickSaveMenu);
433		quickSave->setShortcut(tr("Shift+F%1").arg(i));
434		connect(quickSave, &QAction::triggered, [this, i]() { m_controller->saveState(i); });
435		m_gameActions.append(quickSave);
436		addAction(quickSave);
437		quickSaveMenu->addAction(quickSave);
438	}
439
440#ifndef Q_OS_MAC
441	fileMenu->addSeparator();
442#endif
443      fileMenu->addAction(tr("Settings"), this, SLOT(openSettingsWindow()));
444
445#ifndef Q_OS_MAC
446      fileMenu->addSeparator();
447	fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit);
448#endif
449
450	QMenu* emulationMenu = menubar->addMenu(tr("&Emulation"));
451	QAction* reset = new QAction(tr("&Reset"), emulationMenu);
452	reset->setShortcut(tr("Ctrl+R"));
453	connect(reset, SIGNAL(triggered()), m_controller, SLOT(reset()));
454	m_gameActions.append(reset);
455	addAction(reset);
456	emulationMenu->addAction(reset);
457
458	QAction* shutdown = new QAction(tr("Sh&utdown"), emulationMenu);
459	connect(shutdown, SIGNAL(triggered()), m_controller, SLOT(closeGame()));
460	m_gameActions.append(shutdown);
461	emulationMenu->addAction(shutdown);
462	emulationMenu->addSeparator();
463
464	QAction* pause = new QAction(tr("&Pause"), emulationMenu);
465	pause->setChecked(false);
466	pause->setCheckable(true);
467	pause->setShortcut(tr("Ctrl+P"));
468	connect(pause, SIGNAL(triggered(bool)), m_controller, SLOT(setPaused(bool)));
469	connect(m_controller, &GameController::gamePaused, [this, pause]() {
470		pause->setChecked(true);
471
472		QImage currentImage(reinterpret_cast<const uchar*>(m_controller->drawContext()), VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, 1024, QImage::Format_RGB32);
473		QPixmap pixmap;
474		pixmap.convertFromImage(currentImage.rgbSwapped());
475		m_screenWidget->setPixmap(pixmap);
476	});
477	connect(m_controller, &GameController::gameUnpaused, [pause]() { pause->setChecked(false); });
478	m_gameActions.append(pause);
479	addAction(pause);
480	emulationMenu->addAction(pause);
481
482	QAction* frameAdvance = new QAction(tr("&Next frame"), emulationMenu);
483	frameAdvance->setShortcut(tr("Ctrl+N"));
484	connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance()));
485	m_gameActions.append(frameAdvance);
486	addAction(frameAdvance);
487	emulationMenu->addAction(frameAdvance);
488
489	emulationMenu->addSeparator();
490
491	QAction* turbo = new QAction(tr("&Fast forward"), emulationMenu);
492	turbo->setCheckable(true);
493	turbo->setChecked(false);
494	turbo->setShortcut(tr("Shift+Tab"));
495	connect(turbo, SIGNAL(triggered(bool)), m_controller, SLOT(setTurbo(bool)));
496	addAction(turbo);
497	emulationMenu->addAction(turbo);
498
499	ConfigOption* videoSync = m_config->addOption("videoSync");
500	videoSync->addBoolean(tr("Sync to &video"), emulationMenu);
501	videoSync->connect([this](const QVariant& value) { m_controller->setVideoSync(value.toBool()); });
502	m_config->updateOption("videoSync");
503
504	ConfigOption* audioSync = m_config->addOption("audioSync");
505	audioSync->addBoolean(tr("Sync to &audio"), emulationMenu);
506	audioSync->connect([this](const QVariant& value) { m_controller->setAudioSync(value.toBool()); });
507	m_config->updateOption("audioSync");
508
509	emulationMenu->addSeparator();
510	QAction* keymap = new QAction(tr("Remap keyboard..."), emulationMenu);
511	connect(keymap, SIGNAL(triggered()), this, SLOT(openKeymapWindow()));
512	emulationMenu->addAction(keymap);
513
514#ifdef BUILD_SDL
515	QAction* gamepad = new QAction(tr("Remap gamepad..."), emulationMenu);
516	connect(gamepad, SIGNAL(triggered()), this, SLOT(openGamepadWindow()));
517	emulationMenu->addAction(gamepad);
518#endif
519
520	QMenu* avMenu = menubar->addMenu(tr("Audio/&Video"));
521	QMenu* frameMenu = avMenu->addMenu(tr("Frame size"));
522	for (int i = 1; i <= 6; ++i) {
523		QAction* setSize = new QAction(tr("%1x").arg(QString::number(i)), avMenu);
524		connect(setSize, &QAction::triggered, [this, i]() {
525			showNormal();
526			resizeFrame(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i);
527		});
528		frameMenu->addAction(setSize);
529	}
530	addAction(frameMenu->addAction(tr("Fullscreen"), this, SLOT(toggleFullScreen()), QKeySequence("Ctrl+F")));
531
532	ConfigOption* lockAspectRatio = m_config->addOption("lockAspectRatio");
533	lockAspectRatio->addBoolean(tr("Lock aspect ratio"), avMenu);
534	lockAspectRatio->connect([this](const QVariant& value) { m_display->lockAspectRatio(value.toBool()); });
535	m_config->updateOption("lockAspectRatio");
536
537	ConfigOption* resampleVideo = m_config->addOption("resampleVideo");
538	resampleVideo->addBoolean(tr("Resample video"), avMenu);
539	resampleVideo->connect([this](const QVariant& value) { m_display->filter(value.toBool()); });
540	m_config->updateOption("resampleVideo");
541
542	QMenu* skipMenu = avMenu->addMenu(tr("Frame&skip"));
543	ConfigOption* skip = m_config->addOption("frameskip");
544	skip->connect([this](const QVariant& value) { m_controller->setFrameskip(value.toInt()); });
545	for (int i = 0; i <= 10; ++i) {
546		skip->addValue(QString::number(i), i, skipMenu);
547	}
548	m_config->updateOption("frameskip");
549
550	avMenu->addSeparator();
551
552	QMenu* buffersMenu = avMenu->addMenu(tr("Audio buffer &size"));
553	ConfigOption* buffers = m_config->addOption("audioBuffers");
554	buffers->connect([this](const QVariant& value) { emit audioBufferSamplesChanged(value.toInt()); });
555	buffers->addValue(tr("512"), 512, buffersMenu);
556	buffers->addValue(tr("768"), 768, buffersMenu);
557	buffers->addValue(tr("1024"), 1024, buffersMenu);
558	buffers->addValue(tr("2048"), 2048, buffersMenu);
559	buffers->addValue(tr("4096"), 4096, buffersMenu);
560	m_config->updateOption("audioBuffers");
561
562	avMenu->addSeparator();
563
564	QMenu* target = avMenu->addMenu("FPS target");
565	ConfigOption* fpsTargetOption = m_config->addOption("fpsTarget");
566	fpsTargetOption->connect([this](const QVariant& value) { emit fpsTargetChanged(value.toInt()); });
567	fpsTargetOption->addValue(tr("15"), 15, target);
568	fpsTargetOption->addValue(tr("30"), 30, target);
569	fpsTargetOption->addValue(tr("45"), 45, target);
570	fpsTargetOption->addValue(tr("60"), 60, target);
571	fpsTargetOption->addValue(tr("90"), 90, target);
572	fpsTargetOption->addValue(tr("120"), 120, target);
573	fpsTargetOption->addValue(tr("240"), 240, target);
574	m_config->updateOption("fpsTarget");
575
576#if defined(USE_PNG) || defined(USE_FFMPEG) || defined(USE_MAGICK)
577	avMenu->addSeparator();
578#endif
579
580#ifdef USE_PNG
581	QAction* screenshot = new QAction(tr("Take &screenshot"), avMenu);
582	screenshot->setShortcut(tr("F12"));
583	connect(screenshot, SIGNAL(triggered()), m_display, SLOT(screenshot()));
584	m_gameActions.append(screenshot);
585	addAction(screenshot);
586	avMenu->addAction(screenshot);
587#endif
588
589#ifdef USE_FFMPEG
590	QAction* recordOutput = new QAction(tr("Record output..."), avMenu);
591	recordOutput->setShortcut(tr("F11"));
592	connect(recordOutput, SIGNAL(triggered()), this, SLOT(openVideoWindow()));
593	addAction(recordOutput);
594	avMenu->addAction(recordOutput);
595#endif
596
597#ifdef USE_MAGICK
598	QAction* recordGIF = new QAction(tr("Record GIF..."), avMenu);
599	recordGIF->setShortcut(tr("Shift+F11"));
600	connect(recordGIF, SIGNAL(triggered()), this, SLOT(openGIFWindow()));
601	addAction(recordGIF);
602	avMenu->addAction(recordGIF);
603#endif
604
605	QMenu* debuggingMenu = menubar->addMenu(tr("&Debugging"));
606	QAction* viewLogs = new QAction(tr("View &logs..."), debuggingMenu);
607	connect(viewLogs, SIGNAL(triggered()), m_logView, SLOT(show()));
608	debuggingMenu->addAction(viewLogs);
609#ifdef USE_GDB_STUB
610	QAction* gdbWindow = new QAction(tr("Start &GDB server..."), debuggingMenu);
611	connect(gdbWindow, SIGNAL(triggered()), this, SLOT(gdbOpen()));
612	debuggingMenu->addAction(gdbWindow);
613#endif
614
615	ConfigOption* skipBios = m_config->addOption("skipBios");
616	skipBios->connect([this](const QVariant& value) { m_controller->setSkipBIOS(value.toBool()); });
617
618	foreach (QAction* action, m_gameActions) {
619		action->setDisabled(true);
620	}
621}
622
623void Window::attachWidget(QWidget* widget) {
624	m_screenWidget->layout()->addWidget(widget);
625	static_cast<QStackedLayout*>(m_screenWidget->layout())->setCurrentWidget(widget);
626}
627
628void Window::detachWidget(QWidget* widget) {
629	m_screenWidget->layout()->removeWidget(widget);
630}
631
632WindowBackground::WindowBackground(QWidget* parent)
633	: QLabel(parent)
634{
635	setLayout(new QStackedLayout());
636	layout()->setContentsMargins(0, 0, 0, 0);
637	setAlignment(Qt::AlignCenter);
638	QPalette p = palette();
639	p.setColor(backgroundRole(), Qt::black);
640	setPalette(p);
641	setAutoFillBackground(true);
642}
643
644void WindowBackground::setSizeHint(const QSize& hint) {
645	m_sizeHint = hint;
646}
647
648QSize WindowBackground::sizeHint() const {
649	return m_sizeHint;
650}