1. Only the left 'band activity' display has DXCC and worked B4 status

2. Moved some of the text handling code from MainWindow to Displaytext


git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3550 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Murray Curtis 2013-08-15 12:24:12 +00:00
parent 4e17c5ffaa
commit 4bade4865d
6 changed files with 136 additions and 100 deletions

View File

@ -32,3 +32,92 @@ void DisplayText::resizeEvent(QResizeEvent * event)
_maxDisplayedCharacters = width()/_fontWidth; _maxDisplayedCharacters = width()/_fontWidth;
QTextBrowser::resizeEvent(event); QTextBrowser::resizeEvent(event);
} }
void DisplayText::insertLineSpacer()
{
QTextCursor cursor;
QTextBlockFormat bf;
QString bg="#d3d3d3";
bf.setBackground(QBrush(QColor(bg)));
QString tt="----------------------------------------";
QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
bg + "\"><pre>" + tt + "</pre></td></tr></table>";
cursor = this->textCursor();
cursor.movePosition(QTextCursor::End);
bf = cursor.blockFormat();
bf.setBackground(QBrush(QColor(bg)));
cursor.insertHtml(s);
}
void DisplayText::_appendDXCCWorkedB4(/*mod*/QString& t1, QString& bg, /*uses*/LogBook logBook)
{
// extract the CQer's call TODO: does this work with all call formats? What about 'CQ DX'?
int s1 = 4 + t1.indexOf(" CQ ");
int s2 = t1.indexOf(" ",s1);
QString call = t1.mid(s1,s2-s1);
QString countryName;
bool callWorkedBefore;
bool countryWorkedBefore;
logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore);
int charsAvail = _maxDisplayedCharacters;
// the decoder (seems) to always generate 40 chars. For a normal CQ call, the last five are spaces
t1 = t1.left(36); // reduce trailing white space TODO this magic 36 is also referenced in MainWindow::doubleClickOnCall()
charsAvail -= 36;
if (charsAvail > 4)
{
if (!countryWorkedBefore) // therefore not worked call either
{
t1 += "!";
bg = "#66ff66"; // strong green
}
else
if (!callWorkedBefore) // but have worked the country
{
t1 += "~";
bg = "#76cd76"; // mid green
}
else
{
t1 += " "; // have worked this call before
bg="#9cc79c"; // pale green
}
charsAvail -= 1;
if (countryName.length()>charsAvail)
countryName = countryName.left(1)+"."+countryName.right(charsAvail-2); //abreviate the first word to the first letter, show remaining right most chars
t1 += countryName;
}
}
void DisplayText::displayDecodedText(QString decodedText, QString myCall, bool displayDXCCEntity, LogBook logBook)
{
QString bg="white";
bool CQcall = false;
if (decodedText.indexOf(" CQ ") > 0)
{
CQcall = true;
bg="#66ff66"; //green
}
if (myCall != "" and decodedText.indexOf(" " + myCall + " ") > 0)
bg="#ff6666"; //red
// if enabled add the DXCC entity and B4 status to the end of the preformated text line t1
if (displayDXCCEntity && CQcall)
_appendDXCCWorkedB4(/*mod*/decodedText,bg,logBook);
QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
bg + "\"><pre>" + decodedText + "</pre></td></tr></table>";
QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::End);
QTextBlockFormat bf = cursor.blockFormat();
bf.setBackground(QBrush(QColor(bg)));
cursor.insertHtml(s);
this->setTextCursor(cursor);
}

View File

@ -2,30 +2,33 @@
#define DISPLAYTEXT_H #define DISPLAYTEXT_H
#include <QTextBrowser> #include <QTextBrowser>
#include "logbook/logbook.h"
class DisplayText : public QTextBrowser class DisplayText : public QTextBrowser
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DisplayText(QWidget *parent = 0); explicit DisplayText(QWidget *parent = 0);
void setFont(QFont font); void setFont(QFont font);
int getMaxDisplayedCharacters() { return _maxDisplayedCharacters; }
void insertLineSpacer();
void displayDecodedText(QString decodedText, QString myCall, bool displayDXCCEntity, LogBook logBook);
signals: signals:
void selectCallsign(bool shift, bool ctrl); void selectCallsign(bool shift, bool ctrl);
public slots: public slots:
protected: protected:
void mouseDoubleClickEvent(QMouseEvent *e); void mouseDoubleClickEvent(QMouseEvent *e);
void resizeEvent(QResizeEvent * event); void resizeEvent(QResizeEvent * event);
private: private:
int _fontWidth; int _fontWidth;
int _maxDisplayedCharacters; int _maxDisplayedCharacters;
void _appendDXCCWorkedB4(/*mod*/QString& t1, QString &bg, LogBook logBook);
}; };

View File

@ -117,16 +117,17 @@ void CountryDat::load()
} }
// return country name else "" // return country name else ""
QString CountryDat::find(QString prefix) QString CountryDat::find(const QString prefix)
{ {
while(prefix.length() >= 1) QString pf = prefix.toUpper();
while(pf.length() >= 1)
{ {
if (_data.contains(prefix)) if (_data.contains(pf))
{ {
QString country = _data.value(prefix); QString country = _data.value(pf);
return country; return country;
} }
prefix = prefix.left(prefix.length()-1); pf = pf.left(pf.length()-1);
} }
return ""; return "";
} }

View File

@ -19,7 +19,7 @@ class CountryDat
public: public:
void init(const QString filename); void init(const QString filename);
void load(); void load();
QString find(QString prefix); // return country name or "" QString find(const QString prefix); // return country name or ""
QStringList getCountryNames() { return _countryNames; }; QStringList getCountryNames() { return _countryNames; };
private: private:

View File

@ -23,6 +23,13 @@ void LogBook::init()
int count = _worked.getWorkedCount(); int count = _worked.getWorkedCount();
qDebug() << QSOcount << "QSOs and" << count << "countries worked in file" << logFilename; qDebug() << QSOcount << "QSOs and" << count << "countries worked in file" << logFilename;
*/ */
// QString call = "ok1ct";
// QString countryName;
// bool callWorkedBefore,countryWorkedBefore;
// match(/*in*/call, /*out*/ countryName,callWorkedBefore,countryWorkedBefore);
// qDebug() << countryName;
} }

View File

@ -1406,100 +1406,30 @@ void MainWindow::readFromStdout() //readFromStdout
out << t.mid(0,n-2) << endl; out << t.mid(0,n-2) << endl;
f.close(); f.close();
QTextCursor cursor;
QTextBlockFormat bf; if(m_insertBlank and m_blankLine and jt9com_.nagain==0)
if(m_insertBlank and m_blankLine and jt9com_.nagain==0) { {
QString bg="#d3d3d3"; ui->decodedTextBrowser->insertLineSpacer();
bf.setBackground(QBrush(QColor(bg))); m_blankLine=false;
QString tt="----------------------------------------";
QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
bg + "\"><pre>" + tt + "</pre></td></tr></table>";
cursor = ui->decodedTextBrowser->textCursor();
cursor.movePosition(QTextCursor::End);
bf = cursor.blockFormat();
bf.setBackground(QBrush(QColor(bg)));
cursor.insertHtml(s);
m_blankLine=false;
} }
QString bg="white";
if(t.indexOf(" CQ ")>0) bg="#66ff66"; //green
if(m_myCall!="" and t.indexOf(" "+m_myCall+" ")>0) bg="#ff6666"; //red
bool bQSO=abs(t.mid(14,4).toInt() - m_wideGraph->rxFreq()) <= 10;
QString t1=t.replace("\n","").mid(0,t.length()-4); QString t1=t.replace("\n","").mid(0,t.length()-4);
// if enabled add the DXCC entity and B4 status to the end of the preformated text line t1 // the left band display
int cqi = t.indexOf(" CQ "); ui->decodedTextBrowser->displayDecodedText(t1,m_myCall,m_displayDXCCEntity,m_logBook);
if (m_displayDXCCEntity && (cqi >= 0))
if (abs(t1.mid(14,4).toInt() - m_wideGraph->rxFreq()) <= 10) // this msg is within 10 hertz of our tuned frequency
{ {
// extract the CQer's call TODO: does this work with all call formats? What about 'CQ DX'? // the right QSO window
int s1 = 4 + t.indexOf(" CQ "); ui->decodedTextBrowser2->displayDecodedText(t1,m_myCall,false,m_logBook);
int s2 = t.indexOf(" ",s1);
QString call = t.mid(s1,s2-s1);
QString countryName;
bool callWorkedBefore;
bool countryWorkedBefore;
m_logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore);
int charsAvail = ui->decodedTextBrowser->getMaxDisplayedCharacters(); bool b65=t1.indexOf("#")==19;
if(b65 and m_modeTx!="JT65") on_pbTxMode_clicked();
// the decoder (seems) to always generate 40 chars. For a normal CQ call, the last five are spaces if(!b65 and m_modeTx=="JT65") on_pbTxMode_clicked();
t1 = t1.left(36); // reduce trailing white space m_QSOmsg=t1;
charsAvail -= 36;
if (charsAvail > 4)
{
if (!countryWorkedBefore) // therefore not worked call either
{
t1 += "!";
bg = "#66ff66"; // strong green
}
else
if (!callWorkedBefore) // but have worked the country
{
t1 += "~";
bg = "#76cd76"; // mid green
}
else
{
t1 += " "; // have worked this call before
bg="#9cc79c"; // pale green
}
charsAvail -= 1;
if (countryName.length()>charsAvail)
countryName = countryName.left(1)+"."+countryName.right(charsAvail-2); //abreviate the first word to the first letter, show remaining right most chars
t1 += countryName;
}
}
QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
bg + "\"><pre>" + t1 + "</pre></td></tr></table>";
bool b65=t1.indexOf("#")==19;
if(bQSO) {
cursor = ui->decodedTextBrowser2->textCursor();
cursor.movePosition(QTextCursor::End);
bf = cursor.blockFormat();
bf.setBackground(QBrush(QColor(bg)));
cursor.insertHtml(s);
ui->decodedTextBrowser2->setTextCursor(cursor);
m_QSOmsg=t1;
if(b65 and m_modeTx!="JT65") on_pbTxMode_clicked();
if(!b65 and m_modeTx=="JT65") on_pbTxMode_clicked();
}
if(jt9com_.nagain==0) {
if(m_myCall!="" and t.indexOf(" "+m_myCall+" ")>0) bg="#ff6666"; //red
QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
bg + "\"><pre>" + t1 + "</pre></td></tr></table>";
cursor = ui->decodedTextBrowser->textCursor();
cursor.movePosition(QTextCursor::End);
bf = cursor.blockFormat();
bf.setBackground(QBrush(QColor(bg)));
cursor.insertHtml(s);
ui->decodedTextBrowser->setTextCursor(cursor);
} }
// find and extract any report
QString msg=t.mid(21); QString msg=t.mid(21);
int i1=msg.indexOf("\r"); int i1=msg.indexOf("\r");
if(i1>0) msg=msg.mid(0,i1-1) + " "; if(i1>0) msg=msg.mid(0,i1-1) + " ";
@ -1522,9 +1452,11 @@ void MainWindow::readFromStdout() //readFromStdout
} }
} }
// extract details and send to PSKreporter
int nsec=QDateTime::currentMSecsSinceEpoch()/1000-m_secBandChanged; int nsec=QDateTime::currentMSecsSinceEpoch()/1000-m_secBandChanged;
bool okToPost=(nsec>50); bool okToPost=(nsec>50);
QString msgmode="JT9"; QString msgmode="JT9";
bool b65=t1.indexOf("#")==19;
if(b65) msgmode="JT65"; if(b65) msgmode="JT65";
i1=msg.indexOf(" "); i1=msg.indexOf(" ");
QString c2=msg.mid(i1+1); QString c2=msg.mid(i1+1);
@ -2021,6 +1953,10 @@ void MainWindow::doubleClickOnCall(bool shift, bool ctrl)
QString t1 = t.mid(0,i2); //contents up to \n on selected line QString t1 = t.mid(0,i2); //contents up to \n on selected line
int i1=t1.lastIndexOf("\n") + 1; //points to first char of line int i1=t1.lastIndexOf("\n") + 1; //points to first char of line
QString t2 = t1.mid(i1,i2-i1); //selected line QString t2 = t1.mid(i1,i2-i1); //selected line
if (t2.indexOf(" CQ ") > 0)
t2 = t2.left(36); // to remove DXCC entity and worked B4 status. TODO need a better way to do this
// if(t2.indexOf("Tx")==6) return; //Ignore Tx line // if(t2.indexOf("Tx")==6) return; //Ignore Tx line
int i4=t.mid(i1).length(); int i4=t.mid(i1).length();
if(i4>55) i4=55; if(i4>55) i4=55;