Kbm GUI - minor fixes (#3146)

* KBM Gui fixes

* remove unneeded activate window calls
This commit is contained in:
rainmakerv2 2025-06-27 21:49:31 +08:00 committed by GitHub
parent 4bfd8b967b
commit 09b584b23f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 87 additions and 67 deletions

View file

@ -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; QString SOSString = tr("Speed Offset (def 0.125):") + " " + SOSValue;
ui->SpeedOffsetLabel->setText(SOSString); ui->SpeedOffsetLabel->setText(SOSString);
}); });
connect(this, &KBMSettings::PushKBMEvent, this, [this]() { CheckMapping(MappingButton); });
} }
void KBMSettings::ButtonConnects() { void KBMSettings::ButtonConnects() {
@ -518,7 +520,6 @@ void KBMSettings::StartTimer(QPushButton*& button) {
MappingTimer = 3; MappingTimer = 3;
EnableMapping = true; EnableMapping = true;
MappingCompleted = false; MappingCompleted = false;
modifier = "";
mapping = button->text(); mapping = button->text();
DisableMappingButtons(); DisableMappingButtons();
@ -873,7 +874,6 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
} }
break; break;
case Qt::Key_Meta: case Qt::Key_Meta:
activateWindow();
#ifdef _WIN32 #ifdef _WIN32
pressedKeys.insert("lwin"); pressedKeys.insert("lwin");
#else #else
@ -884,7 +884,6 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
pressedKeys.insert("space"); pressedKeys.insert("space");
break; break;
case Qt::Key_Up: case Qt::Key_Up:
activateWindow();
pressedKeys.insert("up"); pressedKeys.insert("up");
break; break;
case Qt::Key_Down: case Qt::Key_Down:
@ -909,81 +908,100 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
} }
return true; return true;
} }
}
if (event->type() == QEvent::MouseButtonPress) { if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
if (pressedKeys.size() < 3) { if (pressedKeys.size() < 3) {
switch (mouseEvent->button()) { switch (mouseEvent->button()) {
case Qt::LeftButton: case Qt::LeftButton:
pressedKeys.insert("leftbutton"); pressedKeys.insert("leftbutton");
break; break;
case Qt::RightButton: case Qt::RightButton:
pressedKeys.insert("rightbutton"); pressedKeys.insert("rightbutton");
break; break;
case Qt::MiddleButton: case Qt::MiddleButton:
pressedKeys.insert("middlebutton"); pressedKeys.insert("middlebutton");
break; break;
case Qt::XButton1: case Qt::XButton1:
pressedKeys.insert("sidebuttonback"); pressedKeys.insert("sidebuttonback");
break; break;
case Qt::XButton2: case Qt::XButton2:
pressedKeys.insert("sidebuttonforward"); pressedKeys.insert("sidebuttonforward");
break; break;
// default case // default case
default: default:
break; break;
// bottom text // bottom text
}
return true;
} }
return true;
} }
}
const QList<QPushButton*> AxisList = { const QList<QPushButton*> AxisList = {
ui->LStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->LStickRightButton, ui->LStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->LStickRightButton,
ui->RStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->RStickRightButton}; ui->RStickUpButton, ui->LStickDownButton, ui->LStickLeftButton, ui->RStickRightButton};
if (event->type() == QEvent::Wheel) { if (event->type() == QEvent::Wheel) {
QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event); QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
if (pressedKeys.size() < 3) { if (pressedKeys.size() < 3) {
if (wheelEvent->angleDelta().y() > 5) { if (wheelEvent->angleDelta().y() > 5) {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (std::find(AxisList.begin(), AxisList.end(), MappingButton) ==
pressedKeys.insert("mousewheelup"); AxisList.end()) {
} else { pressedKeys.insert("mousewheelup");
QMessageBox::information(this, tr("Cannot set mapping"), if (QApplication::keyboardModifiers() == Qt::NoModifier)
tr("Mousewheel cannot be mapped to stick outputs")); 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 (wheelEvent->angleDelta().x() > 5) {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (std::find(AxisList.begin(), AxisList.end(), MappingButton) ==
pressedKeys.insert("mousewheeldown"); AxisList.end()) {
} else { // QT changes scrolling to horizontal for all widgets with the alt modifier
QMessageBox::information(this, tr("Cannot set mapping"), pressedKeys.insert(
tr("Mousewheel cannot be mapped to stick outputs")); GetModifiedButton(Qt::AltModifier, "mousewheelup", "mousewheelright"));
} if (QApplication::keyboardModifiers() == Qt::NoModifier)
} emit PushKBMEvent();
if (wheelEvent->angleDelta().x() > 5) { } else {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { QMessageBox::information(
// QT changes scrolling to horizontal for all widgets with the alt modifier this, tr("Cannot set mapping"),
pressedKeys.insert( tr("Mousewheel cannot be mapped to stick outputs"));
GetModifiedButton(Qt::AltModifier, "mousewheelup", "mousewheelright")); }
} else { } else if (wheelEvent->angleDelta().x() < -5) {
QMessageBox::information(this, tr("Cannot set mapping"), if (std::find(AxisList.begin(), AxisList.end(), MappingButton) ==
tr("Mousewheel cannot be mapped to stick outputs")); AxisList.end()) {
} pressedKeys.insert(
} else if (wheelEvent->angleDelta().x() < -5) { GetModifiedButton(Qt::AltModifier, "mousewheeldown", "mousewheelleft"));
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (QApplication::keyboardModifiers() == Qt::NoModifier)
pressedKeys.insert( emit PushKBMEvent();
GetModifiedButton(Qt::AltModifier, "mousewheeldown", "mousewheelleft")); } else {
} else { QMessageBox::information(
QMessageBox::information(this, tr("Cannot set mapping"), this, tr("Cannot set mapping"),
tr("Mousewheel cannot be mapped to stick outputs")); tr("Mousewheel cannot be mapped to stick outputs"));
}
} }
} }
} }
if (event->type() == QEvent::KeyRelease || event->type() == QEvent::MouseButtonRelease)
emit PushKBMEvent();
} }
return QDialog::eventFilter(obj, event); return QDialog::eventFilter(obj, event);
} }
KBMSettings::~KBMSettings() {} KBMSettings::~KBMSettings() {}

View file

@ -26,6 +26,9 @@ public:
explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent = nullptr); explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent = nullptr);
~KBMSettings(); ~KBMSettings();
signals:
void PushKBMEvent();
private Q_SLOTS: private Q_SLOTS:
void SaveKBMConfig(bool CloseOnSave); void SaveKBMConfig(bool CloseOnSave);
void SetDefault(); void SetDefault();
@ -50,7 +53,6 @@ private:
bool MappingCompleted = false; bool MappingCompleted = false;
bool HelpWindowOpen = false; bool HelpWindowOpen = false;
QString mapping; QString mapping;
QString modifier;
int MappingTimer; int MappingTimer;
QTimer* timer; QTimer* timer;
QPushButton* MappingButton; QPushButton* MappingButton;