all repos — mgba @ 802e4b87201c4ade66551f5229cafc790ca61ab7

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