Improve font handling when resetting configurations and when restarting

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6649 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-04-26 20:06:36 +00:00
parent 4797cee661
commit d9e4d5f25f
2 changed files with 20 additions and 3 deletions

View File

@ -1141,12 +1141,12 @@ void Configuration::impl::read_settings ()
&& next_font_ != font_) && next_font_ != font_)
{ {
font_ = next_font_; font_ = next_font_;
set_application_font (font_);
} }
else else
{ {
next_font_ = font_; next_font_ = font_;
} }
set_application_font (font_);
if (next_decoded_text_font_.fromString (settings_->value ("DecodedTextFont", "Courier, 10").toString ()) if (next_decoded_text_font_.fromString (settings_->value ("DecodedTextFont", "Courier, 10").toString ())
&& next_decoded_text_font_ != decoded_text_font_) && next_decoded_text_font_ != decoded_text_font_)
@ -2511,6 +2511,9 @@ void Configuration::impl::update_audio_channels (QComboBox const * source_combo_
void Configuration::impl::set_application_font (QFont const& font) 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) + '}'); qApp->setStyleSheet (qApp->styleSheet () + "* {" + font_as_stylesheet (font) + '}');
for (auto& widget : qApp->topLevelWidgets ()) for (auto& widget : qApp->topLevelWidgets ())
{ {

View File

@ -7,6 +7,7 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDir> #include <QDir>
#include <QFont>
#include <QApplication> #include <QApplication>
#include <QStandardPaths> #include <QStandardPaths>
#include <QMainWindow> #include <QMainWindow>
@ -28,6 +29,7 @@
#include <QMetaObject> #include <QMetaObject>
#include "SettingsGroup.hpp" #include "SettingsGroup.hpp"
#include "qt_helpers.hpp"
#include "pimpl_impl.hpp" #include "pimpl_impl.hpp"
@ -180,6 +182,7 @@ private:
// remove a configuration // remove a configuration
void delete_configuration (QMainWindow *); void delete_configuration (QMainWindow *);
QFont original_font_;
QString current_; QString current_;
// action to take on restart // action to take on restart
@ -307,6 +310,15 @@ bool MultiSettings::impl::reposition ()
} }
// insert the new settings // insert the new settings
load_from (new_settings_, false); load_from (new_settings_, false);
if (!new_settings_.size ())
{
// if we are clearing the current settings then we must
// reset the application font and the font in the
// application style sheet, this is necessary since the
// application instance is not recreated
qApp->setFont (original_font_);
qApp->setStyleSheet (qApp->styleSheet () + "* {" + font_as_stylesheet (original_font_) + '}');
}
// now we have set up the new current we can safely purge it // now we have set up the new current we can safely purge it
// from the alternatives // from the alternatives
{ {
@ -422,8 +434,10 @@ auto MultiSettings::impl::get_settings () const -> Dictionary
Dictionary settings; Dictionary settings;
for (auto const& key: settings_.allKeys ()) for (auto const& key: settings_.allKeys ())
{ {
// filter out multi settings group // filter out multi settings group and empty settings
if (!key.contains (multi_settings_root_group)) // placeholder
if (!key.contains (multi_settings_root_group)
&& !key.contains (multi_settings_place_holder_key))
{ {
settings[key] = settings_.value (key); settings[key] = settings_.value (key);
} }