From 9f25842c79ab4512903f38148c8d261fb36f1ded Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Tue, 11 Sep 2018 13:35:29 -0400 Subject: [PATCH] Fixed message reply dialog to be non-modal --- CMakeLists.txt | 1 + keyeater.cpp | 29 +++++++++++++++++++++++++++++ keyeater.h | 33 +++++++++++++++++++++++++++++++++ mainwindow.cpp | 3 ++- mainwindow.h | 42 +----------------------------------------- messagereplydialog.cpp | 12 ++++++++++++ messagereplydialog.h | 1 + widegraph.cpp | 7 ++++++- widegraph.h | 1 + wsjtx.pro | 6 ++++-- 10 files changed, 90 insertions(+), 45 deletions(-) create mode 100644 keyeater.cpp create mode 100644 keyeater.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ab1ab58..dbe26e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,6 +306,7 @@ set (wsjtx_CXXSRCS varicode.cpp SelfDestructMessageBox.cpp messagereplydialog.cpp + keyeater.cpp APRSISClient.cpp mainwindow.cpp Configuration.cpp diff --git a/keyeater.cpp b/keyeater.cpp new file mode 100644 index 0000000..c7aefcc --- /dev/null +++ b/keyeater.cpp @@ -0,0 +1,29 @@ +#include "keyeater.h" + +bool EscapeKeyPressEater::eventFilter(QObject *obj, QEvent *event){ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->key() == Qt::Key_Escape){ + return true; + } + } + + // standard event processing + return QObject::eventFilter(obj, event); +} + +bool EnterKeyPressEater::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){ + bool processed = false; + emit this->enterKeyPressed(obj, keyEvent, &processed); + if(processed){ + return true; + } + } + } + + // standard event processing + return QObject::eventFilter(obj, event); +} diff --git a/keyeater.h b/keyeater.h new file mode 100644 index 0000000..9f96d79 --- /dev/null +++ b/keyeater.h @@ -0,0 +1,33 @@ +#ifndef KEYEATER_H +#define KEYEATER_H + +#include +#include + +class EscapeKeyPressEater : public QObject +{ + Q_OBJECT +public: + EscapeKeyPressEater(){} + virtual ~EscapeKeyPressEater(){} + +protected: + bool eventFilter(QObject *obj, QEvent *event); +}; + +class EnterKeyPressEater : public QObject +{ + Q_OBJECT +public: + EnterKeyPressEater(){} + virtual ~EnterKeyPressEater(){} + +protected: + bool eventFilter(QObject *obj, QEvent *event); + +public: + Q_SIGNAL void enterKeyPressed(QObject *obj, QKeyEvent *evt, bool *pProcessed); +}; + + +#endif // KEYEATER_H diff --git a/mainwindow.cpp b/mainwindow.cpp index ba06d79..36e8c71 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8182,7 +8182,7 @@ void MainWindow::setXIT(int n, Frequency base) void MainWindow::qsy(int hzDelta){ setRig(m_freqNominal + hzDelta); - setFreqOffsetForRestore(1500, false); + setFreqOffsetForRestore(m_wideGraph->centerFreq(), false); } void MainWindow::setFreqOffsetForRestore(int freq, bool shouldRestore){ @@ -9729,6 +9729,7 @@ void MainWindow::processAlertReplyForCommand(CommandDetail d, QString from, QStr QSound::play(wav); } + msgBox->setModal(false); msgBox->show(); } diff --git a/mainwindow.h b/mainwindow.h index a01a534..8d440a4 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -45,6 +45,7 @@ #include "varicode.h" #include "MessageClient.hpp" #include "APRSISClient.h" +#include "keyeater.h" #define NUM_JT4_SYMBOLS 206 //(72+31)*2, embedded sync #define NUM_JT65_SYMBOLS 126 //63 data + 63 sync @@ -932,47 +933,6 @@ private: void writeFoxQSO(QString msg); }; -class EscapeKeyPressEater : 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_Escape){ - return true; - } - } - - // standard event processing - return QObject::eventFilter(obj, event); - } -}; - -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){ - bool processed = false; - emit this->enterKeyPressed(obj, keyEvent, &processed); - if(processed){ - return true; - } - } - } - - // standard event processing - return QObject::eventFilter(obj, event); - } - -public: - Q_SIGNAL void enterKeyPressed(QObject *obj, QKeyEvent *evt, bool *pProcessed); -}; - extern int killbyname(const char* progName); extern void getDev(int* numDevices,char hostAPI_DeviceName[][50], int minChan[], int maxChan[], diff --git a/messagereplydialog.cpp b/messagereplydialog.cpp index fb82188..ff88ffc 100644 --- a/messagereplydialog.cpp +++ b/messagereplydialog.cpp @@ -10,6 +10,18 @@ MessageReplyDialog::MessageReplyDialog(QWidget *parent) : ui(new Ui::MessageReplyDialog) { ui->setupUi(this); + + auto enterFilter = new EnterKeyPressEater(); + connect(enterFilter, &EnterKeyPressEater::enterKeyPressed, this, [this](QObject *, QKeyEvent *, bool *pProcessed){ + if(QApplication::keyboardModifiers() & Qt::ShiftModifier){ + if(pProcessed) *pProcessed = false; + return; + } + if(pProcessed) *pProcessed = true; + + this->accept(); + }); + ui->textEdit->installEventFilter(enterFilter); } MessageReplyDialog::~MessageReplyDialog() diff --git a/messagereplydialog.h b/messagereplydialog.h index 3c0c31d..d973991 100644 --- a/messagereplydialog.h +++ b/messagereplydialog.h @@ -2,6 +2,7 @@ #define MESSAGEREPLYDIALOG_H #include +#include "keyeater.h" namespace Ui { class MessageReplyDialog; diff --git a/widegraph.cpp b/widegraph.cpp index 95e1bb1..baca29f 100644 --- a/widegraph.cpp +++ b/widegraph.cpp @@ -215,7 +215,7 @@ void WideGraph::on_bppSpinBox_valueChanged(int n) //b } void WideGraph::on_qsyPushButton_clicked(){ - int hzDelta = rxFreq() - ui->centerSpinBox->value(); + int hzDelta = rxFreq() - centerFreq(); emit qsy(hzDelta); } @@ -269,6 +269,11 @@ int WideGraph::rxFreq() //rxFr return ui->widePlot->rxFreq(); } +int WideGraph::centerFreq() +{ + return ui->centerSpinBox->value(); +} + int WideGraph::nStartFreq() //nStartFreq { return ui->widePlot->startFreq(); diff --git a/widegraph.h b/widegraph.h index 5e5f49e..023e48e 100644 --- a/widegraph.h +++ b/widegraph.h @@ -29,6 +29,7 @@ public: void dataSink2(float s[], float df3, int ihsym, int ndiskdata); void setRxFreq(int n); int rxFreq(); + int centerFreq(); int nStartFreq(); int Fmin(); int Fmax(); diff --git a/wsjtx.pro b/wsjtx.pro index c4e3907..7e008b3 100644 --- a/wsjtx.pro +++ b/wsjtx.pro @@ -73,7 +73,8 @@ SOURCES += \ MessageClient.cpp \ SelfDestructMessageBox.cpp \ APRSISClient.cpp \ - messagereplydialog.cpp + messagereplydialog.cpp \ + keyeater.cpp HEADERS += qt_helpers.hpp \ pimpl_h.hpp pimpl_impl.hpp \ @@ -98,7 +99,8 @@ HEADERS += qt_helpers.hpp \ MessageClient.hpp \ SelfDestructMessageBox.h \ APRSISClient.h \ - messagereplydialog.h + messagereplydialog.h \ + keyeater.h INCLUDEPATH += qmake_only