| 73 | } |
| 74 | |
| 75 | bool HotkeyWidget::event(QEvent *event) |
| 76 | { |
| 77 | if (event->type() == QEvent::LanguageChange) { |
| 78 | setHotkeyText(); |
| 79 | } else if (event->type() == QEvent::KeyPress) { |
| 80 | keyPressEvent(static_cast<QKeyEvent *>(event)); |
| 81 | return true; |
| 82 | } else if (event->type() == QEvent::FocusIn) { |
| 83 | QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event); |
| 84 | |
| 85 | if (focusEvent->reason() != Qt::TabFocusReason) { |
| 86 | setText(tr("Type your hotkey")); |
| 87 | mKeyboardFocus = false; |
| 88 | grabKeyboard(); |
| 89 | } else { |
| 90 | mKeyboardFocus = true; |
| 91 | } |
| 92 | } else if (event->type() == QEvent::FocusOut) { |
| 93 | if (text() == tr("Invalid hotkey")) { |
| 94 | emit invalidHotkeyError(); |
| 95 | showError(); |
| 96 | } |
| 97 | |
| 98 | releaseKeyboard(); |
| 99 | setHotkeyText(); // Reset the text |
| 100 | } else if ((event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride || event->type() == QEvent::Shortcut) && hasFocus()) { |
| 101 | event->accept(); |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | return QPushButton::event(event); |
| 106 | } |
| 107 | |
| 108 | void HotkeyWidget::keyPressEvent(QKeyEvent *event) |
| 109 | { |
nothing calls this directly
no outgoing calls
no test coverage detected