~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Qt/mainwindow.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef MAINWINDOW_H
 
2
#define MAINWINDOW_H
 
3
 
 
4
#include <QtCore>
 
5
#include <QMenuBar>
 
6
#include <QMainWindow>
 
7
#include <QActionGroup>
 
8
 
 
9
#include "ConsoleListener.h"
 
10
#include "Core/Core.h"
 
11
#include "Core/Config.h"
 
12
#include "Core/System.h"
 
13
#include "Debugger/debugger_disasm.h"
 
14
#include "Debugger/debugger_memory.h"
 
15
#include "Debugger/debugger_memorytex.h"
 
16
#include "Debugger/debugger_displaylist.h"
 
17
#include "base/QtMain.h"
 
18
 
 
19
extern bool g_TakeScreenshot;
 
20
 
 
21
class MenuAction;
 
22
class MenuTree;
 
23
 
 
24
class MainWindow : public QMainWindow
 
25
{
 
26
        Q_OBJECT
 
27
 
 
28
public:
 
29
        explicit MainWindow(QWidget *parent = 0, bool fullscreen=false);
 
30
        ~MainWindow() { };
 
31
 
 
32
        Debugger_Disasm* GetDialogDisasm() { return dialogDisasm; }
 
33
        Debugger_Memory* GetDialogMemory() { return memoryWindow; }
 
34
        Debugger_MemoryTex* GetDialogMemoryTex() { return memoryTexWindow; }
 
35
        Debugger_DisplayList* GetDialogDisplaylist() { return displaylistWindow; }
 
36
        CoreState GetNextState() { return nextState; }
 
37
 
 
38
        void ShowMemory(u32 addr);
 
39
        void updateMenus();
 
40
 
 
41
protected:
 
42
        void changeEvent(QEvent *e)
 
43
        {
 
44
                QMainWindow::changeEvent(e);
 
45
                // Does not work on Linux for Qt5.2 or Qt5.3 (Qt bug)
 
46
                if(e->type() == QEvent::WindowStateChange)
 
47
                        Core_NotifyWindowHidden(isMinimized());
 
48
        }
 
49
 
 
50
        void closeEvent(QCloseEvent *) { exitAct(); }
 
51
 
 
52
signals:
 
53
        void retranslate();
 
54
        void updateMenu();
 
55
 
 
56
public slots:
 
57
        void Boot();
 
58
        void newFrame();
 
59
 
 
60
private slots:
 
61
        // File
 
62
        void openAct();
 
63
        void closeAct();
 
64
        void qlstateAct();
 
65
        void qsstateAct();
 
66
        void lstateAct();
 
67
        void sstateAct();
 
68
        void exitAct();
 
69
 
 
70
        // Emulation
 
71
        void runAct();
 
72
        void pauseAct();
 
73
        void resetAct();
 
74
        void runonloadAct();
 
75
 
 
76
        // Debug
 
77
        void lmapAct();
 
78
        void smapAct();
 
79
        void resetTableAct();
 
80
        void dumpNextAct();
 
81
        void takeScreen() { g_TakeScreenshot = true; }
 
82
        void disasmAct();
 
83
        void dpyListAct();
 
84
        void consoleAct();
 
85
        void memviewAct();
 
86
        void memviewTexAct();
 
87
 
 
88
        // Options
 
89
        // Core
 
90
        void vertexDynarecAct() { g_Config.bVertexDecoderJit = !g_Config.bVertexDecoderJit; }
 
91
        void fastmemAct() { g_Config.bFastMemory = !g_Config.bFastMemory; }
 
92
        void ignoreIllegalAct() { g_Config.bIgnoreBadMemAccess = !g_Config.bIgnoreBadMemAccess; }
 
93
 
 
94
        // Video
 
95
        void anisotropicGroup_triggered(QAction *action) { g_Config.iAnisotropyLevel = action->data().toInt(); }
 
96
 
 
97
        void bufferRenderAct() { g_Config.iRenderingMode = !g_Config.iRenderingMode; }
 
98
        void linearAct() { g_Config.iTexFiltering = (g_Config.iTexFiltering != 0) ? 0 : 3; }
 
99
 
 
100
        void screenGroup_triggered(QAction *action) { SetWindowScale(action->data().toInt()); }
 
101
 
 
102
        void displayLayoutGroup_triggered(QAction *action) { g_Config.iSmallDisplayZoomType = action->data().toInt(); }
 
103
        void transformAct() { g_Config.bHardwareTransform = !g_Config.bHardwareTransform; }
 
104
        void vertexCacheAct() { g_Config.bVertexCache = !g_Config.bVertexCache; }
 
105
        void frameskipAct() { g_Config.iFrameSkip = !g_Config.iFrameSkip; }
 
106
 
 
107
        // Sound
 
108
        void audioAct() { g_Config.bEnableSound = !g_Config.bEnableSound; }
 
109
 
 
110
        void fullscrAct();
 
111
        void raiseTopMost();
 
112
        void statsAct() { g_Config.bShowDebugStats = !g_Config.bShowDebugStats; }
 
113
        void showFPSAct() { g_Config.iShowFPSCounter = !g_Config.iShowFPSCounter; }
 
114
 
 
115
        // Logs
 
116
        void defaultLogGroup_triggered(QAction * action) {
 
117
                LogTypes::LOG_LEVELS level = (LogTypes::LOG_LEVELS)action->data().toInt();
 
118
                for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
 
119
                {
 
120
                        LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i;
 
121
                        if(type == LogTypes::G3D || type == LogTypes::HLE)
 
122
                                continue;
 
123
                        LogManager::GetInstance()->SetLogLevel(type, level);
 
124
                }
 
125
         }
 
126
        void g3dLogGroup_triggered(QAction * action) { LogManager::GetInstance()->SetLogLevel(LogTypes::G3D, (LogTypes::LOG_LEVELS)action->data().toInt()); }
 
127
        void hleLogGroup_triggered(QAction * action) { LogManager::GetInstance()->SetLogLevel(LogTypes::HLE, (LogTypes::LOG_LEVELS)action->data().toInt()); }
 
128
 
 
129
        // Help
 
130
        void websiteAct();
 
131
        void forumAct();
 
132
        void aboutAct();
 
133
 
 
134
        // Others
 
135
        void langChanged(QAction *action) { loadLanguage(action->data().toString(), true); }
 
136
 
 
137
private:
 
138
        void SetWindowScale(int zoom);
 
139
        void SetGameTitle(QString text);
 
140
        void loadLanguage(const QString &language, bool retranslate);
 
141
        void createMenus();
 
142
        void notifyMapsLoaded();
 
143
 
 
144
        QTranslator translator;
 
145
        QString currentLanguage;
 
146
 
 
147
        CoreState nextState;
 
148
        InputState input_state;
 
149
        GlobalUIState lastUIState;
 
150
 
 
151
        Debugger_Disasm *dialogDisasm;
 
152
        Debugger_Memory *memoryWindow;
 
153
        Debugger_MemoryTex *memoryTexWindow;
 
154
        Debugger_DisplayList *displaylistWindow;
 
155
 
 
156
        QActionGroup *anisotropicGroup, *screenGroup, *displayLayoutGroup,
 
157
                     *defaultLogGroup, *g3dLogGroup, *hleLogGroup;
 
158
};
 
159
 
 
160
class MenuAction : public QAction
 
161
{
 
162
        Q_OBJECT
 
163
 
 
164
public:
 
165
        // Add to QMenu
 
166
        MenuAction(QWidget* parent, const char *callback, const char *text, QKeySequence key = 0) :
 
167
                QAction(parent), _text(text), _eventCheck(0), _stateEnable(-1), _stateDisable(-1), _enableStepping(false)
 
168
        {
 
169
                if (key != (QKeySequence)0) {
 
170
                        this->setShortcut(key);
 
171
                        parent->addAction(this); // So we don't lose the shortcut when menubar is hidden
 
172
                }
 
173
                connect(this, SIGNAL(triggered()), parent, callback);
 
174
                connect(parent, SIGNAL(retranslate()), this, SLOT(retranslate()));
 
175
                connect(parent, SIGNAL(updateMenu()), this, SLOT(update()));
 
176
        }
 
177
        // Add to QActionGroup
 
178
        MenuAction(QWidget* parent, QActionGroup* group, QVariant data, QString text, QKeySequence key = 0) :
 
179
                QAction(parent), _eventCheck(0), _stateEnable(-1), _stateDisable(-1), _enableStepping(false)
 
180
        {
 
181
                this->setCheckable(true);
 
182
                this->setData(data);
 
183
                this->setText(text); // Not translatable, yet
 
184
                if (key != (QKeySequence)0) {
 
185
                        this->setShortcut(key);
 
186
                        parent->addAction(this); // So we don't lose the shortcut when menubar is hidden
 
187
                }
 
188
                group->addAction(this);
 
189
        }
 
190
        // Event which causes it to be checked
 
191
        void addEventChecked(bool* event) {
 
192
                this->setCheckable(true);
 
193
                _eventCheck = event;
 
194
        }
 
195
        // TODO: Possibly handle compares
 
196
        void addEventChecked(int* event) {
 
197
                this->setCheckable(true);
 
198
                _eventCheck = (bool*)event;
 
199
        }
 
200
        // UI State which causes it to be enabled
 
201
        void addEnableState(int state) {
 
202
                _stateEnable = state;
 
203
        }
 
204
        void addDisableState(int state) {
 
205
                _stateDisable = state;
 
206
        }
 
207
        MenuAction* addEnableStepping() {
 
208
                _enableStepping = true;
 
209
                return this;
 
210
        }
 
211
public slots:
 
212
        void retranslate() {
 
213
                setText(qApp->translate("MainWindow", _text));
 
214
        }
 
215
        void update() {
 
216
                if (_eventCheck)
 
217
                        setChecked(*_eventCheck);
 
218
                if (_stateEnable >= 0)
 
219
                        setEnabled(GetUIState() == _stateEnable);
 
220
                if (_stateDisable >= 0)
 
221
                        setEnabled(GetUIState() != _stateDisable);
 
222
                if (_enableStepping && Core_IsStepping())
 
223
                        setEnabled(true);
 
224
        }
 
225
private:
 
226
        const char *_text;
 
227
        bool *_eventCheck;
 
228
        int _stateEnable, _stateDisable;
 
229
        bool _enableStepping;
 
230
};
 
231
 
 
232
class MenuActionGroup : public QActionGroup
 
233
{
 
234
        Q_OBJECT
 
235
public:
 
236
        MenuActionGroup(QWidget* parent, QMenu* menu, const char* callback, QStringList nameList,
 
237
                QList<int> valueList, QList<int> keyList = QList<int>()) :
 
238
                QActionGroup(parent)
 
239
        {
 
240
                QListIterator<int> i(valueList);
 
241
                QListIterator<int> k(keyList);
 
242
                foreach(QString name, nameList) {
 
243
                        new MenuAction(parent, this, i.next(), name, keyList.size() ? k.next() : 0);
 
244
                }
 
245
                connect(this, SIGNAL(triggered(QAction *)), parent, callback);
 
246
                menu->addActions(this->actions());
 
247
        }
 
248
};
 
249
 
 
250
class MenuTree : public QMenu
 
251
{
 
252
        Q_OBJECT
 
253
public:
 
254
        MenuTree(QWidget* parent, QMenuBar* menu, const char *text) :
 
255
                QMenu(parent), _text(text)
 
256
        {
 
257
                menu->addMenu(this);
 
258
                connect(parent, SIGNAL(retranslate()), this, SLOT(retranslate()));
 
259
        }
 
260
        MenuTree(QWidget* parent, QMenu* menu, const char *text) :
 
261
                QMenu(parent), _text(text)
 
262
        {
 
263
                menu->addMenu(this);
 
264
                connect(parent, SIGNAL(retranslate()), this, SLOT(retranslate()));
 
265
        }
 
266
        MenuAction* add(MenuAction* action)
 
267
        {
 
268
                addAction(action);
 
269
                return action;
 
270
        }
 
271
public slots:
 
272
        void retranslate() {
 
273
                setTitle(qApp->translate("MainWindow", _text));
 
274
        }
 
275
private:
 
276
        const char *_text;
 
277
};
 
278
 
 
279
#endif // MAINWINDOW_H