diff --git a/sdrgui/gui/commandkeyreceiver.cpp b/sdrgui/gui/commandkeyreceiver.cpp index c586c89c7..bd758e9e1 100644 --- a/sdrgui/gui/commandkeyreceiver.cpp +++ b/sdrgui/gui/commandkeyreceiver.cpp @@ -39,10 +39,10 @@ bool CommandKeyReceiver::eventFilter(QObject* obj, QEvent* event) Qt::KeyboardModifiers keyModifiers; keyEventHandler(keyEvent, key, keyModifiers); emit capturedKey(key, keyModifiers, false); - } - if (!m_pass) { - return true; + if (!m_pass) { // do not pass the event + return true; + } } } else if (m_release && (event->type()==QEvent::KeyRelease)) @@ -56,14 +56,14 @@ bool CommandKeyReceiver::eventFilter(QObject* obj, QEvent* event) Qt::KeyboardModifiers keyModifiers; keyEventHandler(keyEvent, key, keyModifiers); emit capturedKey(key, keyModifiers, true); - } - if (!m_pass) { - return true; + if (!m_pass) { // do not pass the event + return true; + } } } - return QObject::eventFilter(obj, event); + return QObject::eventFilter(obj, event); // pass the event on } void CommandKeyReceiver::keyEventHandler(QKeyEvent *e, Qt::Key& key, Qt::KeyboardModifiers& keyModifiers) diff --git a/sdrgui/gui/editcommanddialog.cpp b/sdrgui/gui/editcommanddialog.cpp index d8fc3b34b..69191790e 100644 --- a/sdrgui/gui/editcommanddialog.cpp +++ b/sdrgui/gui/editcommanddialog.cpp @@ -17,14 +17,12 @@ #include "editcommanddialog.h" #include "ui_editcommanddialog.h" #include "commands/command.h" +#include "commandkeyreceiver.h" #include #include -#include #include -const std::vector EditCommandDialog::m_composeKeys = {Qt::Key_Shift, Qt::Key_Control, Qt::Key_Meta, Qt::Key_Alt, Qt::Key_AltGr}; - EditCommandDialog::EditCommandDialog(const QStringList& groups, const QString& group, QWidget* parent) : QDialog(parent), ui(new Ui::EditCommandDialog), @@ -35,10 +33,14 @@ EditCommandDialog::EditCommandDialog(const QStringList& groups, const QString& g ui->group->lineEdit()->setText(group); setKeyAssociate(); setKeyLabel(); + + m_commandKeyReceiver = new CommandKeyReceiver(); + this->installEventFilter(m_commandKeyReceiver); } EditCommandDialog::~EditCommandDialog() { + m_commandKeyReceiver->deleteLater(); delete ui; } @@ -153,35 +155,13 @@ void EditCommandDialog::on_keyCapture_toggled(bool checked) { ui->keyCapture->setFocus(); ui->keyCapture->setFocusPolicy(Qt::StrongFocus); + connect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), + this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); } else { - ui->keyCapture->setFocusPolicy(Qt::NoFocus); - ui->keyCapture->clearFocus(); - } -} - -void EditCommandDialog::keyPressEvent(QKeyEvent *e) -{ - if (ui->keyCapture->isChecked() && (!isComposeKey(static_cast(e->key())))) - { - m_key = static_cast(e->key()); - - if (e->modifiers()) - { - //qDebug("EditCommandDialog::keyPressEvent: has modifiers: %x", QFlags::Int(e->modifiers())); - m_keyModifiers = e->modifiers(); - } - else - { - m_keyModifiers = Qt::NoModifier; - } - - setKeyAssociate(); - setKeyLabel(); - //qDebug("EditCommandDialog::keyPressEvent: key: %x", m_key); - - ui->keyCapture->setChecked(false); + disconnect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), + this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); ui->keyCapture->setFocusPolicy(Qt::NoFocus); ui->keyCapture->clearFocus(); } @@ -213,12 +193,6 @@ void EditCommandDialog::fromCommand(const Command& command) ui->keyRelease->setChecked(command.getRelease()); } -bool EditCommandDialog::isComposeKey(Qt::Key key) -{ - auto it = std::find(m_composeKeys.begin(), m_composeKeys.end(), key); - return it != m_composeKeys.end(); -} - void EditCommandDialog::setKeyLabel() { if (m_key == 0) @@ -249,3 +223,13 @@ void EditCommandDialog::setKeyAssociate() ui->keyAssociate->setEnabled(true); } } + +void EditCommandDialog::commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release __attribute__((unused))) +{ +// qDebug("EditCommandDialog::commandKeyPressed: key: %x", m_key); +// qDebug("EditCommandDialog::commandKeyPressed: has modifiers: %x", QFlags::Int(keyModifiers)); + m_key = key; + m_keyModifiers = keyModifiers; + setKeyLabel(); + ui->keyCapture->setChecked(false); +} diff --git a/sdrgui/gui/editcommanddialog.h b/sdrgui/gui/editcommanddialog.h index 6f6184844..6861194fd 100644 --- a/sdrgui/gui/editcommanddialog.h +++ b/sdrgui/gui/editcommanddialog.h @@ -25,6 +25,7 @@ namespace Ui { } class Command; +class CommandKeyReceiver; class EditCommandDialog : public QDialog { Q_OBJECT @@ -56,18 +57,15 @@ private: Ui::EditCommandDialog* ui; Qt::Key m_key; Qt::KeyboardModifiers m_keyModifiers; + CommandKeyReceiver *m_commandKeyReceiver; - virtual void keyPressEvent(QKeyEvent *e); - bool isComposeKey(Qt::Key key); void setKeyLabel(); void setKeyAssociate(); - static const std::vector m_composeKeys; - private slots: void on_showFileDialog_clicked(bool checked); void on_keyCapture_toggled(bool checked); - + void commandKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifiers, bool release); };