forked from qt-creator/qt-creator
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: 44820dae13
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user