From 5b198351be22da231b1cc9e3403fa1feaf233efb Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Tue, 24 Jul 2018 17:45:23 -0400 Subject: [PATCH] Send message on enter key press --- mainwindow.cpp | 9 +++++++++ mainwindow.h | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index 926064d..96d1799 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1032,6 +1032,13 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, ui->spotButton->setChecked(m_config.spot_to_psk_reporter()); + auto enterFilter = new EnterKeyPressEater(); + connect(enterFilter, &EnterKeyPressEater::enterKeyPressed, this, [this](QKeyEvent *, QObject *){ + qDebug() << "the enter key was pressed"; + this->toggleTx(true); + }); + ui->extFreeTextMsgEdit->installEventFilter(enterFilter); + auto clearActionSep = new QAction(nullptr); clearActionSep->setSeparator(true); @@ -5489,6 +5496,8 @@ void MainWindow::resetMessageUI(){ ui->nextFreeTextMsg->clear(); ui->extFreeTextMsg->clear(); ui->extFreeTextMsgEdit->clear(); + ui->extFreeTextMsgEdit->setReadOnly(false); + update_dynamic_property (ui->extFreeTextMsgEdit, "transmitting", false); if(ui->startTxButton->isChecked()){ ui->startTxButton->setChecked(false); diff --git a/mainwindow.h b/mainwindow.h index d5a7653..1e61403 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -845,6 +845,27 @@ protected: } }; +class EnterKeyPressEater : public QObject +{ + Q_OBJECT +protected: + bool eventFilter(QObject *obj, QEvent *event){ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return){ + emit this->enterKeyPressed(keyEvent, obj); + return true; + } + } + + // standard event processing + return QObject::eventFilter(obj, event); + } + +public: + Q_SIGNAL void enterKeyPressed(QKeyEvent *evt, QObject *obj); +}; + extern int killbyname(const char* progName); extern void getDev(int* numDevices,char hostAPI_DeviceName[][50], int minChan[], int maxChan[],