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
This commit is contained in:
Murray Curtis 2013-08-09 03:17:04 +00:00
parent 7d198f3d50
commit db4d5f0141
3 changed files with 35 additions and 5 deletions

View File

@ -1,5 +1,7 @@
#include "logbook.h" #include "logbook.h"
#include <QDebug> #include <QDebug>
#include <QFontMetrics>
void LogBook::init() void LogBook::init()
{ {
@ -69,3 +71,13 @@ void LogBook::addAsWorked(const QString call)
if (countryName.length() > 0) if (countryName.length() > 0)
_worked.setAsWorked(countryName); _worked.setAsWorked(countryName);
} }
void LogBook::setDisplayFont(QFont font)
{
QFontMetrics qfm(font);
_fontWidth = qfm.averageCharWidth()+1; // the plus one is emperical
}

View File

@ -8,6 +8,7 @@
#include <QString> #include <QString>
#include <QFont>
#include "countrydat.h" #include "countrydat.h"
#include "countriesworked.h" #include "countriesworked.h"
@ -23,6 +24,10 @@ public:
bool &countryWorkedBefore); bool &countryWorkedBefore);
void addAsWorked(const QString call); 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: private:
CountryDat _countries; CountryDat _countries;
CountriesWorked _worked; CountriesWorked _worked;
@ -30,6 +35,10 @@ private:
void _setAlreadyWorkedFromLog(); void _setAlreadyWorkedFromLog();
int _fontWidth;
}; };
#endif // LOGBOOK_H #endif // LOGBOOK_H

View File

@ -152,6 +152,8 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QString *thekey, \
font.setWeight(fontWeight2); font.setWeight(fontWeight2);
ui->decodedTextBrowser->setFont(font); ui->decodedTextBrowser->setFont(font);
ui->decodedTextBrowser2->setFont(font); ui->decodedTextBrowser2->setFont(font);
m_logBook.setDisplayFont(font);
font=ui->readFreq->font(); font=ui->readFreq->font();
font.setFamily("helvetica"); font.setFamily("helvetica");
font.setPointSize(9); font.setPointSize(9);
@ -1437,7 +1439,12 @@ void MainWindow::readFromStdout() //readFromStdout
bool countryWorkedBefore; bool countryWorkedBefore;
m_logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,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 if (!countryWorkedBefore) // therefore not worked call either
{ {
@ -1455,8 +1462,10 @@ void MainWindow::readFromStdout() //readFromStdout
t1 += " "; // have worked this call before t1 += " "; // have worked this call before
bg="#9cc79c"; // pale green bg="#9cc79c"; // pale green
} }
if (countryName.length()>10) //TODO: hardcoded width. Depends on font and window size/layout charsAvail -= 1;
countryName = countryName.left(1)+"."+countryName.right(8); //abreviate the first word to the first letter, show remaining right most chars
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; t1 += countryName;
} }