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 "core/thread.h"
18#include "gba/gba.h"
19}
20
21#include "GDBController.h"
22#include "InputController.h"
23#include "LoadSaveState.h"
24#include "LogController.h"
25struct mArguments;
26
27namespace QGBA {
28
29class ConfigController;
30class Display;
31class GameController;
32class GIFView;
33class LogView;
34class ShaderSelector;
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(mArguments*);
50
51 void resizeFrame(const QSize& size);
52
53signals:
54 void startDrawing(mCoreThread*);
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 selectROMInArchive();
63 void selectSave(bool temporary);
64 void selectBIOS();
65 void selectPatch();
66 void enterFullScreen();
67 void exitFullScreen();
68 void toggleFullScreen();
69 void loadConfig();
70 void reloadConfig();
71 void saveConfig();
72
73 void replaceROM();
74
75 void multiplayerChanged();
76
77 void importSharkport();
78 void exportSharkport();
79
80 void openSettingsWindow();
81 void openAboutScreen();
82
83#ifdef USE_FFMPEG
84 void openVideoWindow();
85#endif
86
87#ifdef USE_MAGICK
88 void openGIFWindow();
89#endif
90
91#ifdef USE_GDB_STUB
92 void gdbOpen();
93#endif
94
95protected:
96 virtual void keyPressEvent(QKeyEvent* event) override;
97 virtual void keyReleaseEvent(QKeyEvent* event) override;
98 virtual void resizeEvent(QResizeEvent*) override;
99 virtual void showEvent(QShowEvent*) override;
100 virtual void closeEvent(QCloseEvent*) override;
101 virtual void focusInEvent(QFocusEvent*) 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(mCoreThread*, const QString&);
109 void gameStopped();
110 void gameCrashed(const QString&);
111 void gameFailed();
112 void unimplementedBiosCall(int);
113
114 void tryMakePortable();
115 void mustRestart();
116
117 void recordFrame();
118 void showFPS();
119 void focusCheck();
120
121private:
122 static const int FPS_TIMER_INTERVAL = 2000;
123 static const int FRAME_LIST_SIZE = 120;
124
125 void setupMenu(QMenuBar*);
126 void openStateWindow(LoadSave);
127
128 void attachWidget(QWidget* widget);
129 void detachWidget(QWidget* widget);
130
131 void appendMRU(const QString& fname);
132 void updateMRU();
133
134 void openView(QWidget* widget);
135
136 template <typename T, typename... Args> std::function<void()> openTView(const Args&...);
137
138 QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
139 QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
140
141 void updateTitle(float fps = -1);
142
143 QString getFilters() const;
144 QString getFiltersArchive() const;
145
146 GameController* m_controller;
147 Display* m_display;
148 int m_savedScale;
149 // TODO: Move these to a new class
150 QList<QAction*> m_gameActions;
151 QList<QAction*> m_nonMpActions;
152#ifdef M_CORE_GBA
153 QList<QAction*> m_gbaActions;
154#endif
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 ShaderSelector* m_shaderView;
169 bool m_fullscreenOnStart;
170 QTimer m_focusCheck;
171 bool m_autoresume;
172
173 bool m_hitUnimplementedBiosCall;
174
175#ifdef USE_FFMPEG
176 VideoView* m_videoView;
177#endif
178
179#ifdef USE_MAGICK
180 GIFView* m_gifView;
181#endif
182
183#ifdef USE_GDB_STUB
184 GDBController* m_gdbController;
185#endif
186};
187
188class WindowBackground : public QLabel {
189Q_OBJECT
190
191public:
192 WindowBackground(QWidget* parent = 0);
193
194 void setSizeHint(const QSize& size);
195 virtual QSize sizeHint() const override;
196 void setLockAspectRatio(int width, int height);
197
198protected:
199 virtual void paintEvent(QPaintEvent*) override;
200
201private:
202 QSize m_sizeHint;
203 int m_aspectWidth;
204 int m_aspectHeight;
205};
206
207}
208
209#endif