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