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