diff --git a/CMakeLists.txt b/CMakeLists.txt index b565b8997..d532da251 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,7 @@ endif (APPLE) # Project sources # set (wsjt_qt_CXXSRCS + qt_helpers.cpp NetworkServerLookup.cpp revision_utils.cpp WFPalette.cpp diff --git a/Configuration.cpp b/Configuration.cpp index 3ea7599e7..52227a3af 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -108,18 +108,22 @@ // call to broadcast the setting value change. // // 6) Add code to initialise_models() to load the widget control's -// data model with the current setting value. +// data model with the current value. // -// 7) Add any required inter-field validation to the validate() +// 7) If there is no convenient data model field, add a data member to +// store the proposed new value. Ensure this member has a valid value +// on exit from read_settings(). +// +// 8) Add any required inter-field validation to the validate() // operation. // -// 8) Add code to the accept() operation to extract the setting value +// 9) Add code to the accept() operation to extract the setting value // from the widget control data model and load it into the // Configuration::impl member that reflects the publicly visible // setting state. If the setting value is dynamic; add a signal emit // call to broadcast any changed state of the setting. // -// 9) Add a settings write call to save the setting value to the +// 10) Add a settings write call to save the setting value to the // settings database. // @@ -152,8 +156,7 @@ #include #include -#include "ui_Configuration.h" - +#include "qt_helpers.hpp" #include "SettingsGroup.hpp" #include "FrequencyLineEdit.hpp" #include "FrequencyItemDelegate.hpp" @@ -166,6 +169,7 @@ #include "pimpl_impl.hpp" +#include "ui_Configuration.h" #include "moc_Configuration.cpp" namespace @@ -385,6 +389,8 @@ private: bool load_audio_devices (QAudio::Mode, QComboBox *, QAudioDeviceInfo *); void update_audio_channels (QComboBox const *, int, QComboBox *, bool); + void set_application_font (QFont const&); + void initialise_models (); bool open_rig (); //bool set_mode (); @@ -456,11 +462,9 @@ private: QDir save_directory_; QFont font_; - bool font_changed_; QFont next_font_; QFont decoded_text_font_; - bool decoded_text_font_changed_; QFont next_decoded_text_font_; bool restart_sound_input_device_; @@ -517,10 +521,15 @@ private: QString my_callsign_; QString my_grid_; QColor color_CQ_; + QColor next_color_CQ_; QColor color_MyCall_; + QColor next_color_MyCall_; QColor color_TxMsg_; + QColor next_color_TxMsg_; QColor color_DXCC_; + QColor next_color_DXCC_; QColor color_NewCall_; + QColor next_color_NewCall_; qint32 id_interval_; bool id_after_73_; bool tx_QSY_allowed_; @@ -685,9 +694,6 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget * , self_ {self} , ui_ {new Ui::configuration_dialog} , settings_ {settings} - , font_ {QApplication::font ()} - , font_changed_ {false} - , decoded_text_font_changed_ {false} , frequencies_ { { 136130, @@ -994,8 +1000,6 @@ void Configuration::impl::initialise_models () ui_->labTx->setStyleSheet(QString("background: %1").arg(color_TxMsg_.name())); ui_->labDXCC->setStyleSheet(QString("background: %1").arg(color_DXCC_.name())); ui_->labNewCall->setStyleSheet(QString("background: %1").arg(color_NewCall_.name())); - font_changed_ = false; - decoded_text_font_changed_ = false; ui_->CW_id_interval_spin_box->setValue (id_interval_); ui_->PTT_method_button_group->button (rig_params_.PTT_method_)->setChecked (true); ui_->save_path_display_label->setText (save_directory_.absolutePath ()); @@ -1067,25 +1071,33 @@ void Configuration::impl::read_settings () my_callsign_ = settings_->value ("MyCall", "").toString (); my_grid_ = settings_->value ("MyGrid", "").toString (); - color_CQ_ = settings_->value("colorCQ","#66ff66").toString(); - color_MyCall_ = settings_->value("colorMyCall","#ff6666").toString(); - color_TxMsg_ = settings_->value("colorTxMsg","#ffff00").toString(); - color_DXCC_ = settings_->value("colorDXCC","#ff00ff").toString(); - color_NewCall_ = settings_->value("colorNewCall","#ffaaff").toString(); + next_color_CQ_ = color_CQ_ = settings_->value("colorCQ","#66ff66").toString(); + next_color_MyCall_ = color_MyCall_ = settings_->value("colorMyCall","#ff6666").toString(); + next_color_TxMsg_ = color_TxMsg_ = settings_->value("colorTxMsg","#ffff00").toString(); + next_color_DXCC_ = color_DXCC_ = settings_->value("colorDXCC","#ff00ff").toString(); + next_color_NewCall_ = color_NewCall_ = settings_->value("colorNewCall","#ffaaff").toString(); if (next_font_.fromString (settings_->value ("Font", QGuiApplication::font ().toString ()).toString ()) - && next_font_ != QGuiApplication::font ()) + && next_font_ != font_) { font_ = next_font_; - QApplication::setFont (font_); + set_application_font (font_); + } + else + { + next_font_ = font_; } if (next_decoded_text_font_.fromString (settings_->value ("DecodedTextFont", "Courier, 10").toString ()) - && decoded_text_font_ != next_decoded_text_font_) + && next_decoded_text_font_ != decoded_text_font_) { decoded_text_font_ = next_decoded_text_font_; Q_EMIT self_->decoded_text_font_changed (decoded_text_font_); } + else + { + next_decoded_text_font_ = decoded_text_font_; + } id_interval_ = settings_->value ("IDint", 0).toInt (); @@ -1480,20 +1492,24 @@ void Configuration::impl::accept () // parameters so extract values from models and make them live // - if (font_changed_) + if (next_font_ != font_) { - font_changed_ = false; font_ = next_font_; - QApplication::setFont (font_); + set_application_font (font_); } - if (decoded_text_font_changed_) + if (next_decoded_text_font_ != decoded_text_font_) { - decoded_text_font_changed_ = false; decoded_text_font_ = next_decoded_text_font_; Q_EMIT self_->decoded_text_font_changed (decoded_text_font_); } + color_CQ_ = next_color_CQ_; + color_MyCall_ = next_color_MyCall_; + color_TxMsg_ = next_color_TxMsg_; + color_DXCC_ = next_color_DXCC_; + color_NewCall_ = next_color_NewCall_; + rig_params_ = temp_rig_params; // now we can go live with the rig // related configuration parameters rig_is_dummy_ = TransceiverFactory::basic_transceiver_name_ == rig_params_.rig_name_; @@ -1657,47 +1673,62 @@ void Configuration::impl::message_box (QString const& reason, QString const& det void Configuration::impl::on_font_push_button_clicked () { - next_font_ = QFontDialog::getFont (&font_changed_, this); + next_font_ = QFontDialog::getFont (0, next_font_, this); } void Configuration::impl::on_pbCQmsg_clicked() { - color_CQ_ = QColorDialog::getColor("#6666ff"); - ui_->labCQ->setStyleSheet(QString("background: %1").arg(color_CQ_.name())); + auto new_color = QColorDialog::getColor(next_color_CQ_, this, "CQ Messages Color"); + if (new_color.isValid ()) + { + next_color_CQ_ = new_color; + ui_->labCQ->setStyleSheet(QString("background: %1").arg(next_color_CQ_.name())); + } } void Configuration::impl::on_pbMyCall_clicked() { - color_MyCall_ = QColorDialog::getColor("#ff6666"); - ui_->labMyCall->setStyleSheet(QString("background: %1").arg(color_MyCall_.name())); + auto new_color = QColorDialog::getColor(next_color_MyCall_, this, "My Call Messages Color"); + if (new_color.isValid ()) + { + next_color_MyCall_ = new_color; + ui_->labMyCall->setStyleSheet(QString("background: %1").arg(next_color_MyCall_.name())); + } } void Configuration::impl::on_pbTxMsg_clicked() { - color_TxMsg_ = QColorDialog::getColor("#ffff00"); - ui_->labTx->setStyleSheet(QString("background: %1").arg(color_TxMsg_.name())); + auto new_color = QColorDialog::getColor(next_color_TxMsg_, this, "Tx Messages Color"); + if (new_color.isValid ()) + { + next_color_TxMsg_ = new_color; + ui_->labTx->setStyleSheet(QString("background: %1").arg(next_color_TxMsg_.name())); + } } void Configuration::impl::on_pbNewDXCC_clicked() { - color_DXCC_ = QColorDialog::getColor("#ff00ff"); - ui_->labDXCC->setStyleSheet(QString("background: %1").arg(color_DXCC_.name())); + auto new_color = QColorDialog::getColor(next_color_DXCC_, this, "New DXCC Messages Color"); + if (new_color.isValid ()) + { + next_color_DXCC_ = new_color; + ui_->labDXCC->setStyleSheet(QString("background: %1").arg(next_color_DXCC_.name())); + } } void Configuration::impl::on_pbNewCall_clicked() { - color_NewCall_ = QColorDialog::getColor("#ffaaff"); - ui_->labNewCall->setStyleSheet(QString("background: %1").arg(color_NewCall_.name())); + auto new_color = QColorDialog::getColor(next_color_NewCall_, this, "New Call Messages Color"); + if (new_color.isValid ()) + { + next_color_NewCall_ = new_color; + ui_->labNewCall->setStyleSheet(QString("background: %1").arg(next_color_NewCall_.name())); + } } - - - void Configuration::impl::on_decoded_text_font_push_button_clicked () { - next_decoded_text_font_ = QFontDialog::getFont (&decoded_text_font_changed_ - , decoded_text_font_ - , this + next_decoded_text_font_ = QFontDialog::getFont (0, decoded_text_font_ , this , tr ("WSJT-X Decoded Text Font Chooser") #if QT_VERSION >= 0x050201 , QFontDialog::MonospacedFonts @@ -2313,6 +2344,11 @@ void Configuration::impl::update_audio_channels (QComboBox const * source_combo_ } } +void Configuration::impl::set_application_font (QFont const& font) +{ + qApp->setStyleSheet (qApp->styleSheet () + font_as_stylesheet (font)); +} + // load all the supported rig names into the selection combo box void Configuration::impl::enumerate_rigs () { diff --git a/displaytext.cpp b/displaytext.cpp index e4d9b138a..1aa95cc34 100644 --- a/displaytext.cpp +++ b/displaytext.cpp @@ -3,13 +3,15 @@ #include #include +#include "qt_helpers.hpp" + #include "moc_displaytext.cpp" DisplayText::DisplayText(QWidget *parent) : - QTextBrowser(parent) + QTextEdit(parent) { - _fontWidth = 8; // typical - _maxDisplayedCharacters = 48; // a nominal safe(?) value + setReadOnly (true); + setCursorWidth (0); } void DisplayText::mouseDoubleClickEvent(QMouseEvent *e) @@ -17,26 +19,9 @@ void DisplayText::mouseDoubleClickEvent(QMouseEvent *e) bool ctrl = (e->modifiers() & Qt::ControlModifier); bool shift = (e->modifiers() & Qt::ShiftModifier); emit(selectCallsign(shift,ctrl)); - QTextBrowser::mouseDoubleClickEvent(e); + QTextEdit::mouseDoubleClickEvent(e); } - -void DisplayText::setFont(QFont const& 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); -} - - - void DisplayText::insertLineSpacer() { QString tt="----------------------------------------"; @@ -46,16 +31,11 @@ void DisplayText::insertLineSpacer() void DisplayText::_insertText(const QString text, const QString bg) { - QString tt = text.mid(0,_maxDisplayedCharacters); //truncate to max display chars QString s = "
" + tt + "
"; - - QTextCursor cursor = textCursor(); - cursor.movePosition(QTextCursor::End); - QTextBlockFormat bf = cursor.blockFormat(); - bf.setBackground(QBrush(QColor(bg))); - cursor.insertHtml(s); - this->setTextCursor(cursor); + bg + "\">
" + text.trimmed () + "
"; + moveCursor (QTextCursor::End); + append (s); + moveCursor (QTextCursor::End); } @@ -74,7 +54,7 @@ void DisplayText::_appendDXCCWorkedB4(DecodedText& t1, QString& bg, bool countryWorkedBefore; logBook.match(/*in*/call,/*out*/countryName,callWorkedBefore,countryWorkedBefore); - int charsAvail = _maxDisplayedCharacters; + int charsAvail = 48; // the decoder (seems) to always generate 40 chars. For a normal CQ call, the last five are spaces // TODO this magic 36 characters is also referenced in MainWindow::doubleClickOnCall() diff --git a/displaytext.h b/displaytext.h index 9c293016d..24cf619d8 100644 --- a/displaytext.h +++ b/displaytext.h @@ -2,19 +2,17 @@ #ifndef DISPLAYTEXT_H #define DISPLAYTEXT_H -#include +#include #include "logbook/logbook.h" #include "decodedtext.h" -class DisplayText : public QTextBrowser +class DisplayText : public QTextEdit { Q_OBJECT public: explicit DisplayText(QWidget *parent = 0); - void setFont(QFont const& font); - void insertLineSpacer(); void displayDecodedText(DecodedText decodedText, QString myCall, bool displayDXCCEntity, LogBook logBook, QColor color_CQ, QColor color_MyCall, @@ -30,11 +28,8 @@ public slots: protected: void mouseDoubleClickEvent(QMouseEvent *e); - void resizeEvent(QResizeEvent * event); private: - int _fontWidth; - int _maxDisplayedCharacters; void _insertText(const QString text, const QString bg); void _appendDXCCWorkedB4(/*mod*/DecodedText& t1, QString &bg, LogBook logBook, QColor color_CQ, QColor color_DXCC, QColor color_NewCall); diff --git a/mainwindow.cpp b/mainwindow.cpp index 64fcd85e4..d2e38ec9f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -428,8 +428,6 @@ MainWindow::MainWindow(bool multiple, QSettings * settings, QSharedMemory *shdme ui->label_9->setStyleSheet("QLabel{background-color: #aabec8}"); ui->label_10->setStyleSheet("QLabel{background-color: #aabec8}"); - ui->labUTC->setStyleSheet("QLabel { background-color : black; color : yellow; }"); - ui->labDialFreq->setStyleSheet("QLabel { background-color : black; color : yellow; }"); m_config.transceiver_online (true); on_monitorButton_clicked (!m_config.monitor_off_at_startup ()); @@ -563,10 +561,11 @@ void MainWindow::readSettings() void MainWindow::setDecodedTextFont (QFont const& font) { - ui->decodedTextBrowser->setFont (font); - ui->decodedTextBrowser2->setFont (font); - ui->decodedTextLabel->setFont (font); - ui->decodedTextLabel2->setFont (font); + auto style_sheet = font_as_stylesheet (font); + ui->decodedTextBrowser->setStyleSheet (ui->decodedTextBrowser->styleSheet () + style_sheet); + ui->decodedTextBrowser2->setStyleSheet (ui->decodedTextBrowser2->styleSheet () + style_sheet); + ui->decodedTextLabel->setStyleSheet (ui->decodedTextLabel->styleSheet () + style_sheet); + ui->decodedTextLabel2->setStyleSheet (ui->decodedTextLabel2->styleSheet () + style_sheet); } //-------------------------------------------------------------- dataSink() @@ -943,14 +942,11 @@ void MainWindow::displayDialFrequency () valid = true; } } - if (valid) - { - ui->labDialFreq->setStyleSheet("QLabel { background-color : black; color : yellow; }"); - } - else - { - ui->labDialFreq->setStyleSheet("QLabel { background-color : red; color : yellow; }"); - } + ui->labDialFreq->setProperty ("oob", !valid); + // the following sequence is necessary to update the style + ui->labDialFreq->style ()->unpolish (ui->labDialFreq); + ui->labDialFreq->style ()->polish (ui->labDialFreq); + ui->labDialFreq->update (); ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string (m_dialFreq)); } diff --git a/mainwindow.h b/mainwindow.h index 34f3c506a..f5f0b793a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -45,6 +45,7 @@ namespace Ui { class QSettings; class QLineEdit; +class QFont; class WideGraph; class LogQSO; class Transceiver; diff --git a/mainwindow.ui b/mainwindow.ui index c6d890cc7..c1c9272ac 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 770 - 491 + 541 @@ -59,56 +59,6 @@ 1 - - - - - 0 - 0 - - - - - 200 - 100 - - - - - 600 - 1000 - - - - - Courier New - 10 - - - - QFrame::Panel - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Courier New'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - - - false - - - false - - - @@ -293,40 +243,6 @@ p, li { white-space: pre-wrap; } - - - - - 0 - 0 - - - - - 200 - 100 - - - - - 600 - 1000 - - - - - Courier New - 10 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - @@ -393,6 +309,91 @@ p, li { white-space: pre-wrap; } + + + + + 0 + 1 + + + + + 200 + 100 + + + + false + + + QFrame::Panel + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAsNeeded + + + false + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + false + + + Qt::TextSelectableByMouse + + + + + + + + 0 + 1 + + + + + 200 + 100 + + + + false + + + Qt::ScrollBarAlwaysOn + + + false + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + false + + + 0 + + + Qt::TextSelectableByMouse + + + @@ -431,24 +432,12 @@ p, li { white-space: pre-wrap; } - - - 0 - 0 - - 50 0 - - - 16777215 - 16777215 - - Start monitoring @@ -522,12 +511,6 @@ p, li { white-space: pre-wrap; } - - - 0 - 0 - - 50 @@ -558,12 +541,6 @@ p, li { white-space: pre-wrap; } - - - 0 - 0 - - 50 @@ -960,16 +937,21 @@ p, li { white-space: pre-wrap; } 16777215 - - - 16 - 50 - false - - USB dial frequency + + QLabel { + font-family: MS Shell Dlg 2; + font-size: 16pt; + color : yellow; + background-color : black; +} +QLabel[oob="true"] { + background-color: red; +} + + 14.078 @@ -1166,10 +1148,13 @@ p, li { white-space: pre-wrap; } 60 - - - 16 - + + QLabel { + font-family: MS Shell Dlg 2; + font-size: 16pt; + background-color : black; + color : yellow; +} QFrame::StyledPanel @@ -2703,7 +2688,7 @@ list. The list can be maintained in Settings (F2). DisplayText - QTextBrowser + QTextEdit
displaytext.h
@@ -2742,8 +2727,6 @@ list. The list can be maintained in Settings (F2). txb4 txb5 txb6 - decodedTextBrowser - decodedTextBrowser2 genMsg pbAnswerCaller rbFreeText diff --git a/qt_helpers.cpp b/qt_helpers.cpp new file mode 100644 index 000000000..be3af50fd --- /dev/null +++ b/qt_helpers.cpp @@ -0,0 +1,26 @@ +#include "qt_helpers.hpp" + +#include +#include + +QString font_as_stylesheet (QFont const& font) +{ + QString font_weight; + switch (font.weight ()) + { + case QFont::Light: font_weight = "light"; break; + case QFont::Normal: font_weight = "normal"; break; + case QFont::DemiBold: font_weight = "demibold"; break; + case QFont::Bold: font_weight = "bold"; break; + case QFont::Black: font_weight = "black"; break; + } + return QString {"* {\n" + " font-family: %1;\n" + " font-size: %2pt;\n" + " font-style: %3;\n" + " font-weight: %4;}\n"} + .arg (font.family ()) + .arg (font.pointSize ()) + .arg (font.styleName ()) + .arg (font_weight); +} diff --git a/qt_helpers.hpp b/qt_helpers.hpp index 670f8c423..ae8defb97 100644 --- a/qt_helpers.hpp +++ b/qt_helpers.hpp @@ -66,4 +66,6 @@ void throw_qstring (QString const& qs) throw std::runtime_error (qs.toLocal8Bit ().data ()); } +QString font_as_stylesheet (QFont const&); + #endif