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 "core/thread.h"
18#include "gba/gba.h"
19}
20
21#include "GDBController.h"
22#include "InputController.h"
23#include "LoadSaveState.h"
24#include "LogController.h"
25struct mArguments;
26
27namespace QGBA {
28
29class ConfigController;
30class Display;
31class GameController;
32class GIFView;
33class LogView;
34class ShaderSelector;
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(mArguments*);
50
51 void resizeFrame(const QSize& size);
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 void selectSave(bool temporary);
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(mCoreThread*, const QString&);
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 = -1);
148
149 QString getFilters() const;
150
151 GameController* m_controller;
152 Display* m_display;
153 // TODO: Move these to a new class
154 QList<QAction*> m_gameActions;
155 QList<QAction*> m_nonMpActions;
156 QList<QAction*> m_gbaActions;
157 QMap<int, QAction*> m_frameSizes;
158 LogController m_log;
159 LogView* m_logView;
160 LoadSaveState* m_stateWindow;
161 WindowBackground* m_screenWidget;
162 QPixmap m_logo;
163 ConfigController* m_config;
164 InputController m_inputController;
165 QList<QDateTime> m_frameList;
166 QTimer m_fpsTimer;
167 QList<QString> m_mruFiles;
168 QMenu* m_mruMenu;
169 ShortcutController* m_shortcutController;
170 ShaderSelector* m_shaderView;
171 int m_playerId;
172 bool m_fullscreenOnStart;
173 QTimer m_focusCheck;
174 bool m_autoresume;
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