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 A> std::function<void()> openTView(A arg);
137 template <typename T> std::function<void()> openTView();
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 = -1);
143
144 QString getFilters() const;
145 QString getFiltersArchive() const;
146
147 GameController* m_controller;
148 Display* m_display;
149 int m_savedScale;
150 // TODO: Move these to a new class
151 QList<QAction*> m_gameActions;
152 QList<QAction*> m_nonMpActions;
153#ifdef M_CORE_GBA
154 QList<QAction*> m_gbaActions;
155#endif
156 QMap<int, QAction*> m_frameSizes;
157 LogController m_log;
158 LogView* m_logView;
159 LoadSaveState* m_stateWindow;
160 WindowBackground* m_screenWidget;
161 QPixmap m_logo;
162 ConfigController* m_config;
163 InputController m_inputController;
164 QList<QDateTime> m_frameList;
165 QTimer m_fpsTimer;
166 QList<QString> m_mruFiles;
167 QMenu* m_mruMenu;
168 ShortcutController* m_shortcutController;
169 ShaderSelector* m_shaderView;
170 bool m_fullscreenOnStart;
171 QTimer m_focusCheck;
172 bool m_autoresume;
173
174 bool m_hitUnimplementedBiosCall;
175
176#ifdef USE_FFMPEG
177 VideoView* m_videoView;
178#endif
179
180#ifdef USE_MAGICK
181 GIFView* m_gifView;
182#endif
183
184#ifdef USE_GDB_STUB
185 GDBController* m_gdbController;
186#endif
187};
188
189class WindowBackground : public QLabel {
190Q_OBJECT
191
192public:
193 WindowBackground(QWidget* parent = 0);
194
195 void setSizeHint(const QSize& size);
196 virtual QSize sizeHint() const override;
197 void setLockAspectRatio(int width, int height);
198
199protected:
200 virtual void paintEvent(QPaintEvent*) override;
201
202private:
203 QSize m_sizeHint;
204 int m_aspectWidth;
205 int m_aspectHeight;
206};
207
208}
209
210#endif