src/platform/qt/Window.h (view raw)
1/* Copyright (c) 2013-2017 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#pragma once
7
8#include <QDateTime>
9#include <QList>
10#include <QMainWindow>
11#include <QTimer>
12
13#include <functional>
14#include <memory>
15
16#include <mgba/core/thread.h>
17
18#include "InputController.h"
19#include "LoadSaveState.h"
20#include "LogController.h"
21struct mArguments;
22
23namespace QGBA {
24
25class AudioProcessor;
26class ConfigController;
27class CoreController;
28class CoreManager;
29class DebuggerConsoleController;
30class Display;
31class GDBController;
32class GIFView;
33class LibraryController;
34class LogView;
35class OverrideView;
36class SensorView;
37class ShaderSelector;
38class ShortcutController;
39class VideoView;
40class WindowBackground;
41
42class Window : public QMainWindow {
43Q_OBJECT
44
45public:
46 Window(CoreManager* manager, ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
47 virtual ~Window();
48
49 std::shared_ptr<CoreController> controller() { return m_controller; }
50
51 void setConfig(ConfigController*);
52 void argumentsPassed(mArguments*);
53
54 void resizeFrame(const QSize& size);
55
56 void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
57
58signals:
59 void startDrawing();
60 void shutdown();
61 void paused(bool);
62
63public slots:
64 void setController(CoreController* controller, const QString& fname);
65 void selectROM();
66#ifdef USE_SQLITE3
67 void selectROMInArchive();
68 void addDirToLibrary();
69#endif
70 void selectSave(bool temporary);
71 void selectPatch();
72 void enterFullScreen();
73 void exitFullScreen();
74 void toggleFullScreen();
75 void loadConfig();
76 void reloadConfig();
77 void saveConfig();
78
79 void loadCamImage();
80
81 void replaceROM();
82
83 void multiplayerChanged();
84
85 void importSharkport();
86 void exportSharkport();
87
88 void openSettingsWindow();
89
90 void startVideoLog();
91
92#ifdef USE_DEBUGGERS
93 void consoleOpen();
94#endif
95
96#ifdef USE_FFMPEG
97 void openVideoWindow();
98#endif
99
100#ifdef USE_MAGICK
101 void openGIFWindow();
102#endif
103
104#ifdef USE_GDB_STUB
105 void gdbOpen();
106#endif
107
108protected:
109 virtual void keyPressEvent(QKeyEvent* event) override;
110 virtual void keyReleaseEvent(QKeyEvent* event) override;
111 virtual void resizeEvent(QResizeEvent*) override;
112 virtual void showEvent(QShowEvent*) override;
113 virtual void closeEvent(QCloseEvent*) override;
114 virtual void focusInEvent(QFocusEvent*) override;
115 virtual void focusOutEvent(QFocusEvent*) override;
116 virtual void dragEnterEvent(QDragEnterEvent*) override;
117 virtual void dropEvent(QDropEvent*) override;
118 virtual void mouseDoubleClickEvent(QMouseEvent*) override;
119
120private slots:
121 void gameStarted();
122 void gameStopped();
123 void gameCrashed(const QString&);
124 void gameFailed();
125 void unimplementedBiosCall(int);
126
127 void reloadAudioDriver();
128 void reloadDisplayDriver();
129
130 void tryMakePortable();
131 void mustRestart();
132
133 void recordFrame();
134 void showFPS();
135 void focusCheck();
136
137private:
138 static const int FPS_TIMER_INTERVAL = 2000;
139 static const int FRAME_LIST_SIZE = 120;
140
141 void setupMenu(QMenuBar*);
142 void openStateWindow(LoadSave);
143
144 void attachWidget(QWidget* widget);
145 void detachWidget(QWidget* widget);
146
147 void appendMRU(const QString& fname);
148 void updateMRU();
149
150 void openView(QWidget* widget);
151
152 template <typename T, typename... A> std::function<void()> openTView(A... arg);
153 template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
154
155 QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
156 QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
157
158 void updateTitle(float fps = -1);
159
160 QString getFilters() const;
161 QString getFiltersArchive() const;
162
163 CoreManager* m_manager;
164 std::shared_ptr<CoreController> m_controller;
165 std::unique_ptr<AudioProcessor> m_audioProcessor;
166
167 std::unique_ptr<Display> m_display;
168 int m_savedScale;
169 // TODO: Move these to a new class
170 QList<QAction*> m_gameActions;
171 QList<QAction*> m_nonMpActions;
172#ifdef M_CORE_GBA
173 QList<QAction*> m_gbaActions;
174#endif
175 QAction* m_multiWindow;
176 QMap<int, QAction*> m_frameSizes;
177 LogController m_log{0};
178 LogView* m_logView;
179#ifdef USE_DEBUGGERS
180 DebuggerConsoleController* m_console = nullptr;
181#endif
182 LoadSaveState* m_stateWindow = nullptr;
183 WindowBackground* m_screenWidget;
184 QPixmap m_logo{":/res/mgba-1024.png"};
185 ConfigController* m_config;
186 InputController m_inputController;
187 QList<QDateTime> m_frameList;
188 QTimer m_fpsTimer;
189 QList<QString> m_mruFiles;
190 QMenu* m_mruMenu = nullptr;
191 QMenu* m_videoLayers;
192 QMenu* m_audioChannels;
193 ShortcutController* m_shortcutController;
194#if defined(BUILD_GL) || defined(BUILD_GLES2)
195 std::unique_ptr<ShaderSelector> m_shaderView;
196#endif
197 bool m_fullscreenOnStart = false;
198 QTimer m_focusCheck;
199 bool m_autoresume = false;
200 bool m_wasOpened = false;
201 QString m_pendingPatch;
202
203 bool m_hitUnimplementedBiosCall;
204
205 std::unique_ptr<OverrideView> m_overrideView;
206 std::unique_ptr<SensorView> m_sensorView;
207
208#ifdef USE_FFMPEG
209 VideoView* m_videoView = nullptr;
210#endif
211
212#ifdef USE_MAGICK
213 GIFView* m_gifView = nullptr;
214#endif
215
216#ifdef USE_GDB_STUB
217 GDBController* m_gdbController = nullptr;
218#endif
219
220#ifdef USE_SQLITE3
221 LibraryController* m_libraryView;
222#endif
223};
224
225class WindowBackground : public QLabel {
226Q_OBJECT
227
228public:
229 WindowBackground(QWidget* parent = 0);
230
231 void setSizeHint(const QSize& size);
232 virtual QSize sizeHint() const override;
233 void setDimensions(int width, int height);
234 void setLockIntegerScaling(bool lock);
235 void setLockAspectRatio(bool lock);
236
237protected:
238 virtual void paintEvent(QPaintEvent*) override;
239
240private:
241 QSize m_sizeHint;
242 int m_aspectWidth;
243 int m_aspectHeight;
244 bool m_lockAspectRatio;
245 bool m_lockIntegerScaling;
246};
247
248}