diff --git a/mainwindow.cpp b/mainwindow.cpp index 0a626e0..39ad5df 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8716,6 +8716,12 @@ void MainWindow::updateButtonDisplay(){ bool isTransmitting = m_transmitting || m_txFrameCount > 0; auto selectedCallsign = callsignSelected(true); bool emptyCallsign = selectedCallsign.isEmpty(); + bool hasText = !ui->extFreeTextMsgEdit->toPlainText().isEmpty(); + + // update the estimate immediately if we know that the text box is empty... + if(!hasText){ + updateFrameCountEstimate(0); + } ui->cqMacroButton->setDisabled(isTransmitting); ui->replyMacroButton->setDisabled(isTransmitting || emptyCallsign); @@ -8731,20 +8737,24 @@ void MainWindow::updateButtonDisplay(){ int count = m_txFrameCount; int sent = count - m_txFrameQueue.count(); ui->startTxButton->setText(m_tune ? "Tuning" : QString("Sending (%1/%2)").arg(sent).arg(count)); - } else if(m_txTextDirty && (m_txTextDirtyLastText != ui->extFreeTextMsgEdit->toPlainText() || m_txTextDirtyLastSelectedCall != selectedCallsign)){ + } else { + ui->startTxButton->setText(m_txFrameCountEstimate <= 0 ? QString("Send") : QString("Send (%1)").arg(m_txFrameCountEstimate)); + ui->startTxButton->setEnabled(m_txFrameCountEstimate > 0 && ensureSelcalCallsignSelected(false)); + } + + + // schedule count update + if(hasText && m_txTextDirty && (m_txTextDirtyLastText != ui->extFreeTextMsgEdit->toPlainText() || m_txTextDirtyLastSelectedCall != selectedCallsign)){ if(m_txTextDirtyDebounce.isActive()){ m_txTextDirtyDebounce.stop(); } m_txTextDirtyDebounce.start(100); m_txTextDirty = false; - } } void MainWindow::buildMessageFramesAndUpdateCountDisplay(){ - qDebug() << "buildMessageFramesAndUpdateCountDisplay"; - auto text = ui->extFreeTextMsgEdit->toPlainText(); m_txTextDirtyLastText = text; @@ -8780,26 +8790,26 @@ void MainWindow::buildMessageFramesAndUpdateCountDisplay(){ text.append(dt.message()); } - updateFrameCountDisplay(text.join(""), frames.length()); + updateFrameCountEstimate(frames.length()); + updateTextStatsDisplay(text.join(""), frames.length()); }); t->start(); #endif } -void MainWindow::updateFrameCountDisplay(QString text, int count){ - if(count > 0){ - ui->startTxButton->setText(QString("Send (%1)").arg(count)); - ui->startTxButton->setEnabled(ensureSelcalCallsignSelected(false)); +void MainWindow::updateFrameCountEstimate(int count){ + m_txFrameCountEstimate = count; +} +void MainWindow::updateTextStatsDisplay(QString text, int count){ + if(count > 0){ auto words = text.split(" ", QString::SkipEmptyParts).length(); auto wpm = QString::number(words/(count/4.0), 'f', 1); auto cpm = QString::number(text.length()/(count/4.0), 'f', 1); wpm_label.setText(QString("%1wpm / %2cpm").arg(wpm).arg(cpm)); wpm_label.setVisible(true); } else { - ui->startTxButton->setText("Send"); - ui->startTxButton->setEnabled(false); wpm_label.setVisible(false); wpm_label.clear(); } diff --git a/mainwindow.h b/mainwindow.h index 872f82e..480f30e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -728,6 +728,7 @@ private: bool m_rxDirty; bool m_rxDisplayDirty; + int m_txFrameCountEstimate; int m_txFrameCount; QTimer m_txTextDirtyDebounce; bool m_txTextDirty; @@ -882,7 +883,8 @@ private: void postDecode (bool is_new, QString const& message); void displayTransmit(); void updateButtonDisplay(); - void updateFrameCountDisplay(QString text, int count); + void updateFrameCountEstimate(int count); + void updateTextStatsDisplay(QString text, int count); bool isMyCallIncluded(QString const &text); bool isAllCallIncluded(QString const &text); QString callsignSelected(bool useInputText=false);