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