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 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 selectState(bool load);
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 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 mouseMoveEvent(QMouseEvent*) override;
119 virtual void mousePressEvent(QMouseEvent*) override;
120 virtual void mouseReleaseEvent(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 QList<QPair<QAction*, int>> m_platformActions;
176 QAction* m_multiWindow;
177 QMap<int, QAction*> m_frameSizes;
178 LogController m_log{0};
179 LogView* m_logView;
180#ifdef USE_DEBUGGERS
181 DebuggerConsoleController* m_console = nullptr;
182#endif
183 LoadSaveState* m_stateWindow = nullptr;
184 WindowBackground* m_screenWidget;
185 QPixmap m_logo{":/res/medusa-bg.jpg"};
186 ConfigController* m_config;
187 InputController m_inputController;
188 QList<qint64> m_frameList;
189 QElapsedTimer m_frameTimer;
190 QTimer m_fpsTimer;
191 QList<QString> m_mruFiles;
192 QMenu* m_mruMenu = nullptr;
193 QMenu* m_videoLayers;
194 QMenu* m_audioChannels;
195#if defined(BUILD_GL) || defined(BUILD_GLES2)
196 std::unique_ptr<ShaderSelector> m_shaderView;
197#endif
198 bool m_fullscreenOnStart = false;
199 QTimer m_focusCheck;
200 bool m_autoresume = false;
201 bool m_wasOpened = false;
202 QString m_pendingPatch;
203 QString m_pendingState;
204 bool m_pendingPause = false;
205
206 bool m_hitUnimplementedBiosCall;
207
208 std::unique_ptr<OverrideView> m_overrideView;
209 std::unique_ptr<SensorView> m_sensorView;
210
211#ifdef USE_FFMPEG
212 VideoView* m_videoView = nullptr;
213#endif
214
215#ifdef USE_MAGICK
216 GIFView* m_gifView = nullptr;
217#endif
218
219#ifdef USE_GDB_STUB
220 GDBController* m_gdbController = nullptr;
221#endif
222
223#ifdef USE_SQLITE3
224 LibraryController* m_libraryView;
225#endif
226};
227
228class WindowBackground : public QWidget {
229Q_OBJECT
230
231public:
232 WindowBackground(QWidget* parent = 0);
233
234 void setPixmap(const QPixmap& pixmap);
235 void setSizeHint(const QSize& size);
236 virtual QSize sizeHint() const override;
237 void setDimensions(int width, int height);
238 void setCenteredAspectRatio(int width, int height);
239 void setLockIntegerScaling(bool lock);
240 void setLockAspectRatio(bool lock);
241
242 const QPixmap& pixmap() const { return m_pixmap; }
243
244protected:
245 virtual void paintEvent(QPaintEvent*) override;
246
247private:
248 QPixmap m_pixmap;
249 QSize m_sizeHint;
250 bool m_centered;
251 int m_aspectWidth;
252 int m_aspectHeight;
253 bool m_lockAspectRatio;
254 bool m_lockIntegerScaling;
255};
256
257}