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