From 49735af56170c421db2cd66f59f5242034744302 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 13 Jun 2021 22:00:45 -0400 Subject: [PATCH] Updated hot key to gamepad binding logic for Qt GUI. --- src/drivers/Qt/GamePadConf.cpp | 68 +++++++++++++++++++++++++--------- src/drivers/Qt/input.cpp | 7 +++- src/drivers/Qt/input.h | 8 ++++ 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index 81dfaf14..653d9904 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -1944,16 +1944,32 @@ void GamePadFuncConfigDialog::changeKeySeq0(void) if ( ret == QDialog::Accepted ) { - printf("Accepted Hot Key: %i\n", hkd.getSelHotKey() ); - k->hk[0] = hkd.getSelHotKey(); - } - else - { - printf("Rejected Hot Key\n"); - } + hotkey_t *hkp; + char keyName[128]; - hk[0]->setCaptureState(true); - hk[0]->setStyleSheet("background-color: green; color: white;"); + //printf("Accepted Hot Key: %i\n", hkd.getSelHotKey() ); + k->hk[0] = hkd.getSelHotKey(); + + hkp = &Hotkeys[ k->hk[0] ]; + + hkp->getString(keyName); + + k->keySeq[0].key = hkp->qkey.value; + k->keySeq[0].modifier = hkp->qkey.modifier; + k->keySeq[0].name.assign(hkp->getConfigName()); + + if ( keySeqLbl[0] ) + { + keySeqLbl[0]->setText( tr(hkp->getConfigName()) ); + } + } + //else + //{ + // printf("Rejected Hot Key\n"); + //} + + //hk[0]->setCaptureState(true); + //hk[0]->setStyleSheet("background-color: green; color: white;"); } //---------------------------------------------------- void GamePadFuncConfigDialog::changeKeySeq1(void) @@ -1965,16 +1981,32 @@ void GamePadFuncConfigDialog::changeKeySeq1(void) if ( ret == QDialog::Accepted ) { - printf("Accepted Hot Key: %i\n", hkd.getSelHotKey() ); - k->hk[1] = hkd.getSelHotKey(); - } - else - { - printf("Rejected Hot Key\n"); - } + hotkey_t *hkp; + char keyName[128]; - hk[1]->setCaptureState(true); - hk[1]->setStyleSheet("background-color: green; color: white;"); + //printf("Accepted Hot Key: %i\n", hkd.getSelHotKey() ); + k->hk[1] = hkd.getSelHotKey(); + + hkp = &Hotkeys[ k->hk[1] ]; + + hkp->getString(keyName); + + k->keySeq[1].key = hkp->qkey.value; + k->keySeq[1].modifier = hkp->qkey.modifier; + k->keySeq[1].name.assign(keyName); + + if ( keySeqLbl[1] ) + { + keySeqLbl[1]->setText( tr(hkp->getConfigName()) ); + } + } + //else + //{ + // printf("Rejected Hot Key\n"); + //} + + //hk[1]->setCaptureState(true); + //hk[1]->setStyleSheet("background-color: green; color: white;"); } //---------------------------------------------------- void GamePadFuncConfigDialog::clearButton0(void) diff --git a/src/drivers/Qt/input.cpp b/src/drivers/Qt/input.cpp index beab9d66..75ba58c5 100644 --- a/src/drivers/Qt/input.cpp +++ b/src/drivers/Qt/input.cpp @@ -200,6 +200,8 @@ hotkey_t::hotkey_t(void) { sdl.value = 0; sdl.modifier = 0; + qkey.value = 0; + qkey.modifier = 0; prevState = 0; shortcut = nullptr; act = nullptr; @@ -253,6 +255,9 @@ void hotkey_t::conv2SDL(void) if (shortcut == nullptr) return; + qkey.value = (Qt::Key)(shortcut->key()[0] & 0x01FFFFFF); + qkey.modifier = (Qt::KeyboardModifier)(shortcut->key()[0] & 0xFE000000); + SDL_Keycode k = convQtKey2SDLKeyCode((Qt::Key)(shortcut->key()[0] & 0x01FFFFFF)); SDL_Keymod m = convQtKey2SDLModifier((Qt::KeyboardModifier)(shortcut->key()[0] & 0xFE000000)); @@ -477,7 +482,7 @@ void gamepad_function_key_t::sendKeyPressEvent(int idx) { QShortcut *s = Hotkeys[ hk[idx] ].getShortcut(); - if ( s ) + if ( s && s->isEnabled() ) { emit s->activated(); hasShortcut = true; diff --git a/src/drivers/Qt/input.h b/src/drivers/Qt/input.h index 97d0411b..07f4ed26 100644 --- a/src/drivers/Qt/input.h +++ b/src/drivers/Qt/input.h @@ -61,6 +61,8 @@ class hotkey_t const char *getConfigName(void); QShortcut *getShortcut(void); + QKeySequence getKeySeq(void){ return keySeq; }; + // Member variables struct { @@ -68,6 +70,12 @@ class hotkey_t int modifier; } sdl; + struct + { + int value; + int modifier; + } qkey; + char prevState; private: