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