diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2016-03-21 12:32:11 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2016-03-21 15:26:18 +0000 |
commit | ac6a2bd8990626e7b35a4c98033ea082df48dd7c (patch) | |
tree | e7ee4af4a19b2d924016f3b4c09347fe8c4ad1a9 /src/plugins/help | |
parent | db3217af367deb598028d0b436a4b9c4fbec1ee0 (diff) | |
download | qt-creator-ac6a2bd8990626e7b35a4c98033ea082df48dd7c.tar.gz |
Help: Set sensible fallback fonts
The default fallback font was arbitrary. So far this was not a big issue
because it was basically never used.
Set sensible fallback fonts on the different platforms.
Also make sure that we can see in the settings if the default fallback
font has been changed by the user, and also separate the setting for the
different font properties. Since we did not do this before, we now have
to reset the setting for all existing users, so they benefit from the
more sensible default.
Task-number: QTCREATORBUG-15887
Change-Id: I16419f54c300580d5c9a9b19722aacf790ef66fc
GPush-Base: 44820dae1326476a6e1aa693421c61ae67bb13b0
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/plugins/help')
-rw-r--r-- | src/plugins/help/localhelpmanager.cpp | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/plugins/help/localhelpmanager.cpp b/src/plugins/help/localhelpmanager.cpp index fb9a76d927..2c4eb9f08b 100644 --- a/src/plugins/help/localhelpmanager.cpp +++ b/src/plugins/help/localhelpmanager.cpp @@ -32,6 +32,7 @@ #include <app/app_version.h> #include <coreplugin/icore.h> #include <utils/algorithm.h> +#include <utils/hostosinfo.h> #include <utils/qtcassert.h> #include <QMutexLocker> @@ -56,7 +57,10 @@ QString LocalHelpManager::m_currentFilter = QString(); int LocalHelpManager::m_currentFilterIndex = -1; static const char kHelpHomePageKey[] = "Help/HomePage"; -static const char kFontKey[] = "Help/Font"; +static const char kFontFamilyKey[] = "Help/FallbackFontFamily"; +static const char kFontStyleKey[] = "Help/FallbackFontStyle"; +static const char kFontWeightKey[] = "Help/FallbackFontWeight"; +static const char kFontSizeKey[] = "Help/FallbackFontSize"; static const char kStartOptionKey[] = "Help/StartOption"; static const char kContextHelpOptionKey[] = "Help/ContextHelpOption"; static const char kReturnOnCloseKey[] = "Help/ReturnOnClose"; @@ -64,6 +68,29 @@ static const char kLastShownPagesKey[] = "Help/LastShownPages"; static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom"; static const char kLastSelectedTabKey[] = "Help/LastSelectedTab"; +static const QFont::Style kDefaultFallbackFontStyle = QFont::StyleNormal; +static const int kDefaultFallbackFontWeight = QFont::Normal; +static const int kDefaultFallbackFontSize = 14; + +static QString defaultFallbackFontFamily() +{ + if (Utils::HostOsInfo::isMacHost()) + return QLatin1String("Helvetica"); + if (Utils::HostOsInfo::isAnyUnixHost()) + return QLatin1String("sans-serif"); + return QLatin1String("Arial"); +} + +template <typename T> +static void setOrRemoveSetting(const char *key, const T &value, const T &defaultValue) +{ + QSettings *settings = Core::ICore::settings(); + if (value == defaultValue) + settings->remove(QLatin1String(key)); + else + settings->setValue(QLatin1String(key), value); +} + // TODO remove some time after Qt Creator 3.5 static QVariant getSettingWithFallback(const QString &settingsKey, const QString &fallbackSettingsKey, @@ -123,14 +150,22 @@ void LocalHelpManager::setHomePage(const QString &page) QFont LocalHelpManager::fallbackFont() { - const QVariant value = getSettingWithFallback(QLatin1String(kFontKey), - QLatin1String("font"), QVariant()); - return value.value<QFont>(); + QSettings *settings = Core::ICore::settings(); + const QString family = settings->value(QLatin1String(kFontFamilyKey), defaultFallbackFontFamily()).toString(); + const QFont::Style style = QFont::Style(settings->value(QLatin1String(kFontStyleKey), kDefaultFallbackFontStyle).toInt()); + const int weight = settings->value(QLatin1String(kFontWeightKey), kDefaultFallbackFontWeight).toInt(); + const int size = settings->value(QLatin1String(kFontSizeKey), kDefaultFallbackFontSize).toInt(); + QFont font(family, size, weight); + font.setStyle(style); + return font; } void LocalHelpManager::setFallbackFont(const QFont &font) { - Core::ICore::settings()->setValue(QLatin1String(kFontKey), font); + setOrRemoveSetting(kFontFamilyKey, font.family(), defaultFallbackFontFamily()); + setOrRemoveSetting(kFontStyleKey, font.style(), kDefaultFallbackFontStyle); + setOrRemoveSetting(kFontWeightKey, font.weight(), kDefaultFallbackFontWeight); + setOrRemoveSetting(kFontSizeKey, font.pointSize(), kDefaultFallbackFontSize); emit m_instance->fallbackFontChanged(font); } |