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