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