Add button to the decoded text window context menu to erase the contents

Right-click  either decoded  text window  to erase  its contents.  The
"Erase" button on the main UI  still operates as before although it is
implemented differently now.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8090 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2017-09-16 20:27:33 +00:00
parent 1e4845cdfd
commit e7be718b8d
4 changed files with 44 additions and 12 deletions

View File

@ -5,18 +5,39 @@
#include <QTextCharFormat>
#include <QTextCursor>
#include <QTextBlock>
#include <QMenu>
#include <QAction>
#include "qt_helpers.hpp"
#include "moc_displaytext.cpp"
DisplayText::DisplayText(QWidget *parent) :
QTextEdit(parent)
DisplayText::DisplayText(QWidget *parent)
: QTextEdit(parent)
, erase_action_ {new QAction {tr ("&Erase"), this}}
{
setReadOnly (true);
viewport ()->setCursor (Qt::ArrowCursor);
setWordWrapMode (QTextOption::NoWrap);
document ()->setMaximumBlockCount (5000); // max lines to limit heap usage
// max lines to limit heap usage
document ()->setMaximumBlockCount (5000);
// context menu erase action
setContextMenuPolicy (Qt::CustomContextMenu);
connect (this, &DisplayText::customContextMenuRequested, [this] (QPoint const& position) {
auto * menu = createStandardContextMenu (position);
menu->addAction (erase_action_);
menu->exec (mapToGlobal (position));
delete menu;
});
connect (erase_action_, &QAction::triggered, this, &DisplayText::erase);
}
void DisplayText::erase ()
{
clear ();
Q_EMIT erased ();
}
void DisplayText::setContentFont(QFont const& font)

View File

@ -8,6 +8,8 @@
#include "logbook/logbook.h"
#include "decodedtext.h"
class QAction;
class DisplayText
: public QTextEdit
{
@ -25,8 +27,10 @@ public:
void displayQSY(QString text);
Q_SIGNAL void selectCallsign (bool alt, bool ctrl);
Q_SIGNAL void erased ();
Q_SLOT void appendText (QString const& text, QColor bg = Qt::white);
Q_SLOT void erase ();
protected:
void mouseDoubleClickEvent(QMouseEvent *e);
@ -36,6 +40,7 @@ private:
QColor color_CQ, QColor color_DXCC, QColor color_NewCall);
QFont char_font_;
QAction * erase_action_;
};
#endif // DISPLAYTEXT_H

View File

@ -550,6 +550,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
SLOT(doubleClickOnCall(bool,bool)));
connect(ui->decodedTextBrowser,SIGNAL(selectCallsign(bool,bool)),this,
SLOT(doubleClickOnCall2(bool,bool)));
connect (ui->decodedTextBrowser2, &DisplayText::erased, this, &MainWindow::rx_frequency_activity_cleared);
// initialize decoded text font and hook up font change signals
// defer initialization until after construction otherwise menu
@ -2897,23 +2898,27 @@ void MainWindow::killFile ()
}
}
void MainWindow::on_EraseButton_clicked() //Erase
void MainWindow::on_EraseButton_clicked ()
{
qint64 ms=QDateTime::currentMSecsSinceEpoch();
ui->decodedTextBrowser2->clear();
ui->decodedTextBrowser2->erase ();
if(m_mode.startsWith ("WSPR") or m_mode=="Echo" or m_mode=="ISCAT") {
ui->decodedTextBrowser->clear();
ui->decodedTextBrowser->erase ();
} else {
m_QSOText.clear();
if((ms-m_msErase)<500) {
ui->decodedTextBrowser->clear();
m_messageClient->clear_decodes ();
QFile f(m_config.temp_dir ().absoluteFilePath ("decoded.txt"));
if(f.exists()) f.remove();
ui->decodedTextBrowser->erase ();
}
}
m_msErase=ms;
set_dateTimeQSO(-1);
}
void MainWindow::rx_frequency_activity_cleared ()
{
m_QSOText.clear();
m_messageClient->clear_decodes ();
QFile f(m_config.temp_dir ().absoluteFilePath ("decoded.txt"));
if(f.exists()) f.remove();
set_dateTimeQSO(-1); // G4WJS: why do we do this?
}
void MainWindow::decodeBusy(bool b) //decodeBusy()

View File

@ -153,6 +153,7 @@ private slots:
void decode();
void decodeBusy(bool b);
void on_EraseButton_clicked();
void rx_frequency_activity_cleared ();
void on_txFirstCheckBox_stateChanged(int arg1);
void set_dateTimeQSO(int m_ntx);
void set_ntx(int n);