From c790f1481cd1ddfe18cca5480c492b5d489911d6 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 11 Apr 2021 13:53:34 -0400 Subject: [PATCH] Added logic to Qt GUI to produce an error message dialog in the event that an ambiguous activation of conflicting hot key sequences occurs. --- src/drivers/Qt/ConsoleWindow.cpp | 43 ++++++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleWindow.h | 1 + 2 files changed, 44 insertions(+) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 8f6667b0..5120edc6 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -566,6 +566,14 @@ void consoleWin_t::initHotKeys(void) Hotkeys[i].init( this ); } + for (int i = 0; i < HK_MAX; i++) + { + QShortcut *shortcut = Hotkeys[i].getShortcut(); + + // Use Lambda Function to set callback + connect( shortcut, &QShortcut::activatedAmbiguously, [ this, shortcut ] { warnAmbiguousShortcut( shortcut ); } ); + } + // Frame Advance uses key state directly, disable shortcut events Hotkeys[HK_FRAME_ADVANCE].getShortcut()->setEnabled(false); Hotkeys[HK_TURBO ].getShortcut()->setEnabled(false); @@ -2435,6 +2443,41 @@ void consoleWin_t::toggleFamKeyBrdEnable(void) toggleFamilyKeyboardFunc(); } +void consoleWin_t::warnAmbiguousShortcut( QShortcut *shortcut) +{ + char stmp[256]; + std::string msg; + int c = 0; + + sprintf( stmp, "Error: Ambiguous Shortcut Activation for Key Sequence: '%s'\n", shortcut->key().toString().toStdString().c_str() ); + + msg.assign( stmp ); + + for (int i = 0; i < HK_MAX; i++) + { + QShortcut *sc = Hotkeys[i].getShortcut(); + + if ( sc == NULL ) + { + continue; + } + + if ( (sc == shortcut) || (shortcut->key().matches( sc->key() ) == QKeySequence::ExactMatch) ) + { + if ( c == 0 ) + { + msg.append("Hot Key Conflict: "); c++; + } + else + { + msg.append(" and "); c++; + } + msg.append( Hotkeys[i].getConfigName() ); + } + } + QueueErrorMsgWindow( msg.c_str() ); +} + void consoleWin_t::powerConsoleCB(void) { fceuWrapperLock(); diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index c5587688..16a3db4f 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -343,6 +343,7 @@ class consoleWin_t : public QMainWindow void loadState9(void); void mainMenuOpen(void); void mainMenuClose(void); + void warnAmbiguousShortcut( QShortcut*); };