From 38ddf114797539b2e6298b29da441455a3847776 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sun, 9 Sep 2018 10:04:19 -0400 Subject: [PATCH] Added a custom reply dialog box so we can customize the text input validator (upper case text only) --- CMakeLists.txt | 2 ++ mainwindow.cpp | 22 ++++++------- messagereplydialog.cpp | 52 +++++++++++++++++++++++++++++ messagereplydialog.h | 34 +++++++++++++++++++ messagereplydialog.ui | 74 ++++++++++++++++++++++++++++++++++++++++++ wsjtx.pro | 9 +++-- 6 files changed, 179 insertions(+), 14 deletions(-) create mode 100644 messagereplydialog.cpp create mode 100644 messagereplydialog.h create mode 100644 messagereplydialog.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index a5812dc..1fc67ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,6 +305,7 @@ set (wsjtx_CXXSRCS WsprTxScheduler.cpp varicode.cpp SelfDestructMessageBox.cpp + messagereplydialog.cpp APRSISClient.cpp mainwindow.cpp Configuration.cpp @@ -668,6 +669,7 @@ set (wsjtx_UISRCS widegraph.ui logqso.ui Configuration.ui + messagereplydialog.ui ) set (UDP_library_CXXSRCS diff --git a/mainwindow.cpp b/mainwindow.cpp index 3ef5f18..49ba510 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -63,6 +62,7 @@ #include "CallsignValidator.hpp" #include "EqualizationToolsDialog.hpp" #include "SelfDestructMessageBox.h" +#include "messagereplydialog.h" #include "ui_mainwindow.h" #include "moc_mainwindow.cpp" @@ -6126,9 +6126,6 @@ void MainWindow::on_extFreeTextMsgEdit_currentTextChanged (QString const& text) ui->startTxButton->setText("Send"); ui->startTxButton->setEnabled(false); } - - - } int MainWindow::currentFreqOffset(){ @@ -9588,7 +9585,7 @@ void MainWindow::processAlertReplyForCommand(CommandDetail d, QString from, QStr auto rb = msgBox->addButton("Reply", QMessageBox::AcceptRole); auto db = msgBox->addButton("Discard", QMessageBox::NoRole); - connect(msgBox, & QMessageBox::buttonClicked, this, [this, cmd, from, d, db, rb, ab](QAbstractButton * btn) { + connect(msgBox, &QMessageBox::buttonClicked, this, [this, cmd, from, d, db, rb, ab](QAbstractButton * btn) { if (btn == db) { return; } @@ -9598,13 +9595,16 @@ void MainWindow::processAlertReplyForCommand(CommandDetail d, QString from, QStr } if(btn == rb){ - bool ok = false; - QString text = QInputDialog::getMultiLineText(this, "Message Reply", QString("Message to send to %1:").arg(from), "", &ok); - if(ok && !text.isEmpty()){ - enqueueMessage(PriorityHigh, QString("%1%2%3").arg(from).arg(cmd).arg(text), d.freq, nullptr); - } - } + auto diag = new MessageReplyDialog(this); + diag->setWindowTitle("Message Reply"); + diag->setLabel(QString("Message to send to %1:").arg(from)); + connect(diag, &MessageReplyDialog::accepted, this, [this, diag, from, cmd, d](){ + enqueueMessage(PriorityHigh, QString("%1%2%3").arg(from).arg(cmd).arg(diag->textValue()), d.freq, nullptr); + }); + + diag->show(); + } }); auto wav = m_config.sound_am_path(); diff --git a/messagereplydialog.cpp b/messagereplydialog.cpp new file mode 100644 index 0000000..34c9e6c --- /dev/null +++ b/messagereplydialog.cpp @@ -0,0 +1,52 @@ +#include "messagereplydialog.h" +#include "ui_messagereplydialog.h" + +#include "varicode.h" + +MessageReplyDialog::MessageReplyDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::MessageReplyDialog) +{ + ui->setupUi(this); +} + +MessageReplyDialog::~MessageReplyDialog() +{ + delete ui; +} + +void MessageReplyDialog::setLabel(QString value){ + ui->label->setText(value); +} + +void MessageReplyDialog::setTextValue(QString text){ + ui->textEdit->setPlainText(text); +} + +QString MessageReplyDialog::textValue() const { + return ui->textEdit->toPlainText(); +} + +void MessageReplyDialog::on_textEdit_textChanged(){ + auto text = ui->textEdit->toPlainText(); + + QString x; + QString::const_iterator i; + auto validChars = Varicode::huffValidChars(); + for(i = text.constBegin(); i != text.constEnd(); i++){ + auto ch = (*i).toUpper(); + if(validChars.contains(ch)){ + x += ch; + } + } + + if(x != text){ + int pos = ui->textEdit->textCursor().position(); + int maxpos = x.size(); + ui->textEdit->setPlainText(x); + QTextCursor c = ui->textEdit->textCursor(); + c.setPosition(pos < maxpos ? pos : maxpos, QTextCursor::MoveAnchor); + + ui->textEdit->setTextCursor(c); + } +} diff --git a/messagereplydialog.h b/messagereplydialog.h new file mode 100644 index 0000000..3c0c31d --- /dev/null +++ b/messagereplydialog.h @@ -0,0 +1,34 @@ +#ifndef MESSAGEREPLYDIALOG_H +#define MESSAGEREPLYDIALOG_H + +#include + +namespace Ui { +class MessageReplyDialog; +} + +class QTextEdit; + +class MessageReplyDialog : public QDialog +{ + Q_OBJECT + +public: + explicit MessageReplyDialog(QWidget *parent = 0); + ~MessageReplyDialog(); + + void setLabel(QString); + void setTextValue(QString); + QString textValue() const; + + QTextEdit * textEdit(); + + +private slots: + void on_textEdit_textChanged(); + +private: + Ui::MessageReplyDialog *ui; +}; + +#endif // MESSAGEREPLAYDIALOG_H diff --git a/messagereplydialog.ui b/messagereplydialog.ui new file mode 100644 index 0000000..0fbbc86 --- /dev/null +++ b/messagereplydialog.ui @@ -0,0 +1,74 @@ + + + MessageReplyDialog + + + + 0 + 0 + 520 + 260 + + + + Dialog + + + + + + TextLabel + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + MessageReplyDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MessageReplyDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/wsjtx.pro b/wsjtx.pro index f070f20..c4e3907 100644 --- a/wsjtx.pro +++ b/wsjtx.pro @@ -72,7 +72,8 @@ SOURCES += \ NetworkMessage.cpp \ MessageClient.cpp \ SelfDestructMessageBox.cpp \ - APRSISClient.cpp + APRSISClient.cpp \ + messagereplydialog.cpp HEADERS += qt_helpers.hpp \ pimpl_h.hpp pimpl_impl.hpp \ @@ -96,7 +97,8 @@ HEADERS += qt_helpers.hpp \ NetworkMessage.hpp \ MessageClient.hpp \ SelfDestructMessageBox.h \ - APRSISClient.h + APRSISClient.h \ + messagereplydialog.h INCLUDEPATH += qmake_only @@ -108,7 +110,8 @@ HEADERS += OmniRigTransceiver.hpp FORMS += mainwindow.ui about.ui Configuration.ui widegraph.ui astro.ui \ logqso.ui wf_palette_design_dialog.ui messageaveraging.ui echograph.ui \ - fastgraph.ui + fastgraph.ui \ + messagereplydialog.ui RC_FILE = wsjtx.rc RESOURCES = wsjtx.qrc