Bug fix for Qt GUI main menu permanently hi-jacking input focus when using menu accelerators.
This commit is contained in:
parent
049f1017d4
commit
08df12db74
|
@ -62,6 +62,7 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent)
|
||||||
|
|
||||||
setMinimumWidth( GL_NES_WIDTH );
|
setMinimumWidth( GL_NES_WIDTH );
|
||||||
setMinimumHeight( GL_NES_HEIGHT );
|
setMinimumHeight( GL_NES_HEIGHT );
|
||||||
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
QScreen *screen = QGuiApplication::primaryScreen();
|
QScreen *screen = QGuiApplication::primaryScreen();
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
|
||||||
|
|
||||||
setMinimumWidth( GL_NES_WIDTH );
|
setMinimumWidth( GL_NES_WIDTH );
|
||||||
setMinimumHeight( GL_NES_HEIGHT );
|
setMinimumHeight( GL_NES_HEIGHT );
|
||||||
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
view_width = GL_NES_WIDTH;
|
view_width = GL_NES_WIDTH;
|
||||||
view_height = GL_NES_HEIGHT;
|
view_height = GL_NES_HEIGHT;
|
||||||
|
|
|
@ -294,16 +294,19 @@ void consoleWin_t::createMainMenu(void)
|
||||||
int useNativeMenuBar;
|
int useNativeMenuBar;
|
||||||
QStyle *style;
|
QStyle *style;
|
||||||
|
|
||||||
style = this->style();
|
style = this->style();
|
||||||
|
menubar = new consoleMenuBar(this);
|
||||||
|
|
||||||
|
this->setMenuBar(menubar);
|
||||||
|
|
||||||
// This is needed for menu bar to show up on MacOS
|
// This is needed for menu bar to show up on MacOS
|
||||||
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
|
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
|
||||||
|
|
||||||
menuBar()->setNativeMenuBar( useNativeMenuBar ? true : false );
|
menubar->setNativeMenuBar( useNativeMenuBar ? true : false );
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// File
|
// File
|
||||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
fileMenu = menubar->addMenu(tr("&File"));
|
||||||
|
|
||||||
// File -> Open ROM
|
// File -> Open ROM
|
||||||
openROM = new QAction(tr("Open ROM"), this);
|
openROM = new QAction(tr("Open ROM"), this);
|
||||||
|
@ -440,7 +443,7 @@ void consoleWin_t::createMainMenu(void)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Options
|
// Options
|
||||||
optMenu = menuBar()->addMenu(tr("&Options"));
|
optMenu = menubar->addMenu(tr("&Options"));
|
||||||
|
|
||||||
// Options -> Input Config
|
// Options -> Input Config
|
||||||
inputConfig = new QAction(tr("Input Config"), this);
|
inputConfig = new QAction(tr("Input Config"), this);
|
||||||
|
@ -554,7 +557,7 @@ void consoleWin_t::createMainMenu(void)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Emulation
|
// Emulation
|
||||||
emuMenu = menuBar()->addMenu(tr("&Emulation"));
|
emuMenu = menubar->addMenu(tr("&Emulation"));
|
||||||
|
|
||||||
// Emulation -> Power
|
// Emulation -> Power
|
||||||
powerAct = new QAction(tr("Power"), this);
|
powerAct = new QAction(tr("Power"), this);
|
||||||
|
@ -743,7 +746,7 @@ void consoleWin_t::createMainMenu(void)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Tools
|
// Tools
|
||||||
toolsMenu = menuBar()->addMenu(tr("&Tools"));
|
toolsMenu = menubar->addMenu(tr("&Tools"));
|
||||||
|
|
||||||
// Tools -> Cheats
|
// Tools -> Cheats
|
||||||
cheatsAct = new QAction(tr("Cheats..."), this);
|
cheatsAct = new QAction(tr("Cheats..."), this);
|
||||||
|
@ -787,7 +790,7 @@ void consoleWin_t::createMainMenu(void)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Debug
|
// Debug
|
||||||
debugMenu = menuBar()->addMenu(tr("&Debug"));
|
debugMenu = menubar->addMenu(tr("&Debug"));
|
||||||
|
|
||||||
// Debug -> Debugger
|
// Debug -> Debugger
|
||||||
debuggerAct = new QAction(tr("Debugger..."), this);
|
debuggerAct = new QAction(tr("Debugger..."), this);
|
||||||
|
@ -855,7 +858,7 @@ void consoleWin_t::createMainMenu(void)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Movie
|
// Movie
|
||||||
movieMenu = menuBar()->addMenu(tr("Movie"));
|
movieMenu = menubar->addMenu(tr("Movie"));
|
||||||
|
|
||||||
// Movie -> Play
|
// Movie -> Play
|
||||||
openMovAct = new QAction(tr("Play"), this);
|
openMovAct = new QAction(tr("Play"), this);
|
||||||
|
@ -896,7 +899,7 @@ void consoleWin_t::createMainMenu(void)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Help
|
// Help
|
||||||
helpMenu = menuBar()->addMenu(tr("&Help"));
|
helpMenu = menubar->addMenu(tr("&Help"));
|
||||||
|
|
||||||
// Help -> About FCEUX
|
// Help -> About FCEUX
|
||||||
aboutAct = new QAction(tr("About FCEUX"), this);
|
aboutAct = new QAction(tr("About FCEUX"), this);
|
||||||
|
@ -925,13 +928,13 @@ void consoleWin_t::createMainMenu(void)
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void consoleWin_t::toggleMenuVis(void)
|
void consoleWin_t::toggleMenuVis(void)
|
||||||
{
|
{
|
||||||
if ( menuBar()->isVisible() )
|
if ( menubar->isVisible() )
|
||||||
{
|
{
|
||||||
menuBar()->setVisible( false );
|
menubar->setVisible( false );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
menuBar()->setVisible( true );
|
menubar->setVisible( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -2587,3 +2590,35 @@ void emulatorThread_t::run(void)
|
||||||
printf("Emulator Exit\n");
|
printf("Emulator Exit\n");
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Custom QMenuBar for Console
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
consoleMenuBar::consoleMenuBar(QWidget *parent)
|
||||||
|
: QMenuBar(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
consoleMenuBar::~consoleMenuBar(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void consoleMenuBar::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
QMenuBar::keyPressEvent(event);
|
||||||
|
|
||||||
|
// Force de-focus of menu bar when escape key is pressed.
|
||||||
|
// This prevents the menubar from hi-jacking keyboard input focus
|
||||||
|
// when using menu accelerators
|
||||||
|
if ( event->key() == Qt::Key_Escape )
|
||||||
|
{
|
||||||
|
((QWidget*)parent())->setFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void consoleMenuBar::keyReleaseEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
QMenuBar::keyReleaseEvent(event);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -56,6 +56,17 @@ class emulatorThread_t : public QThread
|
||||||
void finished();
|
void finished();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class consoleMenuBar : public QMenuBar
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
consoleMenuBar(QWidget *parent = 0);
|
||||||
|
~consoleMenuBar(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
void keyReleaseEvent(QKeyEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
class consoleWin_t : public QMainWindow
|
class consoleWin_t : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -89,6 +100,8 @@ class consoleWin_t : public QMainWindow
|
||||||
emulatorThread_t *emulatorThread;
|
emulatorThread_t *emulatorThread;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
consoleMenuBar *menubar;
|
||||||
|
|
||||||
QMenu *fileMenu;
|
QMenu *fileMenu;
|
||||||
QMenu *optMenu;
|
QMenu *optMenu;
|
||||||
QMenu *emuMenu;
|
QMenu *emuMenu;
|
||||||
|
@ -155,11 +168,11 @@ class consoleWin_t : public QMainWindow
|
||||||
bool closeRequested;
|
bool closeRequested;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
void keyReleaseEvent(QKeyEvent *event);
|
void keyReleaseEvent(QKeyEvent *event);
|
||||||
void syncActionConfig( QAction *act, const char *property );
|
void syncActionConfig( QAction *act, const char *property );
|
||||||
void showErrorMsgWindow(void);
|
void showErrorMsgWindow(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createMainMenu(void);
|
void createMainMenu(void);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
//#include <QProxyStyle>
|
||||||
|
|
||||||
#include "Qt/ConsoleWindow.h"
|
#include "Qt/ConsoleWindow.h"
|
||||||
#include "Qt/fceuWrapper.h"
|
#include "Qt/fceuWrapper.h"
|
||||||
|
@ -51,36 +52,51 @@ static void MessageOutput(QtMsgType type, const QMessageLogContext &context, con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This custom menu style wrapper used to prevent the menu bar from permanently stealing window focus when the ALT key is pressed.
|
||||||
|
//class MenuStyle : public QProxyStyle
|
||||||
|
//{
|
||||||
|
//public:
|
||||||
|
// int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const
|
||||||
|
// {
|
||||||
|
// if (stylehint == QStyle::SH_MenuBar_AltKeyNavigation)
|
||||||
|
// return 0;
|
||||||
|
//
|
||||||
|
// return QProxyStyle::styleHint(stylehint, opt, widget, returnData);
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
|
||||||
|
|
||||||
#undef main // undef main in case SDL_Main
|
#undef main // undef main in case SDL_Main
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
qInstallMessageHandler(MessageOutput);
|
qInstallMessageHandler(MessageOutput);
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
const char *styleSheetEnv = NULL;
|
const char *styleSheetEnv = NULL;
|
||||||
|
|
||||||
|
//app.setStyle( new MenuStyle() );
|
||||||
|
|
||||||
printf("test\n");
|
styleSheetEnv = ::getenv("FCEUX_QT_STYLESHEET");
|
||||||
|
|
||||||
styleSheetEnv = ::getenv("FCEUX_QT_STYLESHEET");
|
if ( styleSheetEnv != NULL )
|
||||||
|
{
|
||||||
if ( styleSheetEnv != NULL )
|
QFile File(styleSheetEnv);
|
||||||
{
|
|
||||||
QFile File(styleSheetEnv);
|
if ( File.open(QFile::ReadOnly) )
|
||||||
|
{
|
||||||
if ( File.open(QFile::ReadOnly) )
|
QString StyleSheet = QLatin1String(File.readAll());
|
||||||
{
|
|
||||||
QString StyleSheet = QLatin1String(File.readAll());
|
app.setStyleSheet(StyleSheet);
|
||||||
|
|
||||||
app.setStyleSheet(StyleSheet);
|
printf("Using Qt Stylesheet file '%s'\n", styleSheetEnv );
|
||||||
|
}
|
||||||
printf("Using Qt Stylesheet file '%s'\n", styleSheetEnv );
|
else
|
||||||
}
|
{
|
||||||
else
|
printf("Warning: Could not open Qt Stylesheet file '%s'\n", styleSheetEnv );
|
||||||
{
|
}
|
||||||
printf("Warning: Could not open Qt Stylesheet file '%s'\n", styleSheetEnv );
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fceuWrapperInit( argc, argv );
|
fceuWrapperInit( argc, argv );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue