From 84a8696f2250d89de1bf9bef292c4abee2b4fcea Mon Sep 17 00:00:00 2001 From: Murray Curtis Date: Fri, 9 Aug 2013 03:17:04 +0000 Subject: [PATCH] Calc chars available when adding DXCC entity to decoded text line git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3539 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- logbook/logbook.cpp | 12 ++++++++++++ logbook/logbook.h | 9 +++++++++ mainwindow.cpp | 19 ++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp index 68b52ce5d..952e4bf8d 100644 --- a/logbook/logbook.cpp +++ b/logbook/logbook.cpp @@ -1,5 +1,7 @@ #include "logbook.h" #include +#include + void LogBook::init() { @@ -69,3 +71,13 @@ void LogBook::addAsWorked(const QString call) if (countryName.length() > 0) _worked.setAsWorked(countryName); } + + + + +void LogBook::setDisplayFont(QFont font) +{ + QFontMetrics qfm(font); + _fontWidth = qfm.averageCharWidth()+1; // the plus one is emperical +} + diff --git a/logbook/logbook.h b/logbook/logbook.h index 223412d11..79b9120e4 100644 --- a/logbook/logbook.h +++ b/logbook/logbook.h @@ -8,6 +8,7 @@ #include +#include #include "countrydat.h" #include "countriesworked.h" @@ -23,6 +24,10 @@ public: bool &countryWorkedBefore); void addAsWorked(const QString call); + // TODO these are just to avoid more globals in mainwindow + void setDisplayFont(QFont font); + int getMaxDisplayedCharacters(int displayWidth) { return displayWidth/_fontWidth; } // TODO catch /0 + private: CountryDat _countries; CountriesWorked _worked; @@ -30,6 +35,10 @@ private: void _setAlreadyWorkedFromLog(); + int _fontWidth; + + }; #endif // LOGBOOK_H + diff --git a/mainwindow.cpp b/mainwindow.cpp index d75e96383..70c05679a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -152,6 +152,8 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QString *thekey, \ font.setWeight(fontWeight2); ui->decodedTextBrowser->setFont(font); ui->decodedTextBrowser2->setFont(font); + m_logBook.setDisplayFont(font); + font=ui->readFreq->font(); font.setFamily("helvetica"); font.setPointSize(9); @@ -1437,7 +1439,12 @@ void MainWindow::readFromStdout() //readFromStdout bool countryWorkedBefore; m_logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore); - t1 = t1.left(36); // reduce trailing white space TODO: hardcoded char count + //TODO this should happen on a resizeEvent + int charsAvail = m_logBook.getMaxDisplayedCharacters(ui->decodedTextBrowser->width()); + + // 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 + charsAvail -= 36; if (!countryWorkedBefore) // therefore not worked call either { @@ -1455,14 +1462,16 @@ void MainWindow::readFromStdout() //readFromStdout t1 += " "; // have worked this call before bg="#9cc79c"; // pale green } - if (countryName.length()>10) //TODO: hardcoded width. Depends on font and window size/layout - countryName = countryName.left(1)+"."+countryName.right(8); //abreviate the first word to the first letter, show remaining right most chars + 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 = "
" + t1 + "
"; + bg + "\">
" + t1 + "
"; bool b65=t1.indexOf("#")==19; if(bQSO) { cursor = ui->decodedTextBrowser2->textCursor(); @@ -1479,7 +1488,7 @@ void MainWindow::readFromStdout() //readFromStdout if(jt9com_.nagain==0) { if(m_myCall!="" and t.indexOf(" "+m_myCall+" ")>0) bg="#ff6666"; //red QString s = "
" + t1 + "
"; + bg + "\">
" + t1 + "
"; cursor = ui->decodedTextBrowser->textCursor(); cursor.movePosition(QTextCursor::End); bf = cursor.blockFormat();