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