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