CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Qt/mainwindow.h
Views: 1401
#pragma once12#include <queue>3#include <mutex>4#include <string>56#include <QtCore>7#include <QMenuBar>8#include <QMainWindow>9#include <QActionGroup>1011#include "ppsspp_config.h"12#include "Common/System/System.h"13#include "Common/System/NativeApp.h"14#if PPSSPP_PLATFORM(WINDOWS)15#include "Common/Log/ConsoleListener.h"16#endif17#include "Core/Core.h"18#include "Core/Config.h"19#include "Core/System.h"20#include "Qt/QtMain.h"2122extern bool g_TakeScreenshot;2324class MenuAction;25class MenuTree;2627enum {28FB_NON_BUFFERED_MODE = 0,29FB_BUFFERED_MODE = 1,30};3132// hacky, should probably use qt signals or something, but whatever..33enum class MainWindowMsg {34BOOT_DONE,35WINDOW_TITLE_CHANGED,36};3738class MainWindow : public QMainWindow39{40Q_OBJECT4142public:43explicit MainWindow(QWidget *parent = nullptr, bool fullscreen = false);44~MainWindow() { };4546CoreState GetNextState() { return nextState; }4748void updateMenuGroupInt(QActionGroup *group, int value);4950void updateMenus();5152void Notify(MainWindowMsg msg) {53std::unique_lock<std::mutex> lock(msgMutex_);54msgQueue_.push(msg);55}5657void SetWindowTitleAsync(std::string title) {58std::unique_lock<std::mutex> lock(titleMutex_);59newWindowTitle_ = title;60Notify(MainWindowMsg::WINDOW_TITLE_CHANGED);61}6263protected:64void changeEvent(QEvent *e)65{66QMainWindow::changeEvent(e);67// Does not work on Linux for Qt5.2 or Qt5.3 (Qt bug)68if(e->type() == QEvent::WindowStateChange)69Core_NotifyWindowHidden(isMinimized());70}7172void closeEvent(QCloseEvent *) { exitAct(); }7374signals:75void retranslate();76void updateMenu();7778public slots:79void newFrame();8081private slots:82// File83void loadAct();84void closeAct();85void openmsAct();86void saveStateGroup_triggered(QAction *action) { g_Config.iCurrentStateSlot = action->data().toInt(); }87void qlstateAct();88void qsstateAct();89void lstateAct();90void sstateAct();91void recordDisplayAct();92void useLosslessVideoCodecAct();93void useOutputBufferAct();94void recordAudioAct();95void exitAct();9697// Emulation98void runAct();99void pauseAct();100void stopAct();101void resetAct();102void switchUMDAct();103void displayRotationGroup_triggered(QAction *action) { g_Config.iInternalScreenRotation = action->data().toInt(); }104105// Debug106void breakonloadAct();107void ignoreIllegalAct() { g_Config.bIgnoreBadMemAccess = !g_Config.bIgnoreBadMemAccess; }108void lmapAct();109void smapAct();110void lsymAct();111void ssymAct();112void resetTableAct();113void dumpNextAct();114void takeScreen() { g_TakeScreenshot = true; }115void consoleAct();116117// Game settings118void languageAct() { System_PostUIMessage(UIMessage::SHOW_LANGUAGE_SCREEN); }119void controlMappingAct() { System_PostUIMessage(UIMessage::SHOW_CONTROL_MAPPING); }120void displayLayoutEditorAct() { System_PostUIMessage(UIMessage::SHOW_DISPLAY_LAYOUT_EDITOR); }121void moreSettingsAct() { System_PostUIMessage(UIMessage::SHOW_SETTINGS); }122123void bufferRenderAct() {124System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED);125System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);126}127void linearAct() { g_Config.iTexFiltering = (g_Config.iTexFiltering != 0) ? 0 : 3; }128129void renderingResolutionGroup_triggered(QAction *action) {130g_Config.iInternalResolution = action->data().toInt();131System_PostUIMessage(UIMessage::GPU_RENDER_RESIZED);132}133void windowGroup_triggered(QAction *action) { SetWindowScale(action->data().toInt()); }134135void autoframeskipAct() {136g_Config.bAutoFrameSkip = !g_Config.bAutoFrameSkip;137if (g_Config.bSkipBufferEffects) {138g_Config.bSkipBufferEffects = false;139System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);140}141}142void frameSkippingGroup_triggered(QAction *action) { g_Config.iFrameSkip = action->data().toInt(); }143void frameSkippingTypeGroup_triggered(QAction *action) { g_Config.iFrameSkipType = action->data().toInt(); }144void textureFilteringGroup_triggered(QAction *action) { g_Config.iTexFiltering = action->data().toInt(); }145void screenScalingFilterGroup_triggered(QAction *action) { g_Config.iDisplayFilter = action->data().toInt(); }146void textureScalingLevelGroup_triggered(QAction *action) {147g_Config.iTexScalingLevel = action->data().toInt();148System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);149}150void textureScalingTypeGroup_triggered(QAction *action) {151g_Config.iTexScalingType = action->data().toInt();152System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);153}154void deposterizeAct() {155g_Config.bTexDeposterize = !g_Config.bTexDeposterize;156System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);157}158void transformAct() {159g_Config.bHardwareTransform = !g_Config.bHardwareTransform;160System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED);161}162void frameskipAct() { g_Config.iFrameSkip = !g_Config.iFrameSkip; }163void frameskipTypeAct() { g_Config.iFrameSkipType = !g_Config.iFrameSkipType; }164165// Sound166void audioAct() {167g_Config.bEnableSound = !g_Config.bEnableSound;168}169170// Cheats171void cheatsAct() { g_Config.bEnableCheats = !g_Config.bEnableCheats; }172173// Chat174void chatAct() {175if (GetUIState() == UISTATE_INGAME) {176System_PostUIMessage(UIMessage::SHOW_CHAT_SCREEN);177}178}179180void fullscrAct();181void raiseTopMost();182183// Help184void websiteAct();185void forumAct();186void goldAct();187void gitAct();188void discordAct();189void aboutAct();190191// Others192void langChanged(QAction *action) { loadLanguage(action->data().toString(), true); }193194private:195void bootDone();196void SetWindowScale(int zoom);197void SetGameTitle(QString text);198void SetFullScreen(bool fullscreen);199void loadLanguage(const QString &language, bool retranslate);200void createMenus();201202QTranslator translator;203QString currentLanguage;204205CoreState nextState;206GlobalUIState lastUIState;207208QActionGroup *windowGroup,209*textureScalingLevelGroup, *textureScalingTypeGroup,210*screenScalingFilterGroup, *textureFilteringGroup,211*frameSkippingTypeGroup, *frameSkippingGroup,212*renderingResolutionGroup,213*displayRotationGroup, *saveStateGroup;214215std::queue<MainWindowMsg> msgQueue_;216std::mutex msgMutex_;217218std::string newWindowTitle_;219std::mutex titleMutex_;220};221222class MenuAction : public QAction223{224Q_OBJECT225226public:227// Add to QMenu228MenuAction(QWidget* parent, const char *callback, const char *text, QKeySequence key = 0) :229QAction(parent), _text(text)230{231if (key != (QKeySequence)0) {232this->setShortcut(key);233parent->addAction(this); // So we don't lose the shortcut when menubar is hidden234}235connect(this, SIGNAL(triggered()), parent, callback);236connect(parent, SIGNAL(retranslate()), this, SLOT(retranslate()));237connect(parent, SIGNAL(updateMenu()), this, SLOT(update()));238}239// Add to QActionGroup240MenuAction(QWidget* parent, QActionGroup* group, QVariant data, QString text, QKeySequence key = 0) :241QAction(parent)242{243this->setCheckable(true);244this->setData(data);245this->setText(text); // Not translatable, yet246if (key != (QKeySequence)0) {247this->setShortcut(key);248parent->addAction(this); // So we don't lose the shortcut when menubar is hidden249}250group->addAction(this);251}252// Event which causes it to be checked253void addEventChecked(bool* event) {254this->setCheckable(true);255_eventCheck = event;256}257// TODO: Possibly handle compares258void addEventChecked(int* event) {259this->setCheckable(true);260_eventCheck = (bool*)event;261}262// Event which causes it to be unchecked263void addEventUnchecked(bool* event) {264this->setCheckable(true);265_eventUncheck = event;266}267// UI State which causes it to be enabled268void addEnableState(int state) {269_enabledFunc = nullptr;270_stateEnable = state;271_stateDisable = -1;272}273void addDisableState(int state) {274_enabledFunc = nullptr;275_stateEnable = -1;276_stateDisable = state;277}278void SetEnabledFunc(std::function<bool()> func) {279_enabledFunc = func;280_stateEnable = -1;281_stateDisable = -1;282}283public slots:284void retranslate() {285setText(qApp->translate("MainWindow", _text));286}287void update() {288if (_eventCheck)289setChecked(*_eventCheck);290if (_eventUncheck)291setChecked(!*_eventUncheck);292if (_stateEnable >= 0)293setEnabled(GetUIState() == _stateEnable);294if (_stateDisable >= 0)295setEnabled(GetUIState() != _stateDisable);296if (_enabledFunc)297setEnabled(_enabledFunc());298}299private:300const char *_text;301bool *_eventCheck = nullptr;302bool *_eventUncheck = nullptr;303int _stateEnable = -1;304int _stateDisable = -1;305std::function<bool()> _enabledFunc;306};307308class MenuActionGroup : public QActionGroup309{310Q_OBJECT311public:312MenuActionGroup(QWidget* parent, QMenu* menu, const char* callback, QStringList nameList,313QList<int> valueList, QList<int> keyList = QList<int>()) :314QActionGroup(parent)315{316QListIterator<int> i(valueList);317QListIterator<int> k(keyList);318foreach(QString name, nameList) {319new MenuAction(parent, this, i.next(), name, keyList.size() ? k.next() : 0);320}321connect(this, SIGNAL(triggered(QAction *)), parent, callback);322menu->addActions(this->actions());323}324};325326class MenuTree : public QMenu327{328Q_OBJECT329public:330MenuTree(QWidget* parent, QMenuBar* menu, const char *text) :331QMenu(parent), _text(text)332{333menu->addMenu(this);334connect(parent, SIGNAL(retranslate()), this, SLOT(retranslate()));335}336MenuTree(QWidget* parent, QMenu* menu, const char *text) :337QMenu(parent), _text(text)338{339menu->addMenu(this);340connect(parent, SIGNAL(retranslate()), this, SLOT(retranslate()));341}342MenuAction* add(MenuAction* action)343{344addAction(action);345return action;346}347public slots:348void retranslate() {349setTitle(qApp->translate("MainWindow", _text));350}351private:352const char *_text;353};354355356