From 09b584b23fc564c2e492a821b6eeb03b46f84dc5 Mon Sep 17 00:00:00 2001 From: rainmakerv2 <30595646+rainmakerv3@users.noreply.github.com> Date: Fri, 27 Jun 2025 21:49:31 +0800 Subject: [PATCH] Kbm GUI - minor fixes (#3146) * KBM Gui fixes * remove unneeded activate window calls --- src/qt_gui/kbm_gui.cpp | 150 +++++++++++++++++++++++------------------ src/qt_gui/kbm_gui.h | 4 +- 2 files changed, 87 insertions(+), 67 deletions(-) diff --git a/src/qt_gui/kbm_gui.cpp b/src/qt_gui/kbm_gui.cpp index 4cc3c16db..3f41e1f08 100644 --- a/src/qt_gui/kbm_gui.cpp +++ b/src/qt_gui/kbm_gui.cpp @@ -144,6 +144,8 @@ tr("Do you want to overwrite existing mappings with the mappings from the Common QString SOSString = tr("Speed Offset (def 0.125):") + " " + SOSValue; ui->SpeedOffsetLabel->setText(SOSString); }); + + connect(this, &KBMSettings::PushKBMEvent, this, [this]() { CheckMapping(MappingButton); }); } void KBMSettings::ButtonConnects() { @@ -518,7 +520,6 @@ void KBMSettings::StartTimer(QPushButton*& button) { MappingTimer = 3; EnableMapping = true; MappingCompleted = false; - modifier = ""; mapping = button->text(); DisableMappingButtons(); @@ -873,7 +874,6 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { } break; case Qt::Key_Meta: - activateWindow(); #ifdef _WIN32 pressedKeys.insert("lwin"); #else @@ -884,7 +884,6 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { pressedKeys.insert("space"); break; case Qt::Key_Up: - activateWindow(); pressedKeys.insert("up"); break; case Qt::Key_Down: @@ -909,81 +908,100 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { } return true; } - } - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent* mouseEvent = static_cast(event); - if (pressedKeys.size() < 3) { - switch (mouseEvent->button()) { - case Qt::LeftButton: - pressedKeys.insert("leftbutton"); - break; - case Qt::RightButton: - pressedKeys.insert("rightbutton"); - break; - case Qt::MiddleButton: - pressedKeys.insert("middlebutton"); - break; - case Qt::XButton1: - pressedKeys.insert("sidebuttonback"); - break; - case Qt::XButton2: - pressedKeys.insert("sidebuttonforward"); - break; + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent* mouseEvent = static_cast(event); + if (pressedKeys.size() < 3) { + switch (mouseEvent->button()) { + case Qt::LeftButton: + pressedKeys.insert("leftbutton"); + break; + case Qt::RightButton: + pressedKeys.insert("rightbutton"); + break; + case Qt::MiddleButton: + pressedKeys.insert("middlebutton"); + break; + case Qt::XButton1: + pressedKeys.insert("sidebuttonback"); + break; + case Qt::XButton2: + pressedKeys.insert("sidebuttonforward"); + break; - // default case - default: - break; - // bottom text + // default case + default: + break; + // bottom text + } + return true; } - return true; } - } - const QList AxisList = { - ui->LStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->LStickRightButton, - ui->RStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->RStickRightButton}; + const QList AxisList = { + ui->LStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->LStickRightButton, + ui->RStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->RStickRightButton}; - if (event->type() == QEvent::Wheel) { - QWheelEvent* wheelEvent = static_cast(event); - if (pressedKeys.size() < 3) { - if (wheelEvent->angleDelta().y() > 5) { - if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { - pressedKeys.insert("mousewheelup"); - } else { - QMessageBox::information(this, tr("Cannot set mapping"), - tr("Mousewheel cannot be mapped to stick outputs")); + if (event->type() == QEvent::Wheel) { + QWheelEvent* wheelEvent = static_cast(event); + if (pressedKeys.size() < 3) { + if (wheelEvent->angleDelta().y() > 5) { + if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == + AxisList.end()) { + pressedKeys.insert("mousewheelup"); + if (QApplication::keyboardModifiers() == Qt::NoModifier) + emit PushKBMEvent(); + } else { + QMessageBox::information( + this, tr("Cannot set mapping"), + tr("Mousewheel cannot be mapped to stick outputs")); + } + } else if (wheelEvent->angleDelta().y() < -5) { + if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == + AxisList.end()) { + pressedKeys.insert("mousewheeldown"); + if (QApplication::keyboardModifiers() == Qt::NoModifier) + emit PushKBMEvent(); + } else { + QMessageBox::information( + this, tr("Cannot set mapping"), + tr("Mousewheel cannot be mapped to stick outputs")); + } } - } else if (wheelEvent->angleDelta().y() < -5) { - if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { - pressedKeys.insert("mousewheeldown"); - } else { - QMessageBox::information(this, tr("Cannot set mapping"), - tr("Mousewheel cannot be mapped to stick outputs")); - } - } - if (wheelEvent->angleDelta().x() > 5) { - if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { - // QT changes scrolling to horizontal for all widgets with the alt modifier - pressedKeys.insert( - GetModifiedButton(Qt::AltModifier, "mousewheelup", "mousewheelright")); - } else { - QMessageBox::information(this, tr("Cannot set mapping"), - tr("Mousewheel cannot be mapped to stick outputs")); - } - } else if (wheelEvent->angleDelta().x() < -5) { - if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { - pressedKeys.insert( - GetModifiedButton(Qt::AltModifier, "mousewheeldown", "mousewheelleft")); - } else { - QMessageBox::information(this, tr("Cannot set mapping"), - tr("Mousewheel cannot be mapped to stick outputs")); + if (wheelEvent->angleDelta().x() > 5) { + if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == + AxisList.end()) { + // QT changes scrolling to horizontal for all widgets with the alt modifier + pressedKeys.insert( + GetModifiedButton(Qt::AltModifier, "mousewheelup", "mousewheelright")); + if (QApplication::keyboardModifiers() == Qt::NoModifier) + emit PushKBMEvent(); + } else { + QMessageBox::information( + this, tr("Cannot set mapping"), + tr("Mousewheel cannot be mapped to stick outputs")); + } + } else if (wheelEvent->angleDelta().x() < -5) { + if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == + AxisList.end()) { + pressedKeys.insert( + GetModifiedButton(Qt::AltModifier, "mousewheeldown", "mousewheelleft")); + if (QApplication::keyboardModifiers() == Qt::NoModifier) + emit PushKBMEvent(); + } else { + QMessageBox::information( + this, tr("Cannot set mapping"), + tr("Mousewheel cannot be mapped to stick outputs")); + } } } } + + if (event->type() == QEvent::KeyRelease || event->type() == QEvent::MouseButtonRelease) + emit PushKBMEvent(); } return QDialog::eventFilter(obj, event); } -KBMSettings::~KBMSettings() {} \ No newline at end of file +KBMSettings::~KBMSettings() {} diff --git a/src/qt_gui/kbm_gui.h b/src/qt_gui/kbm_gui.h index 09a9166b9..b14b506bd 100644 --- a/src/qt_gui/kbm_gui.h +++ b/src/qt_gui/kbm_gui.h @@ -26,6 +26,9 @@ public: explicit KBMSettings(std::shared_ptr game_info_get, QWidget* parent = nullptr); ~KBMSettings(); +signals: + void PushKBMEvent(); + private Q_SLOTS: void SaveKBMConfig(bool CloseOnSave); void SetDefault(); @@ -50,7 +53,6 @@ private: bool MappingCompleted = false; bool HelpWindowOpen = false; QString mapping; - QString modifier; int MappingTimer; QTimer* timer; QPushButton* MappingButton;