Added main window context menu for Qt GUI.

This commit is contained in:
mjbudd77 2021-07-18 18:07:58 -04:00
parent fcaadd7e84
commit 6aa0c9fec1
5 changed files with 92 additions and 12 deletions

View File

@ -122,6 +122,7 @@ consoleWin_t::consoleWin_t(QWidget *parent)
mainMenuPauseWhenActv = false;
g_config->getOption( "SDL.PauseOnMainMenuAccess", &mainMenuPauseWhenActv );
g_config->getOption( "SDL.ContextMenuEnable", &contextMenuEnable );
g_config->getOption ("SDL.VideoDriver", &use_SDL_video);
if ( use_SDL_video )
@ -498,6 +499,11 @@ void consoleWin_t::setMenuAccessPauseEnable( bool enable )
mainMenuPauseWhenActv = enable;
}
void consoleWin_t::setContextMenuEnable( bool enable )
{
contextMenuEnable = enable;
}
void consoleWin_t::loadCursor(void)
{
int cursorVis;
@ -691,6 +697,47 @@ void consoleWin_t::showEvent(QShowEvent *event)
initScreenHandler();
}
void consoleWin_t::contextMenuEvent(QContextMenuEvent *event)
{
QAction *act;
QMenu menu(this);
if ( !contextMenuEnable )
{
return;
}
act = new QAction(tr("Open ROM"), &menu);
connect( act, SIGNAL(triggered(void)), this, SLOT(openROMFile(void)) );
menu.addAction( act );
act = new QAction(tr("Last ROM Used"), &menu);
act->setEnabled( romList.size() > 0 );
connect( act, SIGNAL(triggered(void)), this, SLOT(loadMostRecentROM(void)) );
menu.addAction( act );
menu.addSeparator();
act = new QAction(tr("Online Help"), &menu);
connect( act, SIGNAL(triggered(void)), this, SLOT(openOnlineDocs(void)) );
menu.addAction( act );
menu.addSeparator();
act = new QAction(tr("Disable Context Menu via Options -> GUI Config"), &menu);
connect( act, SIGNAL(triggered(void)), this, SLOT(openGuiConfWin(void)) );
menu.addAction( act );
menu.addSeparator();
menu.exec(event->globalPos());
event->accept();
}
//---------------------------------------------------------------------------
void consoleWin_t::initHotKeys(void)
{
@ -3915,6 +3962,18 @@ void consoleWin_t::syncActionConfig( QAction *act, const char *property )
}
}
void consoleWin_t::loadMostRecentROM(void)
{
if ( romList.size() <= 0 )
{
return;
}
fceuWrapperLock();
CloseGame ();
LoadGame ( (romList.back())->c_str() );
fceuWrapperUnLock();
}
void consoleWin_t::updatePeriodic(void)
{
// Process all events before attempting to render viewport

View File

@ -165,6 +165,7 @@ class consoleWin_t : public QMainWindow
Qt::CursorShape getViewerCursor(void);
void setMenuAccessPauseEnable(bool enable);
void setContextMenuEnable(bool enable);
protected:
consoleMenuBar *menubar;
@ -249,6 +250,7 @@ class consoleWin_t : public QMainWindow
bool mainMenuEmuWasPaused;
bool mainMenuPauseWhenActv;
bool scrHandlerConnected;
bool contextMenuEnable;
std::list <std::string*> romList;
std::vector <autoFireMenuAction*> afActList;
@ -256,13 +258,14 @@ class consoleWin_t : public QMainWindow
unsigned int updateCounter;
protected:
void resizeEvent(QResizeEvent *event);
void closeEvent(QCloseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event) override;
void closeEvent(QCloseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void showEvent(QShowEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
void syncActionConfig( QAction *act, const char *property );
void showErrorMsgWindow(void);
@ -333,6 +336,7 @@ class consoleWin_t : public QMainWindow
void consolePause(void);
void toggleGameGenie(bool checked);
void loadGameGenieROM(void);
void loadMostRecentROM(void);
void setRegionNTSC(void);
void setRegionPAL(void);
void setRegionDendy(void);

View File

@ -50,7 +50,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
{
int useNativeFileDialogVal;
int useNativeMenuBarVal, pauseOnMenuAccessVal;
int useCustomQssVal, useCustomQPalVal;
int useCustomQssVal, useCustomQPalVal, contextMenuEnable;
QVBoxLayout *mainLayout, *vbox1, *vbox2;
QHBoxLayout *hbox, *hbox1;
QPushButton *closeButton, *button;
@ -75,6 +75,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
g_config->getOption("SDL.UseCustomQss", &useCustomQssVal);
g_config->getOption("SDL.UseCustomQPal", &useCustomQPalVal);
g_config->getOption("SDL.PauseOnMainMenuAccess", &pauseOnMenuAccessVal);
g_config->getOption("SDL.ContextMenuEnable", &contextMenuEnable);
setWindowTitle(tr("GUI Config"));
@ -124,16 +125,19 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
mainLayout->setMenuBar( menuBar );
useNativeFileDialog = new QCheckBox(tr("Use Native OS File Dialog"));
useNativeMenuBar = new QCheckBox(tr("Use Native OS Menu Bar"));
pauseOnMenuAccess = new QCheckBox(tr("Pause On Main Menu Access"));
useNativeMenuBar = new QCheckBox(tr("Use Native OS Menu Bar"));
pauseOnMenuAccess = new QCheckBox(tr("Pause On Main Menu Access"));
ctxMenuEnable = new QCheckBox(tr("Context Menu Enable"));
useNativeFileDialog->setChecked(useNativeFileDialogVal);
useNativeMenuBar->setChecked(useNativeMenuBarVal);
pauseOnMenuAccess->setChecked(pauseOnMenuAccessVal);
ctxMenuEnable->setChecked(contextMenuEnable);
connect(useNativeFileDialog, SIGNAL(stateChanged(int)), this, SLOT(useNativeFileDialogChanged(int)));
connect(useNativeMenuBar, SIGNAL(stateChanged(int)), this, SLOT(useNativeMenuBarChanged(int)));
connect(pauseOnMenuAccess, SIGNAL(stateChanged(int)), this, SLOT(pauseOnMenuAccessChanged(int)));
connect(useNativeMenuBar , SIGNAL(stateChanged(int)), this, SLOT(useNativeMenuBarChanged(int)));
connect(pauseOnMenuAccess , SIGNAL(stateChanged(int)), this, SLOT(pauseOnMenuAccessChanged(int)));
connect(ctxMenuEnable , SIGNAL(stateChanged(int)), this, SLOT(contextMenuEnableChanged(int)));
styleComboBox = new QComboBox();
@ -234,6 +238,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
vbox1->addWidget(useNativeFileDialog, 1);
vbox1->addWidget(useNativeMenuBar, 1);
vbox1->addWidget(pauseOnMenuAccess, 1);
vbox1->addWidget(ctxMenuEnable, 1);
vbox1->addStretch(10);
closeButton = new QPushButton( tr("Close") );
@ -296,6 +301,15 @@ void GuiConfDialog_t::pauseOnMenuAccessChanged(int state)
consoleWindow->setMenuAccessPauseEnable( value );
}
//----------------------------------------------------
void GuiConfDialog_t::contextMenuEnableChanged(int state)
{
int value = (state == Qt::Unchecked) ? 0 : 1;
g_config->setOption("SDL.ContextMenuEnable", value);
consoleWindow->setContextMenuEnable( value );
}
//----------------------------------------------------
void GuiConfDialog_t::useCustomStyleChanged(int state)
{
int value = (state == Qt::Unchecked) ? 0 : 1;

View File

@ -143,6 +143,7 @@ protected:
QCheckBox *useNativeFileDialog;
QCheckBox *useNativeMenuBar;
QCheckBox *pauseOnMenuAccess;
QCheckBox *ctxMenuEnable;
QCheckBox *useCustomStyle;
QCheckBox *useCustomPalette;
QComboBox *styleComboBox;
@ -156,6 +157,7 @@ private slots:
void useNativeFileDialogChanged(int v);
void useNativeMenuBarChanged(int v);
void pauseOnMenuAccessChanged(int v);
void contextMenuEnableChanged(int v);
void useCustomQPaletteChanged(int v);
void useCustomStyleChanged(int v);
void styleChanged(int index);

View File

@ -657,6 +657,7 @@ InitConfig()
config->addOption("_useNativeFileDialog", "SDL.UseNativeFileDialog", false);
config->addOption("_useNativeMenuBar" , "SDL.UseNativeMenuBar", false);
config->addOption("SDL.PauseOnMainMenuAccess", false);
config->addOption("SDL.ContextMenuEnable", true);
config->addOption("SDL.GuiStyle", "");
config->addOption("SDL.QtStyleSheet", "");
config->addOption("SDL.QPaletteFile", "");