Better handling of worked before and country name display

Appended text is  added at a fixed column unless  the message overlaps
in which case the appended information floats to thr right.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8109 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2017-09-22 22:08:56 +00:00
parent 7b0fd1fa54
commit ae5a1b7b1f

View File

@ -107,7 +107,7 @@ QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign
QColor color_NewCall) QColor color_NewCall)
{ {
// allow for seconds // allow for seconds
unsigned padding {message.indexOf (" ") > 4 ? 2U : 0U}; int padding {message.indexOf (" ") > 4 ? 2 : 0};
QString call = callsign; QString call = callsign;
QString countryName; QString countryName;
bool callWorkedBefore; bool callWorkedBefore;
@ -123,41 +123,27 @@ QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign
if(!call.contains(QRegExp("[0-9]|[A-Z]"))) return message; if(!call.contains(QRegExp("[0-9]|[A-Z]"))) return message;
logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore); logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore);
int charsAvail = 52 + padding;
// the decoder (seems) to always generate 41 chars. For a normal CQ message = message.trimmed ();
// call, the last five are spaces QString appendage;
//
// A maximum length call is "QRZ VP2X/GM4WJS IO91" "CQ AA ..." or CQ
// nnn ..." don't allow grid squares so are not longer. Here we align
// the added info at least after the longest CQ/QRZ message plus one
// space so that it can be stripped off algorithmically later.
//
int nmin = 46 + padding;
int s3 = message.indexOf (" ", nmin);
if (s3 < nmin) s3 = nmin; // always want at least the characters to position 45
s3 += 1; // convert the index into a character count
message = message.left(s3); // reduce trailing white space
charsAvail -= s3;
if (charsAvail > 4)
{
if (!countryWorkedBefore) // therefore not worked call either if (!countryWorkedBefore) // therefore not worked call either
{ {
message += "!"; appendage += "!";
*bg = color_DXCC; *bg = color_DXCC;
} }
else else
{
if (!callWorkedBefore) // but have worked the country if (!callWorkedBefore) // but have worked the country
{ {
message += "~"; appendage += "~";
*bg = color_NewCall; *bg = color_NewCall;
} }
else else
{ {
message += " "; // have worked this call before appendage += " "; // have worked this call before
*bg = color_CQ; *bg = color_CQ;
} }
charsAvail -= 1; }
// do some obvious abbreviations // do some obvious abbreviations
countryName.replace ("Islands", "Is."); countryName.replace ("Islands", "Is.");
@ -179,8 +165,18 @@ QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign
countryName.replace ("European", "EU"); countryName.replace ("European", "EU");
countryName.replace ("African", "AF"); countryName.replace ("African", "AF");
message += countryName; appendage += countryName;
// use a nbsp to save the start of appended text so we can find
// it again later, align appended data at a fixed column if
// there is space otherwise let it float to the right
int space_count {40 + padding - message.size ()};
if (space_count > 0)
{
message += QString {space_count, QChar {' '}};
} }
message += QChar::Nbsp + appendage;
return message; return message;
} }
@ -209,10 +205,15 @@ void DisplayText::displayDecodedText(DecodedText const& decodedText, QString con
// if enabled add the DXCC entity and B4 status to the end of the // if enabled add the DXCC entity and B4 status to the end of the
// preformated text line t1 // preformated text line t1
auto message = decodedText.string (); auto message = decodedText.string ();
int nbsp_position = message.indexOf (QChar::Nbsp);
if (nbsp_position >= 0)
{
message = message.left (nbsp_position);
}
if (displayDXCCEntity && CQcall) if (displayDXCCEntity && CQcall)
message = appendDXCCWorkedB4 (message, decodedText.CQersCall (), &bg, logBook, color_CQ, message = appendDXCCWorkedB4 (message, decodedText.CQersCall (), &bg, logBook, color_CQ,
color_DXCC, color_NewCall); color_DXCC, color_NewCall);
appendText (message, bg); appendText (message.trimmed (), bg);
} }