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