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