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