From 873929b3f68952d48b5b3a3dae47ac57bbfe07c0 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Wed, 12 Sep 2018 20:51:46 -0400 Subject: [PATCH] Fixed configuration ui for compose textbox --- Configuration.cpp | 79 ++++++++++++--- Configuration.hpp | 5 +- Configuration.ui | 238 ++++++++++++++++++++++++++++------------------ mainwindow.cpp | 66 +++++++++++-- 4 files changed, 274 insertions(+), 114 deletions(-) diff --git a/Configuration.cpp b/Configuration.cpp index 5a76c16..15bf061 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -473,7 +473,9 @@ private: Q_SLOT void on_rxBackgroundButton_clicked(); Q_SLOT void on_rxForegroundButton_clicked(); Q_SLOT void on_rxFontButton_clicked(); - Q_SLOT void on_txBackgroundButton_clicked(); + Q_SLOT void on_composeBackgroundButton_clicked(); + Q_SLOT void on_composeForegroundButton_clicked(); + Q_SLOT void on_composeFontButton_clicked(); Q_SLOT void on_txForegroundButton_clicked(); Q_SLOT void on_txFontButton_clicked(); @@ -519,6 +521,9 @@ private: QFont tx_text_font_; QFont next_tx_text_font_; + QFont compose_text_font_; + QFont next_compose_text_font_; + bool restart_sound_input_device_; bool restart_sound_output_device_; @@ -582,8 +587,10 @@ private: QColor next_color_rx_background_; QColor color_rx_foreground_; QColor next_color_rx_foreground_; - QColor color_tx_background_; - QColor next_color_tx_background_; + QColor color_compose_background_; + QColor next_color_compose_background_; + QColor color_compose_foreground_; + QColor next_color_compose_foreground_; QColor color_tx_foreground_; QColor next_color_tx_foreground_; QColor color_DXCC_; @@ -695,13 +702,15 @@ QColor Configuration::color_CQ () const {return m_->color_cq_;} QColor Configuration::color_MyCall () const {return m_->color_mycall_;} QColor Configuration::color_rx_background () const {return m_->color_rx_background_;} QColor Configuration::color_rx_foreground () const {return m_->color_rx_foreground_;} -QColor Configuration::color_tx_background () const {return m_->color_tx_background_;} QColor Configuration::color_tx_foreground () const {return m_->color_tx_foreground_;} +QColor Configuration::color_compose_background () const {return m_->color_compose_background_;} +QColor Configuration::color_compose_foreground () const {return m_->color_compose_foreground_;} QColor Configuration::color_DXCC () const {return m_->color_DXCC_;} QColor Configuration::color_NewCall () const {return m_->color_NewCall_;} QFont Configuration::text_font () const {return m_->font_;} QFont Configuration::rx_text_font () const {return m_->rx_text_font_;} QFont Configuration::tx_text_font () const {return m_->tx_text_font_;} +QFont Configuration::compose_text_font () const {return m_->compose_text_font_;} qint32 Configuration::id_interval () const {return m_->id_interval_;} qint32 Configuration::ntrials() const {return m_->ntrials_;} qint32 Configuration::aggressive() const {return m_->aggressive_;} @@ -1275,9 +1284,9 @@ void Configuration::impl::initialize_models () ui_->labMyCall->setStyleSheet(QString("background: %1").arg(color_mycall_.name())); ui_->rxLabel->setStyleSheet(QString("background: %1").arg(color_rx_background_.name())); - ui_->txLabel->setStyleSheet(QString("background: %1").arg(color_tx_background_.name())); ui_->rxForegroundLabel->setStyleSheet(QString("background: %1; color: %2").arg(color_rx_background_.name()).arg(color_rx_foreground_.name())); ui_->txForegroundLabel->setStyleSheet(QString("background: %1; color: %2").arg(color_rx_background_.name()).arg(color_tx_foreground_.name())); + ui_->composeLabel->setStyleSheet(QString("background: %1; color: %2").arg(color_compose_background_.name()).arg(color_compose_foreground_.name())); ui_->CW_id_interval_spin_box->setValue (id_interval_); ui_->sbNtrials->setValue (ntrials_); @@ -1413,7 +1422,8 @@ void Configuration::impl::read_settings () next_color_mycall_ = color_mycall_ = settings_->value("colorMyCall","#ff6666").toString(); next_color_rx_background_ = color_rx_background_ = settings_->value("color_rx_background","#ffeaa7").toString(); next_color_rx_foreground_ = color_rx_foreground_ = settings_->value("color_rx_foreground","#000000").toString(); - next_color_tx_background_ = color_tx_background_ = settings_->value("color_tx_background","#ffffff").toString(); + next_color_compose_background_ = color_compose_background_ = settings_->value("color_compose_background","#ffffff").toString(); + next_color_compose_foreground_ = color_compose_foreground_ = settings_->value("color_compose_foreground","#000000").toString(); next_color_tx_foreground_ = color_tx_foreground_ = settings_->value("color_tx_foreground","#ff0000").toString(); next_color_DXCC_ = color_DXCC_ = settings_->value("colorDXCC","#ff00ff").toString(); next_color_NewCall_ = color_NewCall_ = settings_->value("colorNewCall","#ffaaff").toString(); @@ -1456,6 +1466,19 @@ void Configuration::impl::read_settings () ui_->rxFontButton->setText(QString("Font (%1 %2)").arg(next_rx_text_font_.family()).arg(next_rx_text_font_.pointSize())); + if (next_compose_text_font_.fromString (settings_->value ("composeTextFont", QGuiApplication::font ().toString ()).toString ()) + && next_compose_text_font_ != compose_text_font_) + { + compose_text_font_ = next_compose_text_font_; + Q_EMIT self_->compose_text_font_changed (compose_text_font_); + } + else + { + next_compose_text_font_ = compose_text_font_; + } + + ui_->composeFontButton->setText(QString("Font (%1 %2)").arg(next_compose_text_font_.family()).arg(next_compose_text_font_.pointSize())); + id_interval_ = settings_->value ("IDint", 0).toInt (); ntrials_ = settings_->value ("nTrials", 6).toInt (); txDelay_ = settings_->value ("TxDelay",0.2).toDouble(); @@ -1638,7 +1661,8 @@ void Configuration::impl::write_settings () settings_->setValue("colorMyCall",color_mycall_); settings_->setValue("color_rx_background",color_rx_background_); settings_->setValue("color_rx_foreground",color_rx_foreground_); - settings_->setValue("color_tx_background",color_tx_background_); + settings_->setValue("color_compose_background",color_compose_background_); + settings_->setValue("color_compose_foreground",color_compose_foreground_); settings_->setValue("color_tx_foreground",color_tx_foreground_); settings_->setValue("colorDXCC",color_DXCC_); settings_->setValue("colorNewCall",color_NewCall_); @@ -2018,11 +2042,18 @@ void Configuration::impl::accept () Q_EMIT self_->rx_text_font_changed (rx_text_font_); } + if (next_compose_text_font_ != compose_text_font_) + { + compose_text_font_ = next_compose_text_font_; + Q_EMIT self_->compose_text_font_changed (compose_text_font_); + } + color_cq_ = next_color_cq_; color_mycall_ = next_color_mycall_; color_rx_background_ = next_color_rx_background_; color_rx_foreground_ = next_color_rx_foreground_; - color_tx_background_ = next_color_tx_background_; + color_compose_background_ = next_color_compose_background_; + color_compose_foreground_ = next_color_compose_foreground_; color_tx_foreground_ = next_color_tx_foreground_; color_DXCC_ = next_color_DXCC_; color_NewCall_ = next_color_NewCall_; @@ -2331,15 +2362,23 @@ void Configuration::impl::on_rxFontButton_clicked () ui_->rxFontButton->setText(QString("Font (%1 %2)").arg(next_rx_text_font_.family()).arg(next_rx_text_font_.pointSize())); } -void Configuration::impl::on_txBackgroundButton_clicked() +void Configuration::impl::on_composeBackgroundButton_clicked() { - auto new_color = getColor(next_color_tx_background_, this, "Transmitted Messages Background Color"); + auto new_color = getColor(next_color_compose_background_, this, "Compose Messages Background Color"); if (new_color.isValid ()) { - next_color_tx_background_ = new_color; - ui_->txLabel->setStyleSheet(QString("background: %1").arg(next_color_tx_background_.name())); - ui_->rxForegroundLabel->setStyleSheet(QString("background: %1; color: %2").arg(next_color_rx_background_.name()).arg(next_color_rx_foreground_.name())); - ui_->txForegroundLabel->setStyleSheet(QString("background: %1; color: %2").arg(next_color_rx_background_.name()).arg(next_color_tx_foreground_.name())); + next_color_compose_background_ = new_color; + ui_->composeLabel->setStyleSheet(QString("background: %1; color: %2").arg(next_color_compose_background_.name()).arg(next_color_compose_foreground_.name())); + } +} + +void Configuration::impl::on_composeForegroundButton_clicked() +{ + auto new_color = getColor(next_color_compose_foreground_, this, "Compose Messages Foreground Color"); + if (new_color.isValid ()) + { + next_color_compose_foreground_ = new_color; + ui_->composeLabel->setStyleSheet(QString("background: %1; color: %2").arg(next_color_compose_background_.name()).arg(next_color_compose_foreground_.name())); } } @@ -2349,7 +2388,6 @@ void Configuration::impl::on_txForegroundButton_clicked() if (new_color.isValid ()) { next_color_tx_foreground_ = new_color; - ui_->txLabel->setStyleSheet(QString("background: %1").arg(next_color_tx_background_.name())); ui_->rxForegroundLabel->setStyleSheet(QString("background: %1; color: %2").arg(next_color_rx_background_.name()).arg(next_color_rx_foreground_.name())); ui_->txForegroundLabel->setStyleSheet(QString("background: %1; color: %2").arg(next_color_rx_background_.name()).arg(next_color_tx_foreground_.name())); } @@ -2367,6 +2405,17 @@ void Configuration::impl::on_txFontButton_clicked () ui_->txFontButton->setText(QString("Font (%1 %2)").arg(next_tx_text_font_.family()).arg(next_tx_text_font_.pointSize())); } +void Configuration::impl::on_composeFontButton_clicked () +{ + next_compose_text_font_ = QFontDialog::getFont (0, next_compose_text_font_ , this + , tr ("Font Chooser") +#if QT_VERSION >= 0x050201 + , 0 +#endif + ); + ui_->composeFontButton->setText(QString("Font (%1 %2)").arg(next_compose_text_font_.family()).arg(next_compose_text_font_.pointSize())); +} + void Configuration::impl::on_PTT_port_combo_box_activated (int /* index */) { set_rig_invariants (); diff --git a/Configuration.hpp b/Configuration.hpp index b919fc2..5561086 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -106,6 +106,7 @@ public: QFont text_font () const; QFont rx_text_font () const; QFont tx_text_font () const; + QFont compose_text_font () const; qint32 id_interval () const; qint32 ntrials() const; qint32 aggressive() const; @@ -184,8 +185,9 @@ public: QColor color_MyCall () const; QColor color_rx_background () const; QColor color_rx_foreground () const; - QColor color_tx_background () const; QColor color_tx_foreground () const; + QColor color_compose_background () const; + QColor color_compose_foreground () const; QColor color_DXCC () const; QColor color_NewCall () const; bool pwrBandTxMemory () const; @@ -281,6 +283,7 @@ public: Q_SIGNAL void gui_text_font_changed (QFont); Q_SIGNAL void tx_text_font_changed (QFont); Q_SIGNAL void rx_text_font_changed (QFont); + Q_SIGNAL void compose_text_font_changed (QFont); Q_SIGNAL void colors_changed (); // diff --git a/Configuration.ui b/Configuration.ui index 6909f91..b303b24 100644 --- a/Configuration.ui +++ b/Configuration.ui @@ -2747,7 +2747,7 @@ Right click for insert and delete options. - Band Activity Background + Band Activity Background: @@ -2818,12 +2818,55 @@ Right click for insert and delete options. - + - Message Background + Messages: - - + + + + + Font + + + + + + + true + + + + 140 + 0 + + + + Textbox Color + + + + + + + Foreground Color + + + + + + + QLabel{background-color: #ffeaa7} + + + K1ABC + + + Qt::AlignCenter + + + + true @@ -2845,24 +2888,98 @@ Right click for insert and delete options. - - - - true - - - - 140 - 0 - + + + + QLabel{background-color: #ffeaa7} - Receive Background Color + K1ABC + + + Qt::AlignCenter - - + + + + Transmitted: + + + + + + + Font + + + + + + + Foreground Color + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Received: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Message Composition: + + + + + + Textbox Color + + + + + + + Font + + + + + true @@ -2883,84 +3000,25 @@ Right click for insert and delete options. - - - - Transmit Background Color - - - - - - - - - - Messages Received - - - - - - Font - - - - + Foreground Color - - - - QLabel{background-color: #ffeaa7} - - - K1ABC - - - Qt::AlignCenter - - - - - - - - - - Messages Transmitted - - - - - Foreground Color + + + Qt::Vertical - - - - - - Font + + + 20 + 40 + - - - - - - QLabel{background-color: #ffeaa7} - - - K1ABC - - - Qt::AlignCenter - - + @@ -3418,12 +3476,12 @@ soundcard changes - + + - - + diff --git a/mainwindow.cpp b/mainwindow.cpp index 0d48dd9..4f72960 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -304,10 +304,46 @@ namespace edit->updateGeometry(); } - void setTextEditBackground(QTextEdit *edit, QColor color){ - edit->setStyleSheet(QString("QTextEdit{ background: %1 }").arg(color.name())); + void setTextEditColors(QTextEdit *edit, QColor fg, QColor bg){ + edit->setStyleSheet(QString("QTextEdit { color:%1; background: %2 }").arg(fg.name()).arg(bg.name())); + + QTimer::singleShot(10, nullptr, [edit, fg, bg](){ + QPalette p = edit->palette(); + p.setColor(QPalette::Base, bg); + p.setColor(QPalette::Active, QPalette::Base, bg); + p.setColor(QPalette::Disabled, QPalette::Base, bg); + p.setColor(QPalette::Inactive, QPalette::Base, bg); + + p.setColor(QPalette::Text, fg); + p.setColor(QPalette::Active, QPalette::Text, fg); + p.setColor(QPalette::Disabled, QPalette::Text, fg); + p.setColor(QPalette::Inactive, QPalette::Text, fg); + + edit->setBackgroundRole(QPalette::Base); + edit->setForegroundRole(QPalette::Text); + edit->setPalette(p); + + edit->updateGeometry(); + edit->update(); + }); } + /* + void setTextEditForeground(QTextEdit *edit, QColor color){ + QTimer::singleShot(20, nullptr, [edit, color](){ + QPalette p = edit->palette(); + p.setColor(QPalette::Text, color); + p.setColor(QPalette::Active, QPalette::Text, color); + p.setColor(QPalette::Disabled, QPalette::Text, color); + p.setColor(QPalette::Inactive, QPalette::Text, color); + + edit->setPalette(p); + edit->updateGeometry(); + edit->update(); + }); + } + */ + void highlightBlock(QTextBlock block, QFont font, QColor foreground, QColor background){ QTextCursor cursor(block); @@ -695,12 +731,12 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, connect (&m_config, &Configuration::rx_text_font_changed, [this] (QFont const&) { setTextEditFont(ui->textEditRX, m_config.rx_text_font()); }); - connect (&m_config, &Configuration::tx_text_font_changed, [this] (QFont const&) { - setTextEditFont(ui->extFreeTextMsgEdit, m_config.tx_text_font()); + connect (&m_config, &Configuration::compose_text_font_changed, [this] (QFont const&) { + setTextEditFont(ui->extFreeTextMsgEdit, m_config.compose_text_font()); }); connect (&m_config, &Configuration::colors_changed, [this](){ - setTextEditBackground(ui->textEditRX, m_config.color_rx_background()); - setTextEditBackground(ui->extFreeTextMsgEdit, m_config.color_tx_background()); + setTextEditColors(ui->textEditRX, m_config.color_rx_foreground(), m_config.color_rx_background()); + setTextEditColors(ui->extFreeTextMsgEdit, m_config.color_compose_foreground(), m_config.color_compose_background()); // rehighlight auto d = ui->textEditRX->document(); @@ -1359,6 +1395,17 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, displayActivity(true); + /* + QTimer::singleShot(1000, this, [this](){ + QPalette p; + p.setBrush(QPalette::Text, QColor(Qt::red)); + p.setColor(QPalette::Text, QColor(Qt::red)); + ui->extFreeTextMsgEdit->setPalette(p); + ui->extFreeTextMsgEdit->updateGeometry(); + ui->extFreeTextMsgEdit->update(); + }); + */ + QTimer::singleShot(0, this, &MainWindow::initializeDummyData); // this must be the last statement of constructor @@ -1789,7 +1836,10 @@ void MainWindow::readSettings() //ui->bandHorizontalWidget->setGeometry( m_settings->value("PanelWaterfallGeometry", ui->bandHorizontalWidget->geometry()).toRect()); //qDebug() << m_settings->value("PanelTopGeometry") << ui->extFreeTextMsg; - ui->textEditRX->setStyleSheet(QString("QTextEdit { background: %1 }").arg(m_config.color_rx_background().name())); + setTextEditColors(ui->textEditRX, m_config.color_rx_foreground(), m_config.color_rx_background()); + setTextEditColors(ui->extFreeTextMsgEdit, m_config.color_compose_foreground(), m_config.color_compose_background()); + + { auto const& coeffs = m_settings->value ("PhaseEqualizationCoefficients" @@ -6216,7 +6266,7 @@ void MainWindow::on_extFreeTextMsgEdit_currentTextChanged (QString const& text) QTextCursor c = ui->extFreeTextMsgEdit->textCursor(); c.setPosition(pos < maxpos ? pos : maxpos, QTextCursor::MoveAnchor); - highlightBlock(c.block(), m_config.tx_text_font(), QColor(Qt::black), QColor(Qt::transparent)); + highlightBlock(c.block(), m_config.compose_text_font(), m_config.color_compose_foreground(), QColor(Qt::transparent)); ui->extFreeTextMsgEdit->setTextCursor(c); }