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 <QDebug>
#include <QFontMetrics>
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
}

View File

@ -8,6 +8,7 @@
#include <QString>
#include <QFont>
#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

View File

@ -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,8 +1462,10 @@ 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;
}