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 <QMouseEvent>
DisplayText::DisplayText(QWidget *parent) :
QTextBrowser(parent)
{
_fontWidth = 8; // typical
_maxDisplayedCharacters = 48; // a nominal safe(?) value
}
void DisplayText::mouseDoubleClickEvent(QMouseEvent *e)
@ -14,3 +17,18 @@ void DisplayText::mouseDoubleClickEvent(QMouseEvent *e)
emit(selectCallsign(shift,ctrl));
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
public:
explicit DisplayText(QWidget *parent = 0);
explicit DisplayText(QWidget *parent = 0);
void setFont(QFont font);
int getMaxDisplayedCharacters() { return _maxDisplayedCharacters; }
signals:
void selectCallsign(bool shift, bool ctrl);
public slots:
protected:
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);
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;
@ -35,9 +31,6 @@ private:
void _setAlreadyWorkedFromLog();
int _fontWidth;
};
#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,
SLOT(doubleClickOnCall2(bool,bool)));
setWindowTitle(Program_Title_Version);
connect(&m_detector, &Detector::framesWritten, this, &MainWindow::dataSink);
connect(&m_soundInput, SIGNAL(error(QString)), this,
@ -173,7 +174,6 @@ MainWindow::MainWindow(QSettings * settings, QSharedMemory *shdmem, QString *the
font.setWeight(fontWeight2);
ui->decodedTextBrowser->setFont(font);
ui->decodedTextBrowser2->setFont(font);
m_logBook.setDisplayFont(font);
font=ui->readFreq->font();
font.setFamily("helvetica");
@ -1441,34 +1441,35 @@ void MainWindow::readFromStdout() //readFromStdout
bool countryWorkedBefore;
m_logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore);
//TODO this should happen on a resizeEvent
int charsAvail = m_logBook.getMaxDisplayedCharacters(ui->decodedTextBrowser->width());
int charsAvail = ui->decodedTextBrowser->getMaxDisplayedCharacters();
// 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 (charsAvail > 4)
{
t1 += "!";
bg = "#66ff66"; // strong green
}
else
if (!callWorkedBefore) // but have worked the country
if (!countryWorkedBefore) // therefore not worked call either
{
t1 += "~";
bg = "#76cd76"; // mid green
t1 += "!";
bg = "#66ff66"; // strong green
}
else
{
t1 += " "; // have worked this call before
bg="#9cc79c"; // pale green
}
charsAvail -= 1;
if (!callWorkedBefore) // but have worked the country
{
t1 += "~";
bg = "#76cd76"; // mid green
}
else
{
t1 += " "; // have worked this call before
bg="#9cc79c"; // pale green
}
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;
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;
}
}