bool KeyEditor::event(QEvent* event) { if (!m_button) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() != Qt::Key_Tab && keyEvent->key() != Qt::Key_Backtab) { return QWidget::event(event); } if (!(keyEvent->modifiers() & ~Qt::ShiftModifier)) { keyPressEvent(keyEvent); keyEvent->accept(); return true; } } } else { if (event->type() == GamepadButtonEvent::Down()) { setValueButton(static_cast<GamepadButtonEvent*>(event)->value()); event->accept(); return true; } if (event->type() == GamepadHatEvent::Down()) { GamepadHatEvent* ghe = static_cast<GamepadHatEvent*>(event); setValueHat(ghe->hatId(), ghe->direction()); event->accept(); return true; } if (event->type() == GamepadAxisEvent::Type()) { GamepadAxisEvent* gae = static_cast<GamepadAxisEvent*>(event); if (gae->isNew()) { setValueAxis(gae->axis(), gae->direction()); } event->accept(); return true; } } return QWidget::event(event); }
bool ShortcutController::eventFilter(QObject*, QEvent* event) { if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->isAutoRepeat()) { return false; } auto item = m_heldKeys.find(keyEventToSequence(keyEvent)); if (item == m_heldKeys.end()) { return false; } ShortcutItem::Functions pair = item.value()->functions(); if (event->type() == QEvent::KeyPress) { if (pair.first) { pair.first(); } } else { if (pair.second) { pair.second(); } } event->accept(); return true; } if (event->type() == GamepadButtonEvent::Down()) { auto item = m_buttons.find(static_cast<GamepadButtonEvent*>(event)->value()); if (item == m_buttons.end()) { return false; } QAction* action = item.value()->action(); if (action && action->isEnabled()) { action->trigger(); } ShortcutItem::Functions pair = item.value()->functions(); if (pair.first) { pair.first(); } event->accept(); return true; } if (event->type() == GamepadButtonEvent::Up()) { auto item = m_buttons.find(static_cast<GamepadButtonEvent*>(event)->value()); if (item == m_buttons.end()) { return false; } ShortcutItem::Functions pair = item.value()->functions(); if (pair.second) { pair.second(); } event->accept(); return true; } if (event->type() == GamepadAxisEvent::Type()) { GamepadAxisEvent* gae = static_cast<GamepadAxisEvent*>(event); auto item = m_axes.find(qMakePair(gae->axis(), gae->direction())); if (item == m_axes.end()) { return false; } if (gae->isNew()) { QAction* action = item.value()->action(); if (action && action->isEnabled()) { action->trigger(); } } ShortcutItem::Functions pair = item.value()->functions(); if (gae->isNew()) { if (pair.first) { pair.first(); } } else { if (pair.second) { pair.second(); } } event->accept(); return true; } return false; }