1. Moved font width calc for DXCC enitity display from LogBook to DisplayText.

2. The available character count is now updated by catching resizeEvents


git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3545 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Murray Curtis 2013-08-11 11:45:17 +00:00
parent 2946ad43c4
commit e613c147b3
5 changed files with 50 additions and 35 deletions

View File

@ -2,9 +2,12 @@
#include <QDebug> #include <QDebug>
#include <QMouseEvent> #include <QMouseEvent>
DisplayText::DisplayText(QWidget *parent) : DisplayText::DisplayText(QWidget *parent) :
QTextBrowser(parent) QTextBrowser(parent)
{ {
_fontWidth = 8; // typical
_maxDisplayedCharacters = 48; // a nominal safe(?) value
} }
void DisplayText::mouseDoubleClickEvent(QMouseEvent *e) void DisplayText::mouseDoubleClickEvent(QMouseEvent *e)
@ -14,3 +17,18 @@ void DisplayText::mouseDoubleClickEvent(QMouseEvent *e)
emit(selectCallsign(shift,ctrl)); emit(selectCallsign(shift,ctrl));
QTextBrowser::mouseDoubleClickEvent(e); QTextBrowser::mouseDoubleClickEvent(e);
} }
void DisplayText::setFont(QFont font)
{
QFontMetrics qfm(font);
_fontWidth = qfm.averageCharWidth()+1; // the plus one is emperical
QTextBrowser::setFont(font);
}
void DisplayText::resizeEvent(QResizeEvent * event)
{
if (_fontWidth > 0 && _fontWidth < 999)
_maxDisplayedCharacters = width()/_fontWidth;
QTextBrowser::resizeEvent(event);
}

View File

@ -7,15 +7,25 @@ class DisplayText : public QTextBrowser
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DisplayText(QWidget *parent = 0); explicit DisplayText(QWidget *parent = 0);
void setFont(QFont font);
int getMaxDisplayedCharacters() { return _maxDisplayedCharacters; }
signals: signals:
void selectCallsign(bool shift, bool ctrl); void selectCallsign(bool shift, bool ctrl);
public slots: public slots:
protected: protected:
void mouseDoubleClickEvent(QMouseEvent *e); void mouseDoubleClickEvent(QMouseEvent *e);
void resizeEvent(QResizeEvent * event);
private:
int _fontWidth;
int _maxDisplayedCharacters;
}; };

View File

@ -74,10 +74,3 @@ void LogBook::addAsWorked(const QString call)
void LogBook::setDisplayFont(QFont font)
{
QFontMetrics qfm(font);
_fontWidth = qfm.averageCharWidth()+1; // the plus one is emperical
}

View File

@ -24,10 +24,6 @@ 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;
@ -35,9 +31,6 @@ private:
void _setAlreadyWorkedFromLog(); void _setAlreadyWorkedFromLog();
int _fontWidth;
}; };
#endif // LOGBOOK_H #endif // LOGBOOK_H

View File

@ -137,6 +137,7 @@ MainWindow::MainWindow(QSettings * settings, QSharedMemory *shdmem, QString *the
connect(ui->decodedTextBrowser,SIGNAL(selectCallsign(bool,bool)),this, connect(ui->decodedTextBrowser,SIGNAL(selectCallsign(bool,bool)),this,
SLOT(doubleClickOnCall2(bool,bool))); SLOT(doubleClickOnCall2(bool,bool)));
setWindowTitle(Program_Title_Version); setWindowTitle(Program_Title_Version);
connect(&m_detector, &Detector::framesWritten, this, &MainWindow::dataSink); connect(&m_detector, &Detector::framesWritten, this, &MainWindow::dataSink);
connect(&m_soundInput, SIGNAL(error(QString)), this, connect(&m_soundInput, SIGNAL(error(QString)), this,
@ -173,7 +174,6 @@ MainWindow::MainWindow(QSettings * settings, QSharedMemory *shdmem, QString *the
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");
@ -1441,34 +1441,35 @@ 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);
//TODO this should happen on a resizeEvent int charsAvail = ui->decodedTextBrowser->getMaxDisplayedCharacters();
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 // 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 t1 = t1.left(36); // reduce trailing white space
charsAvail -= 36; charsAvail -= 36;
if (charsAvail > 4)
if (!countryWorkedBefore) // therefore not worked call either
{ {
t1 += "!"; if (!countryWorkedBefore) // therefore not worked call either
bg = "#66ff66"; // strong green
}
else
if (!callWorkedBefore) // but have worked the country
{ {
t1 += "~"; t1 += "!";
bg = "#76cd76"; // mid green bg = "#66ff66"; // strong green
} }
else else
{ if (!callWorkedBefore) // but have worked the country
t1 += " "; // have worked this call before {
bg="#9cc79c"; // pale green t1 += "~";
} bg = "#76cd76"; // mid green
charsAvail -= 1; }
else
{
t1 += " "; // have worked this call before
bg="#9cc79c"; // pale green
}
charsAvail -= 1;
if (countryName.length()>charsAvail) 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 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;
}
} }