Added warning message with a timeout for automatic band switching

This commit is contained in:
Jordan Sherer 2018-08-16 15:19:43 -04:00
parent ad4e567392
commit 6b4390fe5c
6 changed files with 136 additions and 11 deletions

View File

@ -304,6 +304,7 @@ set (wsjtx_CXXSRCS
messageaveraging.cpp messageaveraging.cpp
WsprTxScheduler.cpp WsprTxScheduler.cpp
varicode.cpp varicode.cpp
SelfDestructMessageBox.cpp
mainwindow.cpp mainwindow.cpp
Configuration.cpp Configuration.cpp
main.cpp main.cpp

View File

@ -0,0 +1,40 @@
#include "SelfDestructMessageBox.h"
SelfDestructMessageBox::SelfDestructMessageBox(
int timeout,
const QString& title,
const QString& text,
QMessageBox::Icon icon,
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton,
QWidget* parent,
Qt::WindowFlags flags)
: QMessageBox(icon, title, text, buttons, parent, flags),
m_timeout(timeout),
m_text(text)
{
connect(&m_timer, &QTimer::timeout, this, &SelfDestructMessageBox::tick);
m_timer.setInterval(1000);
setDefaultButton(defaultButton);
connect(this->defaultButton(), &QPushButton::clicked, this, &SelfDestructMessageBox::accept);
}
void SelfDestructMessageBox::showEvent(QShowEvent* event)
{
tick();
m_timer.start();
QMessageBox::showEvent(event);
}
void SelfDestructMessageBox::tick(){
m_timeout--;
if(m_timeout){
setText(m_text.arg(m_timeout));
return;
}
m_timer.stop();
accept();
}

35
SelfDestructMessageBox.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef SELFDESTRUCTMESSAGEBOX_H
#define SELFDESTRUCTMESSAGEBOX_H
#include <QWidget>
#include <QMessageBox>
#include <QPushButton>
#include <QString>
#include <QTimer>
class SelfDestructMessageBox : public QMessageBox
{
Q_OBJECT
public:
SelfDestructMessageBox(int timeout,
const QString& title,
const QString& text,
QMessageBox::Icon icon,
QMessageBox::StandardButtons buttons = QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::StandardButton defaultButton = QMessageBox::Ok,
QWidget* parent = nullptr,
Qt::WindowFlags flags = 0);
void showEvent(QShowEvent* event) override;
private slots:
void tick();
private:
int m_timeout;
QString m_text;
QTimer m_timer;
};
#endif // SELFDESTRUCTMESSAGEBOX_H

View File

@ -58,6 +58,7 @@
#include "MaidenheadLocatorValidator.hpp" #include "MaidenheadLocatorValidator.hpp"
#include "CallsignValidator.hpp" #include "CallsignValidator.hpp"
#include "EqualizationToolsDialog.hpp" #include "EqualizationToolsDialog.hpp"
#include "SelfDestructMessageBox.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "moc_mainwindow.cpp" #include "moc_mainwindow.cpp"
@ -1336,6 +1337,11 @@ void MainWindow::tryBandHop(){
return; return;
} }
// make sure we're not transmitting
if(isMessageQueuedForTransmit()){
return;
}
// get the current band // get the current band
auto dialFreq = dialFrequency(); auto dialFreq = dialFrequency();
@ -1382,21 +1388,43 @@ void MainWindow::tryBandHop(){
freqIsDifferent freqIsDifferent
); );
//qDebug() << "Can switch to" << station.band_name_ << "=" << canSwitch << station.switch_at_.time().toString("hh:mm") << "<=" << d.time().toString("hh:mm") << "<=" << station.switch_until_.time().toString("hh:mm") << m_bandHopped << m_bandHoppedFreq;
// switch, if we can and the band is different than our current band // switch, if we can and the band is different than our current band
if(canSwitch){ if(canSwitch){
Frequency frequency = station.frequency_;
qDebug() << "Automatic band hop from" << currentBand << "to" << station.band_name_ << "at" << Radio::frequency_MHz_string(station.frequency_); m_bandHopped = false;
m_bandHoppedFreq = frequency;
// cache the frequency set by bandHop... SelfDestructMessageBox * m = new SelfDestructMessageBox(30,
m_bandHopped = true; "Scheduled Frequency Change",
m_bandHoppedFreq = station.frequency_; QString("A scheduled frequency change has arrived. The rig frequency will be changed to %1 MHz in %2 second(s).").arg(Radio::frequency_MHz_string(station.frequency_)),
QMessageBox::Information,
QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Ok,
this);
// TODO: jsherer - is this the right way to switch the rig freq? connect(m, &SelfDestructMessageBox::accepted, this, [this, frequency](){
setRig(station.frequency_); m_bandHopped = true;
setRig(frequency);
});
break; m->show();
#if 0
// TODO: jsherer - this is totally a hack because of the signal that gets emitted to clearActivity on band change...
QTimer *t = new QTimer(this);
t->setInterval(250);
t->setSingleShot(true);
connect(t, &QTimer::timeout, this, [this, station, dialFreq](){
auto message = QString("Scheduled frequency switch from %1 MHz to %2 MHz");
message = message.arg(Radio::frequency_MHz_string(dialFreq));
message = message.arg(Radio::frequency_MHz_string(station.frequency_));
writeNoticeTextToUI(QDateTime::currentDateTimeUtc(), message);
});
t->start();
#endif
return;
} }
} }
} }
@ -5705,6 +5733,24 @@ void MainWindow::displayTextForFreq(QString text, int freq, QDateTime date, bool
} }
} }
void MainWindow::writeNoticeTextToUI(QDateTime date, QString text){
auto c = ui->textEditRX->textCursor();
c.movePosition(QTextCursor::End);
if(c.block().length() > 1){
c.insertBlock();
}
text = text.toHtmlEscaped();
c.insertBlock();
c.insertHtml(QString("<strong>%1 - %2</strong>").arg(date.time().toString()).arg(text));
c.movePosition(QTextCursor::End);
ui->textEditRX->ensureCursorVisible();
ui->textEditRX->verticalScrollBar()->setValue(ui->textEditRX->verticalScrollBar()->maximum());
}
int MainWindow::writeMessageTextToUI(QDateTime date, QString text, int freq, bool bold, int block){ int MainWindow::writeMessageTextToUI(QDateTime date, QString text, int freq, bool bold, int block){
auto c = ui->textEditRX->textCursor(); auto c = ui->textEditRX->textCursor();

View File

@ -134,6 +134,7 @@ public slots:
QString lookupCallInCompoundCache(QString const &call); QString lookupCallInCompoundCache(QString const &call);
void clearActivity(); void clearActivity();
void displayTextForFreq(QString text, int freq, QDateTime date, bool isTx, bool isNewLine, bool isLast); void displayTextForFreq(QString text, int freq, QDateTime date, bool isTx, bool isNewLine, bool isLast);
void writeNoticeTextToUI(QDateTime date, QString text);
int writeMessageTextToUI(QDateTime date, QString text, int freq, bool bold, int block=-1); int writeMessageTextToUI(QDateTime date, QString text, int freq, bool bold, int block=-1);
bool isMessageQueuedForTransmit(); bool isMessageQueuedForTransmit();
void addMessageText(QString text, bool clear=false); void addMessageText(QString text, bool clear=false);

View File

@ -70,7 +70,8 @@ SOURCES += \
EqualizationToolsDialog.cpp \ EqualizationToolsDialog.cpp \
varicode.cpp \ varicode.cpp \
NetworkMessage.cpp \ NetworkMessage.cpp \
MessageClient.cpp MessageClient.cpp \
SelfDestructMessageBox.cpp
HEADERS += qt_helpers.hpp \ HEADERS += qt_helpers.hpp \
pimpl_h.hpp pimpl_impl.hpp \ pimpl_h.hpp pimpl_impl.hpp \
@ -92,7 +93,8 @@ HEADERS += qt_helpers.hpp \
qpriorityqueue.h \ qpriorityqueue.h \
crc.h \ crc.h \
NetworkMessage.hpp \ NetworkMessage.hpp \
MessageClient.hpp MessageClient.hpp \
SelfDestructMessageBox.h
INCLUDEPATH += qmake_only INCLUDEPATH += qmake_only