src/platform/qt/Window.cpp (view raw)
1/* Copyright (c) 2013-2016 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 <QDesktopWidget>
9#include <QKeyEvent>
10#include <QKeySequence>
11#include <QMenuBar>
12#include <QMessageBox>
13#include <QMimeData>
14#include <QPainter>
15#include <QStackedLayout>
16
17#ifdef USE_SQLITE3
18#include "ArchiveInspector.h"
19#include "library/LibraryController.h"
20#endif
21
22#include "AboutScreen.h"
23#include "CheatsView.h"
24#include "ConfigController.h"
25#include "DebuggerConsole.h"
26#include "DebuggerConsoleController.h"
27#include "Display.h"
28#include "GameController.h"
29#include "GBAApp.h"
30#include "GDBController.h"
31#include "GDBWindow.h"
32#include "GIFView.h"
33#include "IOViewer.h"
34#include "LoadSaveState.h"
35#include "LogView.h"
36#include "MultiplayerController.h"
37#include "MemorySearch.h"
38#include "MemoryView.h"
39#include "OverrideView.h"
40#include "ObjView.h"
41#include "PaletteView.h"
42#include "ROMInfo.h"
43#include "SensorView.h"
44#include "SettingsView.h"
45#include "ShaderSelector.h"
46#include "ShortcutController.h"
47#include "TileView.h"
48#include "VideoView.h"
49
50#include <mgba/core/version.h>
51#ifdef M_CORE_GB
52#include <mgba/internal/gb/gb.h>
53#include <mgba/internal/gb/video.h>
54#endif
55#ifdef M_CORE_GBA
56#include <mgba/internal/gba/gba.h>
57#include <mgba/internal/gba/video.h>
58#endif
59#include <mgba/feature/commandline.h>
60#include "feature/sqlite3/no-intro.h"
61#include <mgba-util/vfs.h>
62
63using namespace QGBA;
64
65Window::Window(ConfigController* config, int playerId, QWidget* parent)
66 : QMainWindow(parent)
67 , m_logView(new LogView(&m_log))
68 , m_screenWidget(new WindowBackground())
69 , m_config(config)
70 , m_inputController(playerId, this)
71 , m_shortcutController(new ShortcutController(this))
72{
73 setFocusPolicy(Qt::StrongFocus);
74 setAcceptDrops(true);
75 setAttribute(Qt::WA_DeleteOnClose);
76 m_controller = new GameController(this);
77 m_controller->setInputController(&m_inputController);
78 updateTitle();
79
80 m_display = Display::create(this);
81#if defined(BUILD_GL) || defined(BUILD_GLES)
82 m_shaderView = new ShaderSelector(m_display, m_config);
83#endif
84
85 m_logo.setDevicePixelRatio(m_screenWidget->devicePixelRatio());
86 m_logo = m_logo; // Free memory left over in old pixmap
87
88 m_screenWidget->setMinimumSize(m_display->minimumSize());
89 m_screenWidget->setSizePolicy(m_display->sizePolicy());
90#if defined(M_CORE_GBA)
91 float i = 2;
92#elif defined(M_CORE_GB)
93 float i = 3;
94#endif
95 QVariant multiplier = m_config->getOption("scaleMultiplier");
96 if (!multiplier.isNull()) {
97 m_savedScale = multiplier.toInt();
98 i = m_savedScale;
99 }
100#ifdef USE_SQLITE3
101 m_libraryView = new LibraryController(nullptr, ConfigController::configDir() + "/library.sqlite3", m_config);
102 ConfigOption* showLibrary = m_config->addOption("showLibrary");
103 showLibrary->connect([this](const QVariant& value) {
104 if (value.toBool()) {
105 if (m_controller->isLoaded()) {
106 m_screenWidget->layout()->addWidget(m_libraryView);
107 } else {
108 attachWidget(m_libraryView);
109 }
110 } else {
111 detachWidget(m_libraryView);
112 }
113 }, this);
114 m_config->updateOption("showLibrary");
115 ConfigOption* libraryStyle = m_config->addOption("libraryStyle");
116 libraryStyle->connect([this](const QVariant& value) {
117 m_libraryView->setViewStyle(static_cast<LibraryStyle>(value.toInt()));
118 }, this);
119 m_config->updateOption("libraryStyle");
120
121 connect(m_libraryView, &LibraryController::startGame, [this]() {
122 VFile* output = m_libraryView->selectedVFile();
123 if (output) {
124 QPair<QString, QString> path = m_libraryView->selectedPath();
125 m_controller->loadGame(output, path.second, path.first);
126 }
127 });
128#endif
129#if defined(M_CORE_GBA)
130 resizeFrame(QSize(VIDEO_HORIZONTAL_PIXELS * i, VIDEO_VERTICAL_PIXELS * i));
131#elif defined(M_CORE_GB)
132 resizeFrame(QSize(GB_VIDEO_HORIZONTAL_PIXELS * i, GB_VIDEO_VERTICAL_PIXELS * i));
133#endif
134 m_screenWidget->setPixmap(m_logo);
135 m_screenWidget->setDimensions(m_logo.width(), m_logo.height());
136 m_screenWidget->setLockIntegerScaling(false);
137 m_screenWidget->setLockAspectRatio(true);
138 setCentralWidget(m_screenWidget);
139
140 connect(m_controller, &GameController::gameStarted, this, &Window::gameStarted);
141 connect(m_controller, &GameController::gameStarted, &m_inputController, &InputController::suspendScreensaver);
142 connect(m_controller, &GameController::gameStopped, m_display, &Display::stopDrawing);
143 connect(m_controller, &GameController::gameStopped, this, &Window::gameStopped);
144 connect(m_controller, &GameController::gameStopped, &m_inputController, &InputController::resumeScreensaver);
145 connect(m_controller, &GameController::stateLoaded, m_display, &Display::forceDraw);
146 connect(m_controller, &GameController::rewound, m_display, &Display::forceDraw);
147 connect(m_controller, &GameController::gamePaused, [this](mCoreThread* context) {
148 unsigned width, height;
149 context->core->desiredVideoDimensions(context->core, &width, &height);
150 QImage currentImage(reinterpret_cast<const uchar*>(m_controller->drawContext()), width, height,
151 width * BYTES_PER_PIXEL, QImage::Format_RGBX8888);
152 QPixmap pixmap;
153 pixmap.convertFromImage(currentImage);
154 m_screenWidget->setPixmap(pixmap);
155 });
156 connect(m_controller, &GameController::gamePaused, m_display, &Display::pauseDrawing);
157#ifndef Q_OS_MAC
158 connect(m_controller, &GameController::gamePaused, menuBar(), &QWidget::show);
159 connect(m_controller, &GameController::gameUnpaused, [this]() {
160 if(isFullScreen()) {
161 menuBar()->hide();
162 }
163 });
164#endif
165 connect(m_controller, &GameController::gamePaused, &m_inputController, &InputController::resumeScreensaver);
166 connect(m_controller, &GameController::gameUnpaused, m_display, &Display::unpauseDrawing);
167 connect(m_controller, &GameController::gameUnpaused, &m_inputController, &InputController::suspendScreensaver);
168 connect(m_controller, &GameController::postLog, &m_log, &LogController::postLog);
169 connect(m_controller, &GameController::frameAvailable, this, &Window::recordFrame);
170 connect(m_controller, &GameController::frameAvailable, m_display, &Display::framePosted);
171 connect(m_controller, &GameController::gameCrashed, this, &Window::gameCrashed);
172 connect(m_controller, &GameController::gameFailed, this, &Window::gameFailed);
173 connect(m_controller, &GameController::unimplementedBiosCall, this, &Window::unimplementedBiosCall);
174 connect(m_controller, &GameController::statusPosted, m_display, &Display::showMessage);
175 connect(&m_log, &LogController::levelsSet, m_controller, &GameController::setLogLevel);
176 connect(&m_log, &LogController::levelsEnabled, m_controller, &GameController::enableLogLevel);
177 connect(&m_log, &LogController::levelsDisabled, m_controller, &GameController::disableLogLevel);
178 connect(this, &Window::startDrawing, m_display, &Display::startDrawing, Qt::QueuedConnection);
179 connect(this, &Window::shutdown, m_display, &Display::stopDrawing);
180 connect(this, &Window::shutdown, m_controller, &GameController::closeGame);
181 connect(this, &Window::shutdown, m_logView, &QWidget::hide);
182 connect(this, &Window::audioBufferSamplesChanged, m_controller, &GameController::setAudioBufferSamples);
183 connect(this, &Window::sampleRateChanged, m_controller, &GameController::setAudioSampleRate);
184 connect(this, &Window::fpsTargetChanged, m_controller, &GameController::setFPSTarget);
185 connect(&m_fpsTimer, &QTimer::timeout, this, &Window::showFPS);
186 connect(&m_focusCheck, &QTimer::timeout, this, &Window::focusCheck);
187 connect(m_display, &Display::hideCursor, [this]() {
188 if (static_cast<QStackedLayout*>(m_screenWidget->layout())->currentWidget() == m_display) {
189 m_screenWidget->setCursor(Qt::BlankCursor);
190 }
191 });
192 connect(m_display, &Display::showCursor, [this]() {
193 m_screenWidget->unsetCursor();
194 });
195 connect(&m_inputController, &InputController::profileLoaded, m_shortcutController, &ShortcutController::loadProfile);
196
197 m_log.setLevels(mLOG_WARN | mLOG_ERROR | mLOG_FATAL);
198 m_fpsTimer.setInterval(FPS_TIMER_INTERVAL);
199 m_focusCheck.setInterval(200);
200
201 m_shortcutController->setConfigController(m_config);
202 setupMenu(menuBar());
203}
204
205Window::~Window() {
206 delete m_logView;
207
208#ifdef USE_FFMPEG
209 delete m_videoView;
210#endif
211
212#ifdef USE_MAGICK
213 delete m_gifView;
214#endif
215
216#ifdef USE_SQLITE3
217 delete m_libraryView;
218#endif
219}
220
221void Window::argumentsPassed(mArguments* args) {
222 loadConfig();
223
224 if (args->patch) {
225 m_controller->loadPatch(args->patch);
226 }
227
228 if (args->fname) {
229 m_controller->loadGame(args->fname);
230 }
231
232#ifdef USE_GDB_STUB
233 if (args->debuggerType == DEBUGGER_GDB) {
234 if (!m_gdbController) {
235 m_gdbController = new GDBController(m_controller, this);
236 m_gdbController->listen();
237 }
238 }
239#endif
240}
241
242void Window::resizeFrame(const QSize& size) {
243 QSize newSize(size);
244 m_screenWidget->setSizeHint(newSize);
245 newSize -= m_screenWidget->size();
246 newSize += this->size();
247 resize(newSize);
248}
249
250void Window::setConfig(ConfigController* config) {
251 m_config = config;
252}
253
254void Window::loadConfig() {
255 const mCoreOptions* opts = m_config->options();
256 reloadConfig();
257
258 // TODO: Move these to ConfigController
259 if (opts->fpsTarget) {
260 emit fpsTargetChanged(opts->fpsTarget);
261 }
262
263 if (opts->audioBuffers) {
264 emit audioBufferSamplesChanged(opts->audioBuffers);
265 }
266
267 if (opts->sampleRate) {
268 emit sampleRateChanged(opts->sampleRate);
269 }
270
271 if (opts->width && opts->height) {
272 resizeFrame(QSize(opts->width, opts->height));
273 }
274
275 if (opts->fullscreen) {
276 enterFullScreen();
277 }
278
279#if defined(BUILD_GL) || defined(BUILD_GLES)
280 if (opts->shader) {
281 struct VDir* shader = VDirOpen(opts->shader);
282 if (shader) {
283 m_display->setShaders(shader);
284 m_shaderView->refreshShaders();
285 shader->close(shader);
286 }
287 }
288#endif
289
290 m_mruFiles = m_config->getMRU();
291 updateMRU();
292
293 m_inputController.setConfiguration(m_config);
294 m_controller->setUseBIOS(opts->useBios);
295}
296
297void Window::reloadConfig() {
298 const mCoreOptions* opts = m_config->options();
299
300 m_log.setLevels(opts->logLevel);
301
302 m_controller->setConfig(m_config->config());
303 m_display->lockAspectRatio(opts->lockAspectRatio);
304 m_display->filter(opts->resampleVideo);
305
306 m_inputController.setScreensaverSuspendable(opts->suspendScreensaver);
307}
308
309void Window::saveConfig() {
310 m_inputController.saveConfiguration();
311 m_config->write();
312}
313
314QString Window::getFilters() const {
315 QStringList filters;
316 QStringList formats;
317
318#ifdef M_CORE_GBA
319 QStringList gbaFormats{
320 "*.gba",
321#if defined(USE_LIBZIP) || defined(USE_ZLIB)
322 "*.zip",
323#endif
324#ifdef USE_LZMA
325 "*.7z",
326#endif
327 "*.agb",
328 "*.mb",
329 "*.rom",
330 "*.bin"};
331 formats.append(gbaFormats);
332 filters.append(tr("Game Boy Advance ROMs (%1)").arg(gbaFormats.join(QChar(' '))));
333#endif
334
335#ifdef M_CORE_GB
336 QStringList gbFormats{
337 "*.gb",
338 "*.gbc",
339#if defined(USE_LIBZIP) || defined(USE_ZLIB)
340 "*.zip",
341#endif
342#ifdef USE_LZMA
343 "*.7z",
344#endif
345 "*.rom",
346 "*.bin"};
347 formats.append(gbFormats);
348 filters.append(tr("Game Boy ROMs (%1)").arg(gbFormats.join(QChar(' '))));
349#endif
350
351 formats.removeDuplicates();
352 filters.prepend(tr("All ROMs (%1)").arg(formats.join(QChar(' '))));
353 filters.append(tr("%1 Video Logs (*.mvl)").arg(projectName));
354 return filters.join(";;");
355}
356
357QString Window::getFiltersArchive() const {
358 QStringList filters;
359
360 QStringList formats{
361#if defined(USE_LIBZIP) || defined(USE_ZLIB)
362 "*.zip",
363#endif
364#ifdef USE_LZMA
365 "*.7z",
366#endif
367 };
368 filters.append(tr("Archives (%1)").arg(formats.join(QChar(' '))));
369 return filters.join(";;");
370}
371
372void Window::selectROM() {
373 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFilters());
374 if (!filename.isEmpty()) {
375 m_controller->loadGame(filename);
376 }
377}
378
379#ifdef USE_SQLITE3
380void Window::selectROMInArchive() {
381 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFiltersArchive());
382 if (filename.isEmpty()) {
383 return;
384 }
385 ArchiveInspector* archiveInspector = new ArchiveInspector(filename);
386 connect(archiveInspector, &QDialog::accepted, [this, archiveInspector]() {
387 VFile* output = archiveInspector->selectedVFile();
388 QPair<QString, QString> path = archiveInspector->selectedPath();
389 if (output) {
390 m_controller->loadGame(output, path.second, path.first);
391 }
392 archiveInspector->close();
393 });
394 archiveInspector->setAttribute(Qt::WA_DeleteOnClose);
395 archiveInspector->show();
396}
397
398void Window::addDirToLibrary() {
399 QString filename = GBAApp::app()->getOpenDirectoryName(this, tr("Select folder"));
400 if (filename.isEmpty()) {
401 return;
402 }
403 m_libraryView->addDirectory(filename);
404}
405#endif
406
407void Window::replaceROM() {
408 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFilters());
409 if (!filename.isEmpty()) {
410 m_controller->replaceGame(filename);
411 }
412}
413
414void Window::selectSave(bool temporary) {
415 QStringList formats{"*.sav"};
416 QString filter = tr("Game Boy Advance save files (%1)").arg(formats.join(QChar(' ')));
417 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select save"), filter);
418 if (!filename.isEmpty()) {
419 m_controller->loadSave(filename, temporary);
420 }
421}
422
423void Window::multiplayerChanged() {
424 int attached = 1;
425 MultiplayerController* multiplayer = m_controller->multiplayerController();
426 if (multiplayer) {
427 attached = multiplayer->attached();
428 }
429 if (m_controller->isLoaded()) {
430 for (QAction* action : m_nonMpActions) {
431 action->setDisabled(attached > 1);
432 }
433 }
434}
435
436void Window::selectPatch() {
437 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select patch"), tr("Patches (*.ips *.ups *.bps)"));
438 if (!filename.isEmpty()) {
439 m_controller->loadPatch(filename);
440 }
441}
442
443void Window::openView(QWidget* widget) {
444 connect(this, &Window::shutdown, widget, &QWidget::close);
445 connect(m_controller, &GameController::gameStopped, widget, &QWidget::close);
446 widget->setAttribute(Qt::WA_DeleteOnClose);
447 widget->show();
448}
449
450void Window::importSharkport() {
451 QString filename = GBAApp::app()->getOpenFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)"));
452 if (!filename.isEmpty()) {
453 m_controller->importSharkport(filename);
454 }
455}
456
457void Window::exportSharkport() {
458 QString filename = GBAApp::app()->getSaveFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)"));
459 if (!filename.isEmpty()) {
460 m_controller->exportSharkport(filename);
461 }
462}
463
464void Window::openSettingsWindow() {
465 SettingsView* settingsWindow = new SettingsView(m_config, &m_inputController, m_shortcutController);
466#if defined(BUILD_GL) || defined(BUILD_GLES)
467 if (m_display->supportsShaders()) {
468 settingsWindow->setShaderSelector(m_shaderView);
469 }
470#endif
471 connect(settingsWindow, &SettingsView::biosLoaded, m_controller, &GameController::loadBIOS);
472 connect(settingsWindow, &SettingsView::audioDriverChanged, m_controller, &GameController::reloadAudioDriver);
473 connect(settingsWindow, &SettingsView::displayDriverChanged, this, &Window::mustRestart);
474 connect(settingsWindow, &SettingsView::languageChanged, this, &Window::mustRestart);
475 connect(settingsWindow, &SettingsView::pathsChanged, this, &Window::reloadConfig);
476 connect(settingsWindow, &SettingsView::libraryCleared, m_libraryView, &LibraryController::clear);
477 openView(settingsWindow);
478}
479
480void Window::openAboutScreen() {
481 AboutScreen* about = new AboutScreen();
482 openView(about);
483}
484
485void Window::startVideoLog() {
486 QString filename = GBAApp::app()->getSaveFileName(this, tr("Select video log"), tr("Video logs (*.mvl)"));
487 if (!filename.isEmpty()) {
488 m_controller->startVideoLog(filename);
489 }
490}
491
492template <typename T, typename A>
493std::function<void()> Window::openTView(A arg) {
494 return [=]() {
495 T* view = new T(m_controller, arg);
496 openView(view);
497 };
498}
499
500template <typename T>
501std::function<void()> Window::openTView() {
502 return [=]() {
503 T* view = new T(m_controller);
504 openView(view);
505 };
506}
507
508#ifdef USE_FFMPEG
509void Window::openVideoWindow() {
510 if (!m_videoView) {
511 m_videoView = new VideoView();
512 connect(m_videoView, &VideoView::recordingStarted, m_controller, &GameController::setAVStream);
513 connect(m_videoView, &VideoView::recordingStopped, m_controller, &GameController::clearAVStream, Qt::DirectConnection);
514 connect(m_controller, &GameController::gameStopped, m_videoView, &VideoView::stopRecording);
515 connect(m_controller, &GameController::gameStopped, m_videoView, &QWidget::close);
516 connect(m_controller, &GameController::gameStarted, [this]() {
517 m_videoView->setNativeResolution(m_controller->screenDimensions());
518 });
519 if (m_controller->isLoaded()) {
520 m_videoView->setNativeResolution(m_controller->screenDimensions());
521 }
522 connect(this, &Window::shutdown, m_videoView, &QWidget::close);
523 }
524 m_videoView->show();
525}
526#endif
527
528#ifdef USE_MAGICK
529void Window::openGIFWindow() {
530 if (!m_gifView) {
531 m_gifView = new GIFView();
532 connect(m_gifView, &GIFView::recordingStarted, m_controller, &GameController::setAVStream);
533 connect(m_gifView, &GIFView::recordingStopped, m_controller, &GameController::clearAVStream, Qt::DirectConnection);
534 connect(m_controller, &GameController::gameStopped, m_gifView, &GIFView::stopRecording);
535 connect(m_controller, &GameController::gameStopped, m_gifView, &QWidget::close);
536 connect(this, &Window::shutdown, m_gifView, &QWidget::close);
537 }
538 m_gifView->show();
539}
540#endif
541
542#ifdef USE_GDB_STUB
543void Window::gdbOpen() {
544 if (!m_gdbController) {
545 m_gdbController = new GDBController(m_controller, this);
546 }
547 GDBWindow* window = new GDBWindow(m_gdbController);
548 openView(window);
549}
550#endif
551
552#ifdef USE_DEBUGGERS
553void Window::consoleOpen() {
554 if (!m_console) {
555 m_console = new DebuggerConsoleController(m_controller, this);
556 }
557 DebuggerConsole* window = new DebuggerConsole(m_console);
558 openView(window);
559}
560#endif
561
562void Window::keyPressEvent(QKeyEvent* event) {
563 if (event->isAutoRepeat()) {
564 QWidget::keyPressEvent(event);
565 return;
566 }
567 GBAKey key = m_inputController.mapKeyboard(event->key());
568 if (key == GBA_KEY_NONE) {
569 QWidget::keyPressEvent(event);
570 return;
571 }
572 m_controller->keyPressed(key);
573 event->accept();
574}
575
576void Window::keyReleaseEvent(QKeyEvent* event) {
577 if (event->isAutoRepeat()) {
578 QWidget::keyReleaseEvent(event);
579 return;
580 }
581 GBAKey key = m_inputController.mapKeyboard(event->key());
582 if (key == GBA_KEY_NONE) {
583 QWidget::keyPressEvent(event);
584 return;
585 }
586 m_controller->keyReleased(key);
587 event->accept();
588}
589
590void Window::resizeEvent(QResizeEvent* event) {
591 if (!isFullScreen()) {
592 m_config->setOption("height", m_screenWidget->height());
593 m_config->setOption("width", m_screenWidget->width());
594 }
595
596 int factor = 0;
597 QSize size(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
598 if (m_controller->isLoaded()) {
599 size = m_controller->screenDimensions();
600 }
601 if (m_screenWidget->width() % size.width() == 0 && m_screenWidget->height() % size.height() == 0 &&
602 m_screenWidget->width() / size.width() == m_screenWidget->height() / size.height()) {
603 factor = m_screenWidget->width() / size.width();
604 } else {
605 m_savedScale = 0;
606 }
607 for (QMap<int, QAction*>::iterator iter = m_frameSizes.begin(); iter != m_frameSizes.end(); ++iter) {
608 bool enableSignals = iter.value()->blockSignals(true);
609 iter.value()->setChecked(iter.key() == factor);
610 iter.value()->blockSignals(enableSignals);
611 }
612
613 m_config->setOption("fullscreen", isFullScreen());
614}
615
616void Window::showEvent(QShowEvent* event) {
617 if (m_wasOpened) {
618 return;
619 }
620 m_wasOpened = true;
621 resizeFrame(m_screenWidget->sizeHint());
622 QVariant windowPos = m_config->getQtOption("windowPos");
623 if (!windowPos.isNull()) {
624 move(windowPos.toPoint());
625 } else {
626 QRect rect = frameGeometry();
627 rect.moveCenter(QApplication::desktop()->availableGeometry().center());
628 move(rect.topLeft());
629 }
630 if (m_fullscreenOnStart) {
631 enterFullScreen();
632 m_fullscreenOnStart = false;
633 }
634}
635
636void Window::closeEvent(QCloseEvent* event) {
637 emit shutdown();
638 m_config->setQtOption("windowPos", pos());
639
640 if (m_savedScale > 0) {
641 m_config->setOption("height", VIDEO_VERTICAL_PIXELS * m_savedScale);
642 m_config->setOption("width", VIDEO_HORIZONTAL_PIXELS * m_savedScale);
643 }
644 saveConfig();
645 QMainWindow::closeEvent(event);
646}
647
648void Window::focusInEvent(QFocusEvent*) {
649 m_display->forceDraw();
650}
651
652void Window::focusOutEvent(QFocusEvent*) {
653 m_controller->setTurbo(false, false);
654 m_controller->stopRewinding();
655 m_controller->clearKeys();
656}
657
658void Window::dragEnterEvent(QDragEnterEvent* event) {
659 if (event->mimeData()->hasFormat("text/uri-list")) {
660 event->acceptProposedAction();
661 }
662}
663
664void Window::dropEvent(QDropEvent* event) {
665 QString uris = event->mimeData()->data("text/uri-list");
666 uris = uris.trimmed();
667 if (uris.contains("\n")) {
668 // Only one file please
669 return;
670 }
671 QUrl url(uris);
672 if (!url.isLocalFile()) {
673 // No remote loading
674 return;
675 }
676 event->accept();
677 m_controller->loadGame(url.toLocalFile());
678}
679
680void Window::mouseDoubleClickEvent(QMouseEvent* event) {
681 if (event->button() != Qt::LeftButton) {
682 return;
683 }
684 toggleFullScreen();
685}
686
687void Window::enterFullScreen() {
688 if (!isVisible()) {
689 m_fullscreenOnStart = true;
690 return;
691 }
692 if (isFullScreen()) {
693 return;
694 }
695 showFullScreen();
696#ifndef Q_OS_MAC
697 if (m_controller->isLoaded() && !m_controller->isPaused()) {
698 menuBar()->hide();
699 }
700#endif
701}
702
703void Window::exitFullScreen() {
704 if (!isFullScreen()) {
705 return;
706 }
707 m_screenWidget->unsetCursor();
708 menuBar()->show();
709 showNormal();
710}
711
712void Window::toggleFullScreen() {
713 if (isFullScreen()) {
714 exitFullScreen();
715 } else {
716 enterFullScreen();
717 }
718}
719
720void Window::gameStarted(mCoreThread* context, const QString& fname) {
721 MutexLock(&context->stateMutex);
722 if (context->state < THREAD_EXITING) {
723 emit startDrawing(context);
724 } else {
725 MutexUnlock(&context->stateMutex);
726 return;
727 }
728 MutexUnlock(&context->stateMutex);
729 for (QAction* action : m_gameActions) {
730 action->setDisabled(false);
731 }
732#ifdef M_CORE_GBA
733 for (QAction* action : m_gbaActions) {
734 action->setDisabled(context->core->platform(context->core) != PLATFORM_GBA);
735 }
736#endif
737 multiplayerChanged();
738 if (!fname.isEmpty()) {
739 setWindowFilePath(fname);
740 appendMRU(fname);
741 }
742 updateTitle();
743 unsigned width, height;
744 context->core->desiredVideoDimensions(context->core, &width, &height);
745 m_display->setMinimumSize(width, height);
746 m_screenWidget->setMinimumSize(m_display->minimumSize());
747 m_screenWidget->setDimensions(width, height);
748 m_config->updateOption("lockIntegerScaling");
749 m_config->updateOption("lockAspectRatio");
750 if (m_savedScale > 0) {
751 resizeFrame(QSize(width, height) * m_savedScale);
752 }
753 attachWidget(m_display);
754
755#ifndef Q_OS_MAC
756 if (isFullScreen()) {
757 menuBar()->hide();
758 }
759#endif
760
761 m_hitUnimplementedBiosCall = false;
762 m_fpsTimer.start();
763 m_focusCheck.start();
764
765 m_controller->threadInterrupt();
766 if (m_controller->isLoaded()) {
767 mCore* core = m_controller->thread()->core;
768 const mCoreChannelInfo* videoLayers;
769 const mCoreChannelInfo* audioChannels;
770 size_t nVideo = core->listVideoLayers(core, &videoLayers);
771 size_t nAudio = core->listAudioChannels(core, &audioChannels);
772
773 if (nVideo) {
774 for (size_t i = 0; i < nVideo; ++i) {
775 QAction* action = new QAction(videoLayers[i].visibleName, m_videoLayers);
776 action->setCheckable(true);
777 action->setChecked(true);
778 connect(action, &QAction::triggered, [this, videoLayers, i](bool enable) {
779 m_controller->setVideoLayerEnabled(videoLayers[i].id, enable);
780 });
781 m_videoLayers->addAction(action);
782 }
783 }
784 if (nAudio) {
785 for (size_t i = 0; i < nAudio; ++i) {
786 QAction* action = new QAction(audioChannels[i].visibleName, m_audioChannels);
787 action->setCheckable(true);
788 action->setChecked(true);
789 connect(action, &QAction::triggered, [this, audioChannels, i](bool enable) {
790 m_controller->setAudioChannelEnabled(audioChannels[i].id, enable);
791 });
792 m_audioChannels->addAction(action);
793 }
794 }
795 }
796 m_controller->threadContinue();
797}
798
799void Window::gameStopped() {
800#ifdef M_CORE_GBA
801 for (QAction* action : m_gbaActions) {
802 action->setDisabled(false);
803 }
804#endif
805 for (QAction* action : m_gameActions) {
806 action->setDisabled(true);
807 }
808 setWindowFilePath(QString());
809 updateTitle();
810 detachWidget(m_display);
811 m_screenWidget->setDimensions(m_logo.width(), m_logo.height());
812 m_screenWidget->setLockIntegerScaling(false);
813 m_screenWidget->setLockAspectRatio(true);
814 m_screenWidget->setPixmap(m_logo);
815 m_screenWidget->unsetCursor();
816#ifdef M_CORE_GB
817 m_display->setMinimumSize(GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
818#elif defined(M_CORE_GBA)
819 m_display->setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
820#endif
821 m_screenWidget->setMinimumSize(m_display->minimumSize());
822
823 m_videoLayers->clear();
824 m_audioChannels->clear();
825
826 m_fpsTimer.stop();
827 m_focusCheck.stop();
828}
829
830void Window::gameCrashed(const QString& errorMessage) {
831 QMessageBox* crash = new QMessageBox(QMessageBox::Critical, tr("Crash"),
832 tr("The game has crashed with the following error:\n\n%1").arg(errorMessage),
833 QMessageBox::Ok, this, Qt::Sheet);
834 crash->setAttribute(Qt::WA_DeleteOnClose);
835 crash->show();
836 connect(m_controller, &GameController::gameStarted, crash, &QWidget::close);
837}
838
839void Window::gameFailed() {
840 QMessageBox* fail = new QMessageBox(QMessageBox::Warning, tr("Couldn't Load"),
841 tr("Could not load game. Are you sure it's in the correct format?"),
842 QMessageBox::Ok, this, Qt::Sheet);
843 fail->setAttribute(Qt::WA_DeleteOnClose);
844 fail->show();
845 connect(m_controller, &GameController::gameStarted, fail, &QWidget::close);
846}
847
848void Window::unimplementedBiosCall(int call) {
849 if (m_hitUnimplementedBiosCall) {
850 return;
851 }
852 m_hitUnimplementedBiosCall = true;
853
854 QMessageBox* fail = new QMessageBox(
855 QMessageBox::Warning, tr("Unimplemented BIOS call"),
856 tr("This game uses a BIOS call that is not implemented. Please use the official BIOS for best experience."),
857 QMessageBox::Ok, this, Qt::Sheet);
858 fail->setAttribute(Qt::WA_DeleteOnClose);
859 fail->show();
860}
861
862void Window::tryMakePortable() {
863 QMessageBox* confirm = new QMessageBox(QMessageBox::Question, tr("Really make portable?"),
864 tr("This will make the emulator load its configuration from the same directory as the executable. Do you want to continue?"),
865 QMessageBox::Yes | QMessageBox::Cancel, this, Qt::Sheet);
866 confirm->setAttribute(Qt::WA_DeleteOnClose);
867 connect(confirm->button(QMessageBox::Yes), &QAbstractButton::clicked, m_config, &ConfigController::makePortable);
868 confirm->show();
869}
870
871void Window::mustRestart() {
872 QMessageBox* dialog = new QMessageBox(QMessageBox::Warning, tr("Restart needed"),
873 tr("Some changes will not take effect until the emulator is restarted."),
874 QMessageBox::Ok, this, Qt::Sheet);
875 dialog->setAttribute(Qt::WA_DeleteOnClose);
876 dialog->show();
877}
878
879void Window::recordFrame() {
880 m_frameList.append(QDateTime::currentDateTime());
881 while (m_frameList.count() > FRAME_LIST_SIZE) {
882 m_frameList.removeFirst();
883 }
884}
885
886void Window::showFPS() {
887 if (m_frameList.isEmpty()) {
888 updateTitle();
889 return;
890 }
891 qint64 interval = m_frameList.first().msecsTo(m_frameList.last());
892 float fps = (m_frameList.count() - 1) * 10000.f / interval;
893 fps = round(fps) / 10.f;
894 updateTitle(fps);
895}
896
897void Window::updateTitle(float fps) {
898 QString title;
899
900 m_controller->threadInterrupt();
901 if (m_controller->isLoaded()) {
902 const NoIntroDB* db = GBAApp::app()->gameDB();
903 NoIntroGame game{};
904 uint32_t crc32 = 0;
905 m_controller->thread()->core->checksum(m_controller->thread()->core, &crc32, CHECKSUM_CRC32);
906
907 char gameTitle[17] = { '\0' };
908 mCore* core = m_controller->thread()->core;
909 core->getGameTitle(core, gameTitle);
910 title = gameTitle;
911
912#ifdef USE_SQLITE3
913 if (db && crc32 && NoIntroDBLookupGameByCRC(db, crc32, &game)) {
914 title = QLatin1String(game.name);
915 }
916#endif
917 }
918 MultiplayerController* multiplayer = m_controller->multiplayerController();
919 if (multiplayer && multiplayer->attached() > 1) {
920 title += tr(" - Player %1 of %2").arg(multiplayer->playerId(m_controller) + 1).arg(multiplayer->attached());
921 for (QAction* action : m_nonMpActions) {
922 action->setDisabled(true);
923 }
924 } else if (m_controller->isLoaded()) {
925 for (QAction* action : m_nonMpActions) {
926 action->setDisabled(false);
927 }
928 }
929 m_controller->threadContinue();
930 if (title.isNull()) {
931 setWindowTitle(tr("%1 - %2").arg(projectName).arg(projectVersion));
932 } else if (fps < 0) {
933 setWindowTitle(tr("%1 - %2 - %3").arg(projectName).arg(title).arg(projectVersion));
934 } else {
935 setWindowTitle(tr("%1 - %2 (%3 fps) - %4").arg(projectName).arg(title).arg(fps).arg(projectVersion));
936 }
937}
938
939void Window::openStateWindow(LoadSave ls) {
940 if (m_stateWindow) {
941 return;
942 }
943 MultiplayerController* multiplayer = m_controller->multiplayerController();
944 if (multiplayer && multiplayer->attached() > 1) {
945 return;
946 }
947 bool wasPaused = m_controller->isPaused();
948 m_stateWindow = new LoadSaveState(m_controller);
949 connect(this, &Window::shutdown, m_stateWindow, &QWidget::close);
950 connect(m_controller, &GameController::gameStopped, m_stateWindow, &QWidget::close);
951 connect(m_stateWindow, &LoadSaveState::closed, [this]() {
952 detachWidget(m_stateWindow);
953 m_stateWindow = nullptr;
954 QMetaObject::invokeMethod(this, "setFocus", Qt::QueuedConnection);
955 });
956 if (!wasPaused) {
957 m_controller->setPaused(true);
958 connect(m_stateWindow, &LoadSaveState::closed, [this]() { m_controller->setPaused(false); });
959 }
960 m_stateWindow->setAttribute(Qt::WA_DeleteOnClose);
961 m_stateWindow->setMode(ls);
962 attachWidget(m_stateWindow);
963}
964
965void Window::setupMenu(QMenuBar* menubar) {
966 menubar->clear();
967 QMenu* fileMenu = menubar->addMenu(tr("&File"));
968 m_shortcutController->addMenu(fileMenu);
969 installEventFilter(m_shortcutController);
970 addControlledAction(fileMenu, fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open),
971 "loadROM");
972#ifdef USE_SQLITE3
973 addControlledAction(fileMenu, fileMenu->addAction(tr("Load ROM in archive..."), this, SLOT(selectROMInArchive())),
974 "loadROMInArchive");
975 addControlledAction(fileMenu, fileMenu->addAction(tr("Add folder to library..."), this, SLOT(addDirToLibrary())),
976 "addDirToLibrary");
977#endif
978
979 QAction* loadTemporarySave = new QAction(tr("Load temporary save..."), fileMenu);
980 connect(loadTemporarySave, &QAction::triggered, [this]() { this->selectSave(true); });
981 m_gameActions.append(loadTemporarySave);
982 addControlledAction(fileMenu, loadTemporarySave, "loadTemporarySave");
983
984 addControlledAction(fileMenu, fileMenu->addAction(tr("Load &patch..."), this, SLOT(selectPatch())), "loadPatch");
985
986 QAction* bootBIOS = new QAction(tr("Boot BIOS"), fileMenu);
987 connect(bootBIOS, &QAction::triggered, [this]() {
988 m_controller->loadBIOS(PLATFORM_GBA, m_config->getOption("gba.bios"));
989 m_controller->bootBIOS();
990 });
991 addControlledAction(fileMenu, bootBIOS, "bootBIOS");
992
993 addControlledAction(fileMenu, fileMenu->addAction(tr("Replace ROM..."), this, SLOT(replaceROM())), "replaceROM");
994
995 QAction* romInfo = new QAction(tr("ROM &info..."), fileMenu);
996 connect(romInfo, &QAction::triggered, openTView<ROMInfo>());
997 m_gameActions.append(romInfo);
998 addControlledAction(fileMenu, romInfo, "romInfo");
999
1000 m_mruMenu = fileMenu->addMenu(tr("Recent"));
1001
1002 fileMenu->addSeparator();
1003
1004 addControlledAction(fileMenu, fileMenu->addAction(tr("Make portable"), this, SLOT(tryMakePortable())), "makePortable");
1005
1006 fileMenu->addSeparator();
1007
1008 QAction* loadState = new QAction(tr("&Load state"), fileMenu);
1009 loadState->setShortcut(tr("F10"));
1010 connect(loadState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::LOAD); });
1011 m_gameActions.append(loadState);
1012 m_nonMpActions.append(loadState);
1013 addControlledAction(fileMenu, loadState, "loadState");
1014
1015 QAction* saveState = new QAction(tr("&Save state"), fileMenu);
1016 saveState->setShortcut(tr("Shift+F10"));
1017 connect(saveState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::SAVE); });
1018 m_gameActions.append(saveState);
1019 m_nonMpActions.append(saveState);
1020 addControlledAction(fileMenu, saveState, "saveState");
1021
1022 QMenu* quickLoadMenu = fileMenu->addMenu(tr("Quick load"));
1023 QMenu* quickSaveMenu = fileMenu->addMenu(tr("Quick save"));
1024 m_shortcutController->addMenu(quickLoadMenu);
1025 m_shortcutController->addMenu(quickSaveMenu);
1026
1027 QAction* quickLoad = new QAction(tr("Load recent"), quickLoadMenu);
1028 connect(quickLoad, &QAction::triggered, m_controller, &GameController::loadState);
1029 m_gameActions.append(quickLoad);
1030 m_nonMpActions.append(quickLoad);
1031 addControlledAction(quickLoadMenu, quickLoad, "quickLoad");
1032
1033 QAction* quickSave = new QAction(tr("Save recent"), quickSaveMenu);
1034 connect(quickSave, &QAction::triggered, m_controller, &GameController::saveState);
1035 m_gameActions.append(quickSave);
1036 m_nonMpActions.append(quickSave);
1037 addControlledAction(quickSaveMenu, quickSave, "quickSave");
1038
1039 quickLoadMenu->addSeparator();
1040 quickSaveMenu->addSeparator();
1041
1042 QAction* undoLoadState = new QAction(tr("Undo load state"), quickLoadMenu);
1043 undoLoadState->setShortcut(tr("F11"));
1044 connect(undoLoadState, &QAction::triggered, m_controller, &GameController::loadBackupState);
1045 m_gameActions.append(undoLoadState);
1046 m_nonMpActions.append(undoLoadState);
1047 addControlledAction(quickLoadMenu, undoLoadState, "undoLoadState");
1048
1049 QAction* undoSaveState = new QAction(tr("Undo save state"), quickSaveMenu);
1050 undoSaveState->setShortcut(tr("Shift+F11"));
1051 connect(undoSaveState, &QAction::triggered, m_controller, &GameController::saveBackupState);
1052 m_gameActions.append(undoSaveState);
1053 m_nonMpActions.append(undoSaveState);
1054 addControlledAction(quickSaveMenu, undoSaveState, "undoSaveState");
1055
1056 quickLoadMenu->addSeparator();
1057 quickSaveMenu->addSeparator();
1058
1059 int i;
1060 for (i = 1; i < 10; ++i) {
1061 quickLoad = new QAction(tr("State &%1").arg(i), quickLoadMenu);
1062 quickLoad->setShortcut(tr("F%1").arg(i));
1063 connect(quickLoad, &QAction::triggered, [this, i]() { m_controller->loadState(i); });
1064 m_gameActions.append(quickLoad);
1065 m_nonMpActions.append(quickLoad);
1066 addControlledAction(quickLoadMenu, quickLoad, QString("quickLoad.%1").arg(i));
1067
1068 quickSave = new QAction(tr("State &%1").arg(i), quickSaveMenu);
1069 quickSave->setShortcut(tr("Shift+F%1").arg(i));
1070 connect(quickSave, &QAction::triggered, [this, i]() { m_controller->saveState(i); });
1071 m_gameActions.append(quickSave);
1072 m_nonMpActions.append(quickSave);
1073 addControlledAction(quickSaveMenu, quickSave, QString("quickSave.%1").arg(i));
1074 }
1075
1076#ifdef M_CORE_GBA
1077 fileMenu->addSeparator();
1078 QAction* importShark = new QAction(tr("Import GameShark Save"), fileMenu);
1079 connect(importShark, &QAction::triggered, this, &Window::importSharkport);
1080 m_gameActions.append(importShark);
1081 m_gbaActions.append(importShark);
1082 addControlledAction(fileMenu, importShark, "importShark");
1083
1084 QAction* exportShark = new QAction(tr("Export GameShark Save"), fileMenu);
1085 connect(exportShark, &QAction::triggered, this, &Window::exportSharkport);
1086 m_gameActions.append(exportShark);
1087 m_gbaActions.append(exportShark);
1088 addControlledAction(fileMenu, exportShark, "exportShark");
1089#endif
1090
1091 fileMenu->addSeparator();
1092 m_multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
1093 connect(m_multiWindow, &QAction::triggered, [this]() {
1094 GBAApp::app()->newWindow();
1095 });
1096 addControlledAction(fileMenu, m_multiWindow, "multiWindow");
1097
1098#ifndef Q_OS_MAC
1099 fileMenu->addSeparator();
1100#endif
1101
1102 QAction* about = new QAction(tr("About"), fileMenu);
1103 connect(about, &QAction::triggered, this, &Window::openAboutScreen);
1104 fileMenu->addAction(about);
1105
1106#ifndef Q_OS_MAC
1107 addControlledAction(fileMenu, fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit), "quit");
1108#endif
1109
1110 QMenu* emulationMenu = menubar->addMenu(tr("&Emulation"));
1111 m_shortcutController->addMenu(emulationMenu);
1112 QAction* reset = new QAction(tr("&Reset"), emulationMenu);
1113 reset->setShortcut(tr("Ctrl+R"));
1114 connect(reset, &QAction::triggered, m_controller, &GameController::reset);
1115 m_gameActions.append(reset);
1116 addControlledAction(emulationMenu, reset, "reset");
1117
1118 QAction* shutdown = new QAction(tr("Sh&utdown"), emulationMenu);
1119 connect(shutdown, &QAction::triggered, m_controller, &GameController::closeGame);
1120 m_gameActions.append(shutdown);
1121 addControlledAction(emulationMenu, shutdown, "shutdown");
1122
1123#ifdef M_CORE_GBA
1124 QAction* yank = new QAction(tr("Yank game pak"), emulationMenu);
1125 connect(yank, &QAction::triggered, m_controller, &GameController::yankPak);
1126 m_gameActions.append(yank);
1127 m_gbaActions.append(yank);
1128 addControlledAction(emulationMenu, yank, "yank");
1129#endif
1130 emulationMenu->addSeparator();
1131
1132 QAction* pause = new QAction(tr("&Pause"), emulationMenu);
1133 pause->setChecked(false);
1134 pause->setCheckable(true);
1135 pause->setShortcut(tr("Ctrl+P"));
1136 connect(pause, &QAction::triggered, m_controller, &GameController::setPaused);
1137 connect(m_controller, &GameController::gamePaused, [this, pause]() {
1138 pause->setChecked(true);
1139 });
1140 connect(m_controller, &GameController::gameUnpaused, [pause]() { pause->setChecked(false); });
1141 m_gameActions.append(pause);
1142 addControlledAction(emulationMenu, pause, "pause");
1143
1144 QAction* frameAdvance = new QAction(tr("&Next frame"), emulationMenu);
1145 frameAdvance->setShortcut(tr("Ctrl+N"));
1146 connect(frameAdvance, &QAction::triggered, m_controller, &GameController::frameAdvance);
1147 m_gameActions.append(frameAdvance);
1148 addControlledAction(emulationMenu, frameAdvance, "frameAdvance");
1149
1150 emulationMenu->addSeparator();
1151
1152 m_shortcutController->addFunctions(emulationMenu, [this]() {
1153 m_controller->setTurbo(true, false);
1154 }, [this]() {
1155 m_controller->setTurbo(false, false);
1156 }, QKeySequence(Qt::Key_Tab), tr("Fast forward (held)"), "holdFastForward");
1157
1158 QAction* turbo = new QAction(tr("&Fast forward"), emulationMenu);
1159 turbo->setCheckable(true);
1160 turbo->setChecked(false);
1161 turbo->setShortcut(tr("Shift+Tab"));
1162 connect(turbo, SIGNAL(triggered(bool)), m_controller, SLOT(setTurbo(bool)));
1163 addControlledAction(emulationMenu, turbo, "fastForward");
1164
1165 QMenu* ffspeedMenu = emulationMenu->addMenu(tr("Fast forward speed"));
1166 ConfigOption* ffspeed = m_config->addOption("fastForwardRatio");
1167 ffspeed->connect([this](const QVariant& value) {
1168 m_controller->setTurboSpeed(value.toFloat());
1169 }, this);
1170 ffspeed->addValue(tr("Unbounded"), -1.0f, ffspeedMenu);
1171 ffspeed->setValue(QVariant(-1.0f));
1172 ffspeedMenu->addSeparator();
1173 for (i = 2; i < 11; ++i) {
1174 ffspeed->addValue(tr("%0x").arg(i), i, ffspeedMenu);
1175 }
1176 m_config->updateOption("fastForwardRatio");
1177
1178 m_shortcutController->addFunctions(emulationMenu, [this]() {
1179 m_controller->startRewinding();
1180 }, [this]() {
1181 m_controller->stopRewinding();
1182 }, QKeySequence("`"), tr("Rewind (held)"), "holdRewind");
1183
1184 QAction* rewind = new QAction(tr("Re&wind"), emulationMenu);
1185 rewind->setShortcut(tr("~"));
1186 connect(rewind, &QAction::triggered, m_controller, &GameController::rewind);
1187 m_gameActions.append(rewind);
1188 m_nonMpActions.append(rewind);
1189 addControlledAction(emulationMenu, rewind, "rewind");
1190
1191 QAction* frameRewind = new QAction(tr("Step backwards"), emulationMenu);
1192 frameRewind->setShortcut(tr("Ctrl+B"));
1193 connect(frameRewind, &QAction::triggered, [this] () {
1194 m_controller->rewind(1);
1195 });
1196 m_gameActions.append(frameRewind);
1197 m_nonMpActions.append(frameRewind);
1198 addControlledAction(emulationMenu, frameRewind, "frameRewind");
1199
1200 ConfigOption* videoSync = m_config->addOption("videoSync");
1201 videoSync->addBoolean(tr("Sync to &video"), emulationMenu);
1202 videoSync->connect([this](const QVariant& value) {
1203 m_controller->setVideoSync(value.toBool());
1204 }, this);
1205 m_config->updateOption("videoSync");
1206
1207 ConfigOption* audioSync = m_config->addOption("audioSync");
1208 audioSync->addBoolean(tr("Sync to &audio"), emulationMenu);
1209 audioSync->connect([this](const QVariant& value) {
1210 m_controller->setAudioSync(value.toBool());
1211 }, this);
1212 m_config->updateOption("audioSync");
1213
1214 emulationMenu->addSeparator();
1215
1216 QMenu* solarMenu = emulationMenu->addMenu(tr("Solar sensor"));
1217 m_shortcutController->addMenu(solarMenu);
1218 QAction* solarIncrease = new QAction(tr("Increase solar level"), solarMenu);
1219 connect(solarIncrease, &QAction::triggered, m_controller, &GameController::increaseLuminanceLevel);
1220 addControlledAction(solarMenu, solarIncrease, "increaseLuminanceLevel");
1221
1222 QAction* solarDecrease = new QAction(tr("Decrease solar level"), solarMenu);
1223 connect(solarDecrease, &QAction::triggered, m_controller, &GameController::decreaseLuminanceLevel);
1224 addControlledAction(solarMenu, solarDecrease, "decreaseLuminanceLevel");
1225
1226 QAction* maxSolar = new QAction(tr("Brightest solar level"), solarMenu);
1227 connect(maxSolar, &QAction::triggered, [this]() { m_controller->setLuminanceLevel(10); });
1228 addControlledAction(solarMenu, maxSolar, "maxLuminanceLevel");
1229
1230 QAction* minSolar = new QAction(tr("Darkest solar level"), solarMenu);
1231 connect(minSolar, &QAction::triggered, [this]() { m_controller->setLuminanceLevel(0); });
1232 addControlledAction(solarMenu, minSolar, "minLuminanceLevel");
1233
1234 solarMenu->addSeparator();
1235 for (int i = 0; i <= 10; ++i) {
1236 QAction* setSolar = new QAction(tr("Brightness %1").arg(QString::number(i)), solarMenu);
1237 connect(setSolar, &QAction::triggered, [this, i]() {
1238 m_controller->setLuminanceLevel(i);
1239 });
1240 addControlledAction(solarMenu, setSolar, QString("luminanceLevel.%1").arg(QString::number(i)));
1241 }
1242
1243 QMenu* avMenu = menubar->addMenu(tr("Audio/&Video"));
1244 m_shortcutController->addMenu(avMenu);
1245 QMenu* frameMenu = avMenu->addMenu(tr("Frame size"));
1246 m_shortcutController->addMenu(frameMenu, avMenu);
1247 for (int i = 1; i <= 6; ++i) {
1248 QAction* setSize = new QAction(tr("%1x").arg(QString::number(i)), avMenu);
1249 setSize->setCheckable(true);
1250 if (m_savedScale == i) {
1251 setSize->setChecked(true);
1252 }
1253 connect(setSize, &QAction::triggered, [this, i, setSize]() {
1254 showNormal();
1255 QSize size(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
1256 if (m_controller->isLoaded()) {
1257 size = m_controller->screenDimensions();
1258 }
1259 size *= i;
1260 m_savedScale = i;
1261 m_config->setOption("scaleMultiplier", i); // TODO: Port to other
1262 resizeFrame(size);
1263 bool enableSignals = setSize->blockSignals(true);
1264 setSize->setChecked(true);
1265 setSize->blockSignals(enableSignals);
1266 });
1267 m_frameSizes[i] = setSize;
1268 addControlledAction(frameMenu, setSize, QString("frame%1x").arg(QString::number(i)));
1269 }
1270 QKeySequence fullscreenKeys;
1271#ifdef Q_OS_WIN
1272 fullscreenKeys = QKeySequence("Alt+Return");
1273#else
1274 fullscreenKeys = QKeySequence("Ctrl+F");
1275#endif
1276 addControlledAction(frameMenu, frameMenu->addAction(tr("Toggle fullscreen"), this, SLOT(toggleFullScreen()), fullscreenKeys), "fullscreen");
1277
1278 ConfigOption* lockAspectRatio = m_config->addOption("lockAspectRatio");
1279 lockAspectRatio->addBoolean(tr("Lock aspect ratio"), avMenu);
1280 lockAspectRatio->connect([this](const QVariant& value) {
1281 m_display->lockAspectRatio(value.toBool());
1282 if (m_controller->isLoaded()) {
1283 m_screenWidget->setLockAspectRatio(value.toBool());
1284 }
1285 }, this);
1286 m_config->updateOption("lockAspectRatio");
1287
1288 ConfigOption* lockIntegerScaling = m_config->addOption("lockIntegerScaling");
1289 lockIntegerScaling->addBoolean(tr("Force integer scaling"), avMenu);
1290 lockIntegerScaling->connect([this](const QVariant& value) {
1291 m_display->lockIntegerScaling(value.toBool());
1292 if (m_controller->isLoaded()) {
1293 m_screenWidget->setLockIntegerScaling(value.toBool());
1294 }
1295 }, this);
1296 m_config->updateOption("lockIntegerScaling");
1297
1298 ConfigOption* resampleVideo = m_config->addOption("resampleVideo");
1299 resampleVideo->addBoolean(tr("Bilinear filtering"), avMenu);
1300 resampleVideo->connect([this](const QVariant& value) {
1301 m_display->filter(value.toBool());
1302 }, this);
1303 m_config->updateOption("resampleVideo");
1304
1305 QMenu* skipMenu = avMenu->addMenu(tr("Frame&skip"));
1306 ConfigOption* skip = m_config->addOption("frameskip");
1307 skip->connect([this](const QVariant& value) {
1308 reloadConfig();
1309 }, this);
1310 for (int i = 0; i <= 10; ++i) {
1311 skip->addValue(QString::number(i), i, skipMenu);
1312 }
1313 m_config->updateOption("frameskip");
1314
1315 avMenu->addSeparator();
1316
1317 ConfigOption* mute = m_config->addOption("mute");
1318 QAction* muteAction = mute->addBoolean(tr("Mute"), avMenu);
1319 mute->connect([this](const QVariant& value) {
1320 reloadConfig();
1321 }, this);
1322 m_config->updateOption("mute");
1323 addControlledAction(avMenu, muteAction, "mute");
1324
1325 QMenu* target = avMenu->addMenu(tr("FPS target"));
1326 ConfigOption* fpsTargetOption = m_config->addOption("fpsTarget");
1327 fpsTargetOption->connect([this](const QVariant& value) {
1328 emit fpsTargetChanged(value.toFloat());
1329 }, this);
1330 fpsTargetOption->addValue(tr("15"), 15, target);
1331 fpsTargetOption->addValue(tr("30"), 30, target);
1332 fpsTargetOption->addValue(tr("45"), 45, target);
1333 fpsTargetOption->addValue(tr("Native (59.7)"), float(GBA_ARM7TDMI_FREQUENCY) / float(VIDEO_TOTAL_LENGTH), target);
1334 fpsTargetOption->addValue(tr("60"), 60, target);
1335 fpsTargetOption->addValue(tr("90"), 90, target);
1336 fpsTargetOption->addValue(tr("120"), 120, target);
1337 fpsTargetOption->addValue(tr("240"), 240, target);
1338 m_config->updateOption("fpsTarget");
1339
1340#if defined(USE_PNG) || defined(USE_FFMPEG) || defined(USE_MAGICK)
1341 avMenu->addSeparator();
1342#endif
1343
1344#ifdef USE_PNG
1345 QAction* screenshot = new QAction(tr("Take &screenshot"), avMenu);
1346 screenshot->setShortcut(tr("F12"));
1347 connect(screenshot, &QAction::triggered, m_controller, &GameController::screenshot);
1348 m_gameActions.append(screenshot);
1349 addControlledAction(avMenu, screenshot, "screenshot");
1350#endif
1351
1352#ifdef USE_FFMPEG
1353 QAction* recordOutput = new QAction(tr("Record output..."), avMenu);
1354 connect(recordOutput, &QAction::triggered, this, &Window::openVideoWindow);
1355 addControlledAction(avMenu, recordOutput, "recordOutput");
1356 m_gameActions.append(recordOutput);
1357#endif
1358
1359#ifdef USE_MAGICK
1360 QAction* recordGIF = new QAction(tr("Record GIF..."), avMenu);
1361 connect(recordGIF, &QAction::triggered, this, &Window::openGIFWindow);
1362 addControlledAction(avMenu, recordGIF, "recordGIF");
1363#endif
1364
1365 QAction* recordVL = new QAction(tr("Record video log..."), avMenu);
1366 connect(recordVL, &QAction::triggered, this, &Window::startVideoLog);
1367 addControlledAction(avMenu, recordVL, "recordVL");
1368 m_gameActions.append(recordVL);
1369
1370 QAction* stopVL = new QAction(tr("Stop video log"), avMenu);
1371 connect(stopVL, &QAction::triggered, m_controller, &GameController::endVideoLog);
1372 addControlledAction(avMenu, stopVL, "stopVL");
1373 m_gameActions.append(stopVL);
1374
1375 avMenu->addSeparator();
1376 m_videoLayers = avMenu->addMenu(tr("Video layers"));
1377 m_shortcutController->addMenu(m_videoLayers, avMenu);
1378
1379 m_audioChannels = avMenu->addMenu(tr("Audio channels"));
1380 m_shortcutController->addMenu(m_audioChannels, avMenu);
1381
1382 QMenu* toolsMenu = menubar->addMenu(tr("&Tools"));
1383 m_shortcutController->addMenu(toolsMenu);
1384 QAction* viewLogs = new QAction(tr("View &logs..."), toolsMenu);
1385 connect(viewLogs, &QAction::triggered, m_logView, &QWidget::show);
1386 addControlledAction(toolsMenu, viewLogs, "viewLogs");
1387
1388 QAction* overrides = new QAction(tr("Game &overrides..."), toolsMenu);
1389 connect(overrides, &QAction::triggered, openTView<OverrideView, ConfigController*>(m_config));
1390 addControlledAction(toolsMenu, overrides, "overrideWindow");
1391
1392 QAction* sensors = new QAction(tr("Game &Pak sensors..."), toolsMenu);
1393 connect(sensors, &QAction::triggered, openTView<SensorView, InputController*>(&m_inputController));
1394 addControlledAction(toolsMenu, sensors, "sensorWindow");
1395
1396 QAction* cheats = new QAction(tr("&Cheats..."), toolsMenu);
1397 connect(cheats, &QAction::triggered, openTView<CheatsView>());
1398 m_gameActions.append(cheats);
1399 addControlledAction(toolsMenu, cheats, "cheatsWindow");
1400
1401 toolsMenu->addSeparator();
1402 addControlledAction(toolsMenu, toolsMenu->addAction(tr("Settings..."), this, SLOT(openSettingsWindow())),
1403 "settings");
1404
1405 toolsMenu->addSeparator();
1406
1407#ifdef USE_DEBUGGERS
1408 QAction* consoleWindow = new QAction(tr("Open debugger console..."), toolsMenu);
1409 connect(consoleWindow, &QAction::triggered, this, &Window::consoleOpen);
1410 addControlledAction(toolsMenu, consoleWindow, "debuggerWindow");
1411#endif
1412
1413#ifdef USE_GDB_STUB
1414 QAction* gdbWindow = new QAction(tr("Start &GDB server..."), toolsMenu);
1415 connect(gdbWindow, &QAction::triggered, this, &Window::gdbOpen);
1416 m_gbaActions.append(gdbWindow);
1417 addControlledAction(toolsMenu, gdbWindow, "gdbWindow");
1418#endif
1419 toolsMenu->addSeparator();
1420
1421 QAction* paletteView = new QAction(tr("View &palette..."), toolsMenu);
1422 connect(paletteView, &QAction::triggered, openTView<PaletteView>());
1423 m_gameActions.append(paletteView);
1424 addControlledAction(toolsMenu, paletteView, "paletteWindow");
1425
1426 QAction* objView = new QAction(tr("View &sprites..."), toolsMenu);
1427 connect(objView, &QAction::triggered, openTView<ObjView>());
1428 m_gameActions.append(objView);
1429 addControlledAction(toolsMenu, objView, "spriteWindow");
1430
1431 QAction* tileView = new QAction(tr("View &tiles..."), toolsMenu);
1432 connect(tileView, &QAction::triggered, openTView<TileView>());
1433 m_gameActions.append(tileView);
1434 addControlledAction(toolsMenu, tileView, "tileWindow");
1435
1436 QAction* memoryView = new QAction(tr("View memory..."), toolsMenu);
1437 connect(memoryView, &QAction::triggered, openTView<MemoryView>());
1438 m_gameActions.append(memoryView);
1439 addControlledAction(toolsMenu, memoryView, "memoryView");
1440
1441 QAction* memorySearch = new QAction(tr("Search memory..."), toolsMenu);
1442 connect(memorySearch, &QAction::triggered, openTView<MemorySearch>());
1443 m_gameActions.append(memorySearch);
1444 addControlledAction(toolsMenu, memorySearch, "memorySearch");
1445
1446#ifdef M_CORE_GBA
1447 QAction* ioViewer = new QAction(tr("View &I/O registers..."), toolsMenu);
1448 connect(ioViewer, &QAction::triggered, openTView<IOViewer>());
1449 m_gameActions.append(ioViewer);
1450 m_gbaActions.append(ioViewer);
1451 addControlledAction(toolsMenu, ioViewer, "ioViewer");
1452#endif
1453
1454 ConfigOption* skipBios = m_config->addOption("skipBios");
1455 skipBios->connect([this](const QVariant& value) {
1456 reloadConfig();
1457 }, this);
1458
1459 ConfigOption* useBios = m_config->addOption("useBios");
1460 useBios->connect([this](const QVariant& value) {
1461 m_controller->setUseBIOS(value.toBool());
1462 }, this);
1463
1464 ConfigOption* buffers = m_config->addOption("audioBuffers");
1465 buffers->connect([this](const QVariant& value) {
1466 emit audioBufferSamplesChanged(value.toInt());
1467 }, this);
1468
1469 ConfigOption* sampleRate = m_config->addOption("sampleRate");
1470 sampleRate->connect([this](const QVariant& value) {
1471 emit sampleRateChanged(value.toUInt());
1472 }, this);
1473
1474 ConfigOption* volume = m_config->addOption("volume");
1475 volume->connect([this](const QVariant& value) {
1476 reloadConfig();
1477 }, this);
1478
1479 ConfigOption* rewindEnable = m_config->addOption("rewindEnable");
1480 rewindEnable->connect([this](const QVariant& value) {
1481 m_controller->setRewind(value.toBool(), m_config->getOption("rewindBufferCapacity").toInt(), m_config->getOption("rewindSave").toInt());
1482 }, this);
1483
1484 ConfigOption* rewindBufferCapacity = m_config->addOption("rewindBufferCapacity");
1485 rewindBufferCapacity->connect([this](const QVariant& value) {
1486 m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), value.toInt(), m_config->getOption("rewindSave").toInt());
1487 }, this);
1488
1489 ConfigOption* rewindSave = m_config->addOption("rewindSave");
1490 rewindBufferCapacity->connect([this](const QVariant& value) {
1491 m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), m_config->getOption("rewindBufferCapacity").toInt(), value.toBool());
1492 }, this);
1493
1494 ConfigOption* allowOpposingDirections = m_config->addOption("allowOpposingDirections");
1495 allowOpposingDirections->connect([this](const QVariant& value) {
1496 m_inputController.setAllowOpposing(value.toBool());
1497 }, this);
1498
1499 ConfigOption* saveStateExtdata = m_config->addOption("saveStateExtdata");
1500 saveStateExtdata->connect([this](const QVariant& value) {
1501 m_controller->setSaveStateExtdata(value.toInt());
1502 }, this);
1503 m_config->updateOption("saveStateExtdata");
1504
1505 ConfigOption* loadStateExtdata = m_config->addOption("loadStateExtdata");
1506 loadStateExtdata->connect([this](const QVariant& value) {
1507 m_controller->setLoadStateExtdata(value.toInt());
1508 }, this);
1509 m_config->updateOption("loadStateExtdata");
1510
1511 ConfigOption* preload = m_config->addOption("preload");
1512 preload->connect([this](const QVariant& value) {
1513 m_controller->setPreload(value.toBool());
1514 }, this);
1515 m_config->updateOption("preload");
1516
1517 QAction* exitFullScreen = new QAction(tr("Exit fullscreen"), frameMenu);
1518 connect(exitFullScreen, &QAction::triggered, this, &Window::exitFullScreen);
1519 exitFullScreen->setShortcut(QKeySequence("Esc"));
1520 addHiddenAction(frameMenu, exitFullScreen, "exitFullScreen");
1521
1522 QMenu* autofireMenu = new QMenu(tr("Autofire"), this);
1523 m_shortcutController->addMenu(autofireMenu);
1524
1525 m_shortcutController->addFunctions(autofireMenu, [this]() {
1526 m_controller->setAutofire(GBA_KEY_A, true);
1527 }, [this]() {
1528 m_controller->setAutofire(GBA_KEY_A, false);
1529 }, QKeySequence(), tr("Autofire A"), "autofireA");
1530
1531 m_shortcutController->addFunctions(autofireMenu, [this]() {
1532 m_controller->setAutofire(GBA_KEY_B, true);
1533 }, [this]() {
1534 m_controller->setAutofire(GBA_KEY_B, false);
1535 }, QKeySequence(), tr("Autofire B"), "autofireB");
1536
1537 m_shortcutController->addFunctions(autofireMenu, [this]() {
1538 m_controller->setAutofire(GBA_KEY_L, true);
1539 }, [this]() {
1540 m_controller->setAutofire(GBA_KEY_L, false);
1541 }, QKeySequence(), tr("Autofire L"), "autofireL");
1542
1543 m_shortcutController->addFunctions(autofireMenu, [this]() {
1544 m_controller->setAutofire(GBA_KEY_R, true);
1545 }, [this]() {
1546 m_controller->setAutofire(GBA_KEY_R, false);
1547 }, QKeySequence(), tr("Autofire R"), "autofireR");
1548
1549 m_shortcutController->addFunctions(autofireMenu, [this]() {
1550 m_controller->setAutofire(GBA_KEY_START, true);
1551 }, [this]() {
1552 m_controller->setAutofire(GBA_KEY_START, false);
1553 }, QKeySequence(), tr("Autofire Start"), "autofireStart");
1554
1555 m_shortcutController->addFunctions(autofireMenu, [this]() {
1556 m_controller->setAutofire(GBA_KEY_SELECT, true);
1557 }, [this]() {
1558 m_controller->setAutofire(GBA_KEY_SELECT, false);
1559 }, QKeySequence(), tr("Autofire Select"), "autofireSelect");
1560
1561 m_shortcutController->addFunctions(autofireMenu, [this]() {
1562 m_controller->setAutofire(GBA_KEY_UP, true);
1563 }, [this]() {
1564 m_controller->setAutofire(GBA_KEY_UP, false);
1565 }, QKeySequence(), tr("Autofire Up"), "autofireUp");
1566
1567 m_shortcutController->addFunctions(autofireMenu, [this]() {
1568 m_controller->setAutofire(GBA_KEY_RIGHT, true);
1569 }, [this]() {
1570 m_controller->setAutofire(GBA_KEY_RIGHT, false);
1571 }, QKeySequence(), tr("Autofire Right"), "autofireRight");
1572
1573 m_shortcutController->addFunctions(autofireMenu, [this]() {
1574 m_controller->setAutofire(GBA_KEY_DOWN, true);
1575 }, [this]() {
1576 m_controller->setAutofire(GBA_KEY_DOWN, false);
1577 }, QKeySequence(), tr("Autofire Down"), "autofireDown");
1578
1579 m_shortcutController->addFunctions(autofireMenu, [this]() {
1580 m_controller->setAutofire(GBA_KEY_LEFT, true);
1581 }, [this]() {
1582 m_controller->setAutofire(GBA_KEY_LEFT, false);
1583 }, QKeySequence(), tr("Autofire Left"), "autofireLeft");
1584
1585 for (QAction* action : m_gameActions) {
1586 action->setDisabled(true);
1587 }
1588}
1589
1590void Window::attachWidget(QWidget* widget) {
1591 m_screenWidget->layout()->addWidget(widget);
1592 m_screenWidget->unsetCursor();
1593 static_cast<QStackedLayout*>(m_screenWidget->layout())->setCurrentWidget(widget);
1594}
1595
1596void Window::detachWidget(QWidget* widget) {
1597 m_screenWidget->layout()->removeWidget(widget);
1598}
1599
1600void Window::appendMRU(const QString& fname) {
1601 int index = m_mruFiles.indexOf(fname);
1602 if (index >= 0) {
1603 m_mruFiles.removeAt(index);
1604 }
1605 m_mruFiles.prepend(fname);
1606 while (m_mruFiles.size() > ConfigController::MRU_LIST_SIZE) {
1607 m_mruFiles.removeLast();
1608 }
1609 updateMRU();
1610}
1611
1612void Window::updateMRU() {
1613 if (!m_mruMenu) {
1614 return;
1615 }
1616 for (QAction* action : m_mruMenu->actions()) {
1617 delete action;
1618 }
1619 m_mruMenu->clear();
1620 int i = 0;
1621 for (const QString& file : m_mruFiles) {
1622 QAction* item = new QAction(QDir::toNativeSeparators(file).replace("&", "&&"), m_mruMenu);
1623 item->setShortcut(QString("Ctrl+%1").arg(i));
1624 connect(item, &QAction::triggered, [this, file]() { m_controller->loadGame(file); });
1625 m_mruMenu->addAction(item);
1626 ++i;
1627 }
1628 m_config->setMRU(m_mruFiles);
1629 m_config->write();
1630 m_mruMenu->setEnabled(i > 0);
1631}
1632
1633QAction* Window::addControlledAction(QMenu* menu, QAction* action, const QString& name) {
1634 addHiddenAction(menu, action, name);
1635 menu->addAction(action);
1636 return action;
1637}
1638
1639QAction* Window::addHiddenAction(QMenu* menu, QAction* action, const QString& name) {
1640 m_shortcutController->addAction(menu, action, name);
1641 action->setShortcutContext(Qt::WidgetShortcut);
1642 addAction(action);
1643 return action;
1644}
1645
1646void Window::focusCheck() {
1647 if (!m_config->getOption("pauseOnFocusLost").toInt()) {
1648 return;
1649 }
1650 if (QGuiApplication::focusWindow() && m_autoresume) {
1651 m_controller->setPaused(false);
1652 m_autoresume = false;
1653 } else if (!QGuiApplication::focusWindow() && !m_controller->isPaused()) {
1654 m_autoresume = true;
1655 m_controller->setPaused(true);
1656 }
1657}
1658
1659WindowBackground::WindowBackground(QWidget* parent)
1660 : QLabel(parent)
1661{
1662 setLayout(new QStackedLayout());
1663 layout()->setContentsMargins(0, 0, 0, 0);
1664 setAlignment(Qt::AlignCenter);
1665}
1666
1667void WindowBackground::setSizeHint(const QSize& hint) {
1668 m_sizeHint = hint;
1669}
1670
1671QSize WindowBackground::sizeHint() const {
1672 return m_sizeHint;
1673}
1674
1675void WindowBackground::setDimensions(int width, int height) {
1676 m_aspectWidth = width;
1677 m_aspectHeight = height;
1678}
1679
1680void WindowBackground::setLockIntegerScaling(bool lock) {
1681 m_lockIntegerScaling = lock;
1682}
1683
1684void WindowBackground::setLockAspectRatio(bool lock) {
1685 m_lockAspectRatio = lock;
1686}
1687
1688void WindowBackground::paintEvent(QPaintEvent*) {
1689 const QPixmap* logo = pixmap();
1690 if (!logo) {
1691 return;
1692 }
1693 QPainter painter(this);
1694 painter.setRenderHint(QPainter::SmoothPixmapTransform);
1695 painter.fillRect(QRect(QPoint(), size()), Qt::black);
1696 QSize s = size();
1697 QSize ds = s;
1698 if (m_lockAspectRatio) {
1699 if (ds.width() * m_aspectHeight > ds.height() * m_aspectWidth) {
1700 ds.setWidth(ds.height() * m_aspectWidth / m_aspectHeight);
1701 } else if (ds.width() * m_aspectHeight < ds.height() * m_aspectWidth) {
1702 ds.setHeight(ds.width() * m_aspectHeight / m_aspectWidth);
1703 }
1704 }
1705 if (m_lockIntegerScaling) {
1706 ds.setWidth(ds.width() - ds.width() % m_aspectWidth);
1707 ds.setHeight(ds.height() - ds.height() % m_aspectHeight);
1708 }
1709 QPoint origin = QPoint((s.width() - ds.width()) / 2, (s.height() - ds.height()) / 2);
1710 QRect full(origin, ds);
1711 painter.drawPixmap(full, *logo);
1712}