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