src/platform/qt/Window.h (view raw)
1/* Copyright (c) 2013-2015 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
16extern "C" {
17#include "gba/gba.h"
18}
19
20#include "GDBController.h"
21#include "InputController.h"
22#include "LoadSaveState.h"
23#include "LogController.h"
24
25struct GBAOptions;
26struct GBAArguments;
27
28namespace QGBA {
29
30class ConfigController;
31class Display;
32class GameController;
33class GIFView;
34class LogView;
35class ShaderSelector;
36class ShortcutController;
37class VideoView;
38class WindowBackground;
39
40class Window : public QMainWindow {
41Q_OBJECT
42
43public:
44 Window(ConfigController* config, int playerId = 0, QWidget* parent = nullptr);
45 virtual ~Window();
46
47 GameController* controller() { return m_controller; }
48
49 void setConfig(ConfigController*);
50 void argumentsPassed(GBAArguments*);
51
52 void resizeFrame(int width, int height);
53
54signals:
55 void startDrawing(GBAThread*);
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 void selectBIOS();
64 void selectPatch();
65 void enterFullScreen();
66 void exitFullScreen();
67 void toggleFullScreen();
68 void loadConfig();
69 void saveConfig();
70
71 void replaceROM();
72
73 void multiplayerChanged();
74
75 void importSharkport();
76 void exportSharkport();
77
78 void openKeymapWindow();
79 void openSettingsWindow();
80 void openShortcutWindow();
81
82 void openOverrideWindow();
83 void openSensorWindow();
84 void openCheatsWindow();
85
86 void openPaletteWindow();
87 void openMemoryWindow();
88 void openIOViewer();
89
90 void openAboutScreen();
91 void openROMInfo();
92 void openDatDownloadWindow();
93
94#ifdef BUILD_SDL
95 void openGamepadWindow();
96#endif
97
98#ifdef USE_FFMPEG
99 void openVideoWindow();
100#endif
101
102#ifdef USE_MAGICK
103 void openGIFWindow();
104#endif
105
106#ifdef USE_GDB_STUB
107 void gdbOpen();
108#endif
109
110protected:
111 virtual void keyPressEvent(QKeyEvent* event) override;
112 virtual void keyReleaseEvent(QKeyEvent* event) override;
113 virtual void resizeEvent(QResizeEvent*) override;
114 virtual void showEvent(QShowEvent*) override;
115 virtual void closeEvent(QCloseEvent*) override;
116 virtual void focusInEvent(QFocusEvent*) override;
117 virtual void focusOutEvent(QFocusEvent*) override;
118 virtual void dragEnterEvent(QDragEnterEvent*) override;
119 virtual void dropEvent(QDropEvent*) override;
120 virtual void mouseDoubleClickEvent(QMouseEvent*) override;
121
122private slots:
123 void gameStarted(GBAThread*);
124 void gameStopped();
125 void gameCrashed(const QString&);
126 void gameFailed();
127 void unimplementedBiosCall(int);
128
129 void tryMakePortable();
130 void mustRestart();
131
132 void recordFrame();
133 void showFPS();
134
135private:
136 static const int FPS_TIMER_INTERVAL = 2000;
137 static const int FRAME_LIST_SIZE = 120;
138
139 void setupMenu(QMenuBar*);
140 void openStateWindow(LoadSave);
141
142 void attachWidget(QWidget* widget);
143 void detachWidget(QWidget* widget);
144
145 void appendMRU(const QString& fname);
146 void updateMRU();
147
148 void openView(QWidget* widget);
149
150 QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
151 QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
152
153 void updateTitle(float fps = NAN);
154
155 GameController* m_controller;
156 Display* m_display;
157 QList<QAction*> m_gameActions;
158 QList<QAction*> m_nonMpActions;
159 QMap<int, QAction*> m_frameSizes;
160 LogController m_log;
161 LogView* m_logView;
162 LoadSaveState* m_stateWindow;
163 WindowBackground* m_screenWidget;
164 QPixmap m_logo;
165 ConfigController* m_config;
166 InputController m_inputController;
167 QList<QDateTime> m_frameList;
168 QTimer m_fpsTimer;
169 QList<QString> m_mruFiles;
170 QMenu* m_mruMenu;
171 ShortcutController* m_shortcutController;
172 ShaderSelector* m_shaderView;
173 int m_playerId;
174 bool m_fullscreenOnStart;
175
176 bool m_hitUnimplementedBiosCall;
177
178#ifdef USE_FFMPEG
179 VideoView* m_videoView;
180#endif
181
182#ifdef USE_MAGICK
183 GIFView* m_gifView;
184#endif
185
186#ifdef USE_GDB_STUB
187 GDBController* m_gdbController;
188#endif
189};
190
191class WindowBackground : public QLabel {
192Q_OBJECT
193
194public:
195 WindowBackground(QWidget* parent = 0);
196
197 void setSizeHint(const QSize& size);
198 virtual QSize sizeHint() const override;
199 void setLockAspectRatio(int width, int height);
200
201protected:
202 virtual void paintEvent(QPaintEvent*) override;
203
204private:
205 QSize m_sizeHint;
206 int m_aspectWidth;
207 int m_aspectHeight;
208};
209
210}
211
212#endif