Fix initialization issue with user modified application font

The main  window font  has to  be set  after main  window construction
otherwise the menu bar font does not get set.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8077 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2017-09-09 19:34:54 +00:00
parent 4d5331899b
commit c8dc00320f
4 changed files with 34 additions and 21 deletions

View File

@ -380,8 +380,6 @@ 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 initialize_models ();
bool split_mode () const
{
@ -621,6 +619,7 @@ QColor Configuration::color_MyCall () const {return m_->color_MyCall_;}
QColor Configuration::color_TxMsg () const {return m_->color_TxMsg_;}
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::decoded_text_font () const {return m_->decoded_text_font_;}
qint32 Configuration::id_interval () const {return m_->id_interval_;}
qint32 Configuration::ntrials() const {return m_->ntrials_;}
@ -1179,13 +1178,12 @@ void Configuration::impl::read_settings ()
&& next_font_ != font_)
{
font_ = next_font_;
Q_EMIT self_->text_font_changed (font_);
}
else
{
next_font_ = font_;
}
set_application_font (font_);
if (next_decoded_text_font_.fromString (settings_->value ("DecodedTextFont", "Courier, 10").toString ())
&& next_decoded_text_font_ != decoded_text_font_)
{
@ -1694,7 +1692,7 @@ void Configuration::impl::accept ()
if (next_font_ != font_)
{
font_ = next_font_;
set_application_font (font_);
Q_EMIT self_->text_font_changed (font_);
}
if (next_decoded_text_font_ != decoded_text_font_)
@ -2633,18 +2631,6 @@ void Configuration::impl::update_audio_channels (QComboBox const * source_combo_
}
}
void Configuration::impl::set_application_font (QFont const& font)
{
qApp->setFont (font);
// set font in the application style sheet as well in case it has
// been modified in the style sheet which has priority
qApp->setStyleSheet (qApp->styleSheet () + "* {" + font_as_stylesheet (font) + '}');
for (auto& widget : qApp->topLevelWidgets ())
{
widget->updateGeometry ();
}
}
// load all the supported rig names into the selection combo box
void Configuration::impl::enumerate_rigs ()
{

View File

@ -96,6 +96,7 @@ public:
QString my_callsign () const;
QString my_grid () const;
QFont text_font () const;
QFont decoded_text_font () const;
qint32 id_interval () const;
qint32 ntrials() const;
@ -211,9 +212,10 @@ public:
//
// This signal indicates that a font has been selected and accepted
// for the decoded text.
// These signals indicate a font has been selected and accepted for
// the application text and decoded text respectively.
//
Q_SIGNAL void text_font_changed (QFont);
Q_SIGNAL void decoded_text_font_changed (QFont);
//

View File

@ -551,8 +551,13 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
connect(ui->decodedTextBrowser,SIGNAL(selectCallsign(bool,bool)),this,
SLOT(doubleClickOnCall2(bool,bool)));
// initialise decoded text font and hook up change signal
setDecodedTextFont (m_config.decoded_text_font ());
// initialize decoded text font and hook up font change signals
// defer initialization until after construction otherwise menu
// fonts do not get set
QTimer::singleShot (0, this, SLOT (initialize_fonts ()));
connect (&m_config, &Configuration::text_font_changed, [this] (QFont const& font) {
set_application_font (font);
});
connect (&m_config, &Configuration::decoded_text_font_changed, [this] (QFont const& font) {
setDecodedTextFont (font);
});
@ -894,6 +899,12 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
if (!m_valid) throw std::runtime_error {"Fatal initialization exception"};
}
void MainWindow::initialize_fonts ()
{
set_application_font (m_config.text_font ());
setDecodedTextFont (m_config.decoded_text_font ());
}
void MainWindow::splash_done ()
{
m_splash && m_splash->close ();
@ -1093,6 +1104,18 @@ void MainWindow::readSettings()
if (displayMsgAvg) on_actionMessage_averaging_triggered();
}
void MainWindow::set_application_font (QFont const& font)
{
qApp->setFont (font);
// set font in the application style sheet as well in case it has
// been modified in the style sheet which has priority
qApp->setStyleSheet (qApp->styleSheet () + "* {" + font_as_stylesheet (font) + '}');
for (auto& widget : qApp->topLevelWidgets ())
{
widget->updateGeometry ();
}
}
void MainWindow::setDecodedTextFont (QFont const& font)
{
ui->decodedTextBrowser->setContentFont (font);

View File

@ -123,6 +123,7 @@ protected:
bool eventFilter(QObject *, QEvent *) override;
private slots:
void initialize_fonts ();
void on_tx1_editingFinished();
void on_tx2_editingFinished();
void on_tx3_editingFinished();
@ -571,6 +572,7 @@ private:
//---------------------------------------------------- private functions
void readSettings();
void set_application_font (QFont const&);
void setDecodedTextFont (QFont const&);
void writeSettings();
void createStatusBar();