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
88 void openAboutScreen();
89
90#ifdef BUILD_SDL
91 void openGamepadWindow();
92#endif
93
94#ifdef USE_FFMPEG
95 void openVideoWindow();
96#endif
97
98#ifdef USE_MAGICK
99 void openGIFWindow();
100#endif
101
102#ifdef USE_GDB_STUB
103 void gdbOpen();
104#endif
105
106protected:
107 virtual void keyPressEvent(QKeyEvent* event) override;
108 virtual void keyReleaseEvent(QKeyEvent* event) override;
109 virtual void resizeEvent(QResizeEvent*) override;
110 virtual void showEvent(QShowEvent*) override;
111 virtual void closeEvent(QCloseEvent*) override;
112 virtual void focusInEvent(QFocusEvent*) override;
113 virtual void focusOutEvent(QFocusEvent*) override;
114 virtual void dragEnterEvent(QDragEnterEvent*) override;
115 virtual void dropEvent(QDropEvent*) override;
116 virtual void mouseDoubleClickEvent(QMouseEvent*) override;
117
118private slots:
119 void gameStarted(GBAThread*);
120 void gameStopped();
121 void gameCrashed(const QString&);
122 void gameFailed();
123 void unimplementedBiosCall(int);
124
125 void tryMakePortable();
126 void mustRestart();
127
128 void recordFrame();
129 void showFPS();
130
131private:
132 static const int FPS_TIMER_INTERVAL = 2000;
133 static const int FRAME_LIST_SIZE = 120;
134
135 void setupMenu(QMenuBar*);
136 void openStateWindow(LoadSave);
137
138 void attachWidget(QWidget* widget);
139 void detachWidget(QWidget* widget);
140
141 void appendMRU(const QString& fname);
142 void updateMRU();
143
144 void openView(QWidget* widget);
145
146 QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
147 QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
148
149 void updateTitle(float fps = NAN);
150
151 GameController* m_controller;
152 Display* m_display;
153 QList<QAction*> m_gameActions;
154 QList<QAction*> m_nonMpActions;
155 QMap<int, QAction*> m_frameSizes;
156 LogController m_log;
157 LogView* m_logView;
158 LoadSaveState* m_stateWindow;
159 WindowBackground* m_screenWidget;
160 QPixmap m_logo;
161 ConfigController* m_config;
162 InputController m_inputController;
163 QList<QDateTime> m_frameList;
164 QTimer m_fpsTimer;
165 QList<QString> m_mruFiles;
166 QMenu* m_mruMenu;
167 ShortcutController* m_shortcutController;
168 int m_playerId;
169 bool m_fullscreenOnStart;
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