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