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