From b4aebf2d137b892f53503b13785ecae900062ff7 Mon Sep 17 00:00:00 2001 From: Enrico Rossi Date: Sat, 3 Nov 2018 17:52:26 +0100 Subject: New upstream version 1.9.1+repack * Drop local hamlib copy (commit d1b545be). * Drop local boost copy (1.63.0). --- displaytext.cpp | 216 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 191 insertions(+), 25 deletions(-) (limited to 'displaytext.cpp') diff --git a/displaytext.cpp b/displaytext.cpp index 989e206b..a31cf9bc 100644 --- a/displaytext.cpp +++ b/displaytext.cpp @@ -1,5 +1,5 @@ #include "displaytext.h" - +#include "mainwindow.h" #include #include #include @@ -17,6 +17,7 @@ DisplayText::DisplayText(QWidget *parent) , erase_action_ {new QAction {tr ("&Erase"), this}} { setReadOnly (true); + setUndoRedoEnabled (false); viewport ()->setCursor (Qt::ArrowCursor); setWordWrapMode (QTextOption::NoWrap); @@ -72,7 +73,7 @@ void DisplayText::insertLineSpacer(QString const& line) appendText (line, "#d3d3d3"); } -void DisplayText::appendText(QString const& text, QColor bg) +void DisplayText::appendText(QString const& text, QColor bg, QString const& call1, QString const& call2) { auto cursor = textCursor (); cursor.movePosition (QTextCursor::End); @@ -89,7 +90,59 @@ void DisplayText::appendText(QString const& text, QColor bg) { cursor.insertBlock (block_format); } - cursor.insertText (text); + + QTextCharFormat format = cursor.charFormat(); + format.clearBackground(); + int text_index {0}; + if (call1.size ()) + { + auto call_index = text.indexOf (call1); + if (call_index != -1) // sanity check + { + auto pos = highlighted_calls_.find (call1); + if (pos != highlighted_calls_.end ()) + { + cursor.insertText(text.left (call_index), format); + if (pos.value ().first.isValid ()) + { + format.setBackground (pos.value ().first); + } + if (pos.value ().second.isValid ()) + { + format.setForeground (pos.value ().second); + } + cursor.insertText(text.mid (call_index, call1.size ()), format); + text_index = call_index + call1.size (); + } + } + } + if (call2.size ()) + { + auto call_index = text.indexOf (call2, text_index); + if (call_index != -1) // sanity check + { + auto pos = highlighted_calls_.find (call2); + if (pos != highlighted_calls_.end ()) + { + format.setBackground (bg); + format.clearForeground (); + cursor.insertText(text.mid (text_index, call_index - text_index), format); + if (pos.value ().second.isValid ()) + { + format.setBackground (pos.value ().first); + } + if (pos.value ().second.isValid ()) + { + format.setForeground (pos.value ().second); + } + cursor.insertText(text.mid (call_index, call2.size ()), format); + text_index = call_index + call2.size (); + } + } + } + format.setBackground (bg); + format.clearForeground (); + cursor.insertText(text.mid (text_index), format); // position so viewport scrolled to left cursor.movePosition (QTextCursor::StartOfLine); @@ -121,7 +174,6 @@ QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign if(!call.contains(QRegExp("[0-9]|[A-Z]"))) return message; logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore); - message = message.trimmed (); QString appendage; if (!countryWorkedBefore) // therefore not worked call either @@ -143,25 +195,32 @@ QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign } } + int i1=countryName.indexOf(";"); + if(m_bPrincipalPrefix) { + int i2=countryName.lastIndexOf(";"); + if(i1>0) countryName=countryName.mid(i1+2,i2-i1-2); + } else { + if(i1>0) countryName=countryName.mid(0,i1); // do some obvious abbreviations - countryName.replace ("Islands", "Is."); - countryName.replace ("Island", "Is."); - countryName.replace ("North ", "N. "); - countryName.replace ("Northern ", "N. "); - countryName.replace ("South ", "S. "); - countryName.replace ("East ", "E. "); - countryName.replace ("Eastern ", "E. "); - countryName.replace ("West ", "W. "); - countryName.replace ("Western ", "W. "); - countryName.replace ("Central ", "C. "); - countryName.replace (" and ", " & "); - countryName.replace ("Republic", "Rep."); - countryName.replace ("United States", "U.S.A."); - countryName.replace ("Fed. Rep. of ", ""); - countryName.replace ("French ", "Fr."); - countryName.replace ("Asiatic", "AS"); - countryName.replace ("European", "EU"); - countryName.replace ("African", "AF"); + countryName.replace ("Islands", "Is."); + countryName.replace ("Island", "Is."); + countryName.replace ("North ", "N. "); + countryName.replace ("Northern ", "N. "); + countryName.replace ("South ", "S. "); + countryName.replace ("East ", "E. "); + countryName.replace ("Eastern ", "E. "); + countryName.replace ("West ", "W. "); + countryName.replace ("Western ", "W. "); + countryName.replace ("Central ", "C. "); + countryName.replace (" and ", " & "); + countryName.replace ("Republic", "Rep."); + countryName.replace ("United States", "U.S.A."); + countryName.replace ("Fed. Rep. of ", ""); + countryName.replace ("French ", "Fr."); + countryName.replace ("Asiatic", "AS"); + countryName.replace ("European", "EU"); + countryName.replace ("African", "AF"); + } appendage += countryName; @@ -181,9 +240,11 @@ QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign void DisplayText::displayDecodedText(DecodedText const& decodedText, QString const& myCall, bool displayDXCCEntity, LogBook const& logBook, QColor color_CQ, QColor color_MyCall, - QColor color_DXCC, QColor color_NewCall) + QColor color_DXCC, QColor color_NewCall, bool ppfx, + bool bCQonly) { - QColor bg {Qt::white}; + m_bPrincipalPrefix=ppfx; + QColor bg {Qt::transparent}; bool CQcall = false; if (decodedText.string ().contains (" CQ ") || decodedText.string ().contains (" CQDX ") @@ -192,6 +253,7 @@ void DisplayText::displayDecodedText(DecodedText const& decodedText, QString con CQcall = true; bg = color_CQ; } + if(bCQonly and !CQcall) return; if (myCall != "" and ( decodedText.indexOf (" " + myCall + " ") >= 0 or decodedText.indexOf (" " + myCall + "/") >= 0 @@ -201,13 +263,16 @@ void DisplayText::displayDecodedText(DecodedText const& decodedText, QString con bg = color_MyCall; } auto message = decodedText.string (); + QString dxCall; + QString dxGrid; + decodedText.deCallAndGrid (dxCall, dxGrid); message = message.left (message.indexOf (QChar::Nbsp)); // strip appended info if (displayDXCCEntity && CQcall) // if enabled add the DXCC entity and B4 status to the end of the // preformated text line t1 message = appendDXCCWorkedB4 (message, decodedText.CQersCall (), &bg, logBook, color_CQ, color_DXCC, color_NewCall); - appendText (message.trimmed (), bg); + appendText (message.trimmed (), bg, decodedText.call (), dxCall); } @@ -225,6 +290,9 @@ void DisplayText::displayTransmittedText(QString text, QString modeTx, qint32 tx if(bFastMode or modeTx=="FT8") { t = QDateTime::currentDateTimeUtc().toString("hhmmss") + \ " Tx " + t2 + t1 + text; + } else if(modeTx.mid(0,6)=="FT8fox") { + t = QDateTime::currentDateTimeUtc().toString("hhmmss") + \ + " Tx" + modeTx.mid(7) + " " + text; } else { t = QDateTime::currentDateTimeUtc().toString("hhmm") + \ " Tx " + t2 + t1 + text; @@ -237,3 +305,101 @@ void DisplayText::displayQSY(QString text) QString t = QDateTime::currentDateTimeUtc().toString("hhmmss") + " " + text; appendText (t, "hotpink"); } + +void DisplayText::displayFoxToBeCalled(QString t, QColor bg) +{ + appendText(t,bg); +} + +namespace +{ + void update_selection (QTextCursor& cursor, QColor const& bg, QColor const& fg) + { + if (!cursor.isNull ()) + { + QTextCharFormat format {cursor.charFormat ()}; + if (bg.isValid ()) + { + format.setBackground (bg); + } + else + { + format.clearBackground (); + } + if (fg.isValid ()) + { + format.setForeground (fg); + } + else + { + format.clearForeground (); + } + cursor.mergeCharFormat (format); + } + } + + void reset_selection (QTextCursor& cursor) + { + if (!cursor.isNull ()) + { + // restore previous text format, we rely on the text + // char format at he start of the selection being the + // old one which should be the case + auto c2 = cursor; + c2.setPosition (c2.selectionStart ()); + cursor.setCharFormat (c2.charFormat ()); + } + } +} + +void DisplayText::highlight_callsign (QString const& callsign, QColor const& bg, QColor const& fg, bool last_only) +{ + QTextCharFormat old_format {currentCharFormat ()}; + QTextCursor cursor {document ()}; + if (last_only) + { + cursor.movePosition (QTextCursor::End); + cursor = document ()->find (callsign, cursor + , QTextDocument::FindBackward | QTextDocument::FindWholeWords); + if (bg.isValid () || fg.isValid ()) + { + update_selection (cursor, bg, fg); + } + else + { + reset_selection (cursor); + } + } + else + { + auto pos = highlighted_calls_.find (callsign); + if (bg.isValid () || fg.isValid ()) + { + auto colours = qMakePair (bg, fg); + if (pos == highlighted_calls_.end ()) + { + pos = highlighted_calls_.insert (callsign.toUpper (), colours); + } + else + { + pos.value () = colours; // update colours + } + while (!cursor.isNull ()) + { + cursor = document ()->find (callsign, cursor, QTextDocument::FindWholeWords); + update_selection (cursor, bg, fg); + } + } + else if (pos != highlighted_calls_.end ()) + { + highlighted_calls_.erase (pos); + QTextCursor cursor {document ()}; + while (!cursor.isNull ()) + { + cursor = document ()->find (callsign, cursor, QTextDocument::FindWholeWords); + reset_selection (cursor); + } + } + } + setCurrentCharFormat (old_format); +} -- cgit v1.2.3