all repos — mgba @ 1ee69deffb8f95a6fd5923dfcc6ade99f4b41b9a

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