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 reloadConfig();
70 void saveConfig();
71
72 void replaceROM();
73
74 void multiplayerChanged();
75
76 void importSharkport();
77 void exportSharkport();
78
79 void openSettingsWindow();
80 void openOverrideWindow();
81 void openSensorWindow();
82 void openCheatsWindow();
83
84 void openPaletteWindow();
85 void openMemoryWindow();
86 void openIOViewer();
87
88 void openAboutScreen();
89 void openROMInfo();
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 keyPressEvent(QKeyEvent* event) override;
105 virtual void keyReleaseEvent(QKeyEvent* event) override;
106 virtual void resizeEvent(QResizeEvent*) override;
107 virtual void showEvent(QShowEvent*) override;
108 virtual void closeEvent(QCloseEvent*) override;
109 virtual void focusInEvent(QFocusEvent*) override;
110 virtual void focusOutEvent(QFocusEvent*) override;
111 virtual void dragEnterEvent(QDragEnterEvent*) override;
112 virtual void dropEvent(QDropEvent*) override;
113 virtual void mouseDoubleClickEvent(QMouseEvent*) override;
114
115private slots:
116 void gameStarted(GBAThread*);
117 void gameStopped();
118 void gameCrashed(const QString&);
119 void gameFailed();
120 void unimplementedBiosCall(int);
121
122 void tryMakePortable();
123 void mustRestart();
124
125 void recordFrame();
126 void showFPS();
127 void focusCheck();
128
129private:
130 static const int FPS_TIMER_INTERVAL = 2000;
131 static const int FRAME_LIST_SIZE = 120;
132
133 void setupMenu(QMenuBar*);
134 void openStateWindow(LoadSave);
135
136 void attachWidget(QWidget* widget);
137 void detachWidget(QWidget* widget);
138
139 void appendMRU(const QString& fname);
140 void updateMRU();
141
142 void openView(QWidget* widget);
143
144 QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
145 QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
146
147 void updateTitle(float fps = NAN);
148
149 GameController* m_controller;
150 Display* m_display;
151 QList<QAction*> m_gameActions;
152 QList<QAction*> m_nonMpActions;
153 QMap<int, QAction*> m_frameSizes;
154 LogController m_log;
155 LogView* m_logView;
156 LoadSaveState* m_stateWindow;
157 WindowBackground* m_screenWidget;
158 QPixmap m_logo;
159 ConfigController* m_config;
160 InputController m_inputController;
161 QList<QDateTime> m_frameList;
162 QTimer m_fpsTimer;
163 QList<QString> m_mruFiles;
164 QMenu* m_mruMenu;
165 ShortcutController* m_shortcutController;
166 ShaderSelector* m_shaderView;
167 int m_playerId;
168 bool m_fullscreenOnStart;
169 QTimer m_focusCheck;
170 bool m_autoresume;
171
172 bool m_hitUnimplementedBiosCall;
173
174#ifdef USE_FFMPEG
175 VideoView* m_videoView;
176#endif
177
178#ifdef USE_MAGICK
179 GIFView* m_gifView;
180#endif
181
182#ifdef USE_GDB_STUB
183 GDBController* m_gdbController;
184#endif
185};
186
187class WindowBackground : public QLabel {
188Q_OBJECT
189
190public:
191 WindowBackground(QWidget* parent = 0);
192
193 void setSizeHint(const QSize& size);
194 virtual QSize sizeHint() const override;
195 void setLockAspectRatio(int width, int height);
196
197protected:
198 virtual void paintEvent(QPaintEvent*) override;
199
200private:
201 QSize m_sizeHint;
202 int m_aspectWidth;
203 int m_aspectHeight;
204};
205
206}
207
208#endif