diff --git a/displaytext.cpp b/displaytext.cpp index 0b8181e45..51039f7e3 100644 --- a/displaytext.cpp +++ b/displaytext.cpp @@ -2,9 +2,12 @@ #include #include + 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); +} diff --git a/displaytext.h b/displaytext.h index c07f00eca..bb1c9edf4 100644 --- a/displaytext.h +++ b/displaytext.h @@ -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; }; diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp index 952e4bf8d..a328540a6 100644 --- a/logbook/logbook.cpp +++ b/logbook/logbook.cpp @@ -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 -} - diff --git a/logbook/logbook.h b/logbook/logbook.h index 79b9120e4..f274ea8a0 100644 --- a/logbook/logbook.h +++ b/logbook/logbook.h @@ -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 diff --git a/mainwindow.cpp b/mainwindow.cpp index 776cdb202..c436ce556 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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; + } }