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 );
|
||||
setMinimumHeight( GL_NES_HEIGHT );
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
|
|||
|
||||
setMinimumWidth( GL_NES_WIDTH );
|
||||
setMinimumHeight( GL_NES_HEIGHT );
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
view_width = GL_NES_WIDTH;
|
||||
view_height = GL_NES_HEIGHT;
|
||||
|
|
|
@ -294,16 +294,19 @@ void consoleWin_t::createMainMenu(void)
|
|||
int useNativeMenuBar;
|
||||
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
|
||||
g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar );
|
||||
|
||||
menuBar()->setNativeMenuBar( useNativeMenuBar ? true : false );
|
||||
menubar->setNativeMenuBar( useNativeMenuBar ? true : false );
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// File
|
||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
fileMenu = menubar->addMenu(tr("&File"));
|
||||
|
||||
// File -> Open ROM
|
||||
openROM = new QAction(tr("Open ROM"), this);
|
||||
|
@ -440,7 +443,7 @@ void consoleWin_t::createMainMenu(void)
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
// Options
|
||||
optMenu = menuBar()->addMenu(tr("&Options"));
|
||||
optMenu = menubar->addMenu(tr("&Options"));
|
||||
|
||||
// Options -> Input Config
|
||||
inputConfig = new QAction(tr("Input Config"), this);
|
||||
|
@ -554,7 +557,7 @@ void consoleWin_t::createMainMenu(void)
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
// Emulation
|
||||
emuMenu = menuBar()->addMenu(tr("&Emulation"));
|
||||
emuMenu = menubar->addMenu(tr("&Emulation"));
|
||||
|
||||
// Emulation -> Power
|
||||
powerAct = new QAction(tr("Power"), this);
|
||||
|
@ -743,7 +746,7 @@ void consoleWin_t::createMainMenu(void)
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
// Tools
|
||||
toolsMenu = menuBar()->addMenu(tr("&Tools"));
|
||||
toolsMenu = menubar->addMenu(tr("&Tools"));
|
||||
|
||||
// Tools -> Cheats
|
||||
cheatsAct = new QAction(tr("Cheats..."), this);
|
||||
|
@ -787,7 +790,7 @@ void consoleWin_t::createMainMenu(void)
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
// Debug
|
||||
debugMenu = menuBar()->addMenu(tr("&Debug"));
|
||||
debugMenu = menubar->addMenu(tr("&Debug"));
|
||||
|
||||
// Debug -> Debugger
|
||||
debuggerAct = new QAction(tr("Debugger..."), this);
|
||||
|
@ -855,7 +858,7 @@ void consoleWin_t::createMainMenu(void)
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
// Movie
|
||||
movieMenu = menuBar()->addMenu(tr("Movie"));
|
||||
movieMenu = menubar->addMenu(tr("Movie"));
|
||||
|
||||
// Movie -> Play
|
||||
openMovAct = new QAction(tr("Play"), this);
|
||||
|
@ -896,7 +899,7 @@ void consoleWin_t::createMainMenu(void)
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
// Help
|
||||
helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
helpMenu = menubar->addMenu(tr("&Help"));
|
||||
|
||||
// Help -> About FCEUX
|
||||
aboutAct = new QAction(tr("About FCEUX"), this);
|
||||
|
@ -925,13 +928,13 @@ void consoleWin_t::createMainMenu(void)
|
|||
//---------------------------------------------------------------------------
|
||||
void consoleWin_t::toggleMenuVis(void)
|
||||
{
|
||||
if ( menuBar()->isVisible() )
|
||||
if ( menubar->isVisible() )
|
||||
{
|
||||
menuBar()->setVisible( false );
|
||||
menubar->setVisible( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
menuBar()->setVisible( true );
|
||||
menubar->setVisible( true );
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -2587,3 +2590,35 @@ void emulatorThread_t::run(void)
|
|||
printf("Emulator Exit\n");
|
||||
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();
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -89,6 +100,8 @@ class consoleWin_t : public QMainWindow
|
|||
emulatorThread_t *emulatorThread;
|
||||
|
||||
protected:
|
||||
consoleMenuBar *menubar;
|
||||
|
||||
QMenu *fileMenu;
|
||||
QMenu *optMenu;
|
||||
QMenu *emuMenu;
|
||||
|
@ -155,11 +168,11 @@ class consoleWin_t : public QMainWindow
|
|||
bool closeRequested;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void keyReleaseEvent(QKeyEvent *event);
|
||||
void syncActionConfig( QAction *act, const char *property );
|
||||
void showErrorMsgWindow(void);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void keyReleaseEvent(QKeyEvent *event);
|
||||
void syncActionConfig( QAction *act, const char *property );
|
||||
void showErrorMsgWindow(void);
|
||||
|
||||
private:
|
||||
void createMainMenu(void);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <QApplication>
|
||||
//#include <QProxyStyle>
|
||||
|
||||
#include "Qt/ConsoleWindow.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
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int retval;
|
||||
qInstallMessageHandler(MessageOutput);
|
||||
qInstallMessageHandler(MessageOutput);
|
||||
QApplication app(argc, argv);
|
||||
const char *styleSheetEnv = NULL;
|
||||
const char *styleSheetEnv = NULL;
|
||||
|
||||
//app.setStyle( new MenuStyle() );
|
||||
|
||||
printf("test\n");
|
||||
|
||||
styleSheetEnv = ::getenv("FCEUX_QT_STYLESHEET");
|
||||
|
||||
if ( styleSheetEnv != NULL )
|
||||
{
|
||||
QFile File(styleSheetEnv);
|
||||
|
||||
if ( File.open(QFile::ReadOnly) )
|
||||
{
|
||||
QString StyleSheet = QLatin1String(File.readAll());
|
||||
|
||||
app.setStyleSheet(StyleSheet);
|
||||
|
||||
printf("Using Qt Stylesheet file '%s'\n", styleSheetEnv );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Warning: Could not open Qt Stylesheet file '%s'\n", styleSheetEnv );
|
||||
}
|
||||
}
|
||||
styleSheetEnv = ::getenv("FCEUX_QT_STYLESHEET");
|
||||
|
||||
if ( styleSheetEnv != NULL )
|
||||
{
|
||||
QFile File(styleSheetEnv);
|
||||
|
||||
if ( File.open(QFile::ReadOnly) )
|
||||
{
|
||||
QString StyleSheet = QLatin1String(File.readAll());
|
||||
|
||||
app.setStyleSheet(StyleSheet);
|
||||
|
||||
printf("Using Qt Stylesheet file '%s'\n", styleSheetEnv );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Warning: Could not open Qt Stylesheet file '%s'\n", styleSheetEnv );
|
||||
}
|
||||
}
|
||||
|
||||
fceuWrapperInit( argc, argv );
|
||||
|
||||
|
|
Loading…
Reference in New Issue