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