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