forked from qt-creator/qt-creator
Help: Fix that selecting fallback font style was very limited
It could only handle combinations of "Regular", "Bold", "Oblique", but fonts can have their own sets of fancy style names. Actually set the selected style name on the font and save that in the settings. Task-number: QTCREATORBUG-16620 Change-Id: Ibf8cd6f2ac0d3ff1c0fd100e9db627937c0eb1ec Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -299,21 +299,9 @@ void GeneralSettingsPage::updateFont()
|
||||
fontSize = m_ui->sizeComboBox->itemData(currentIndex).toInt();
|
||||
m_font.setPointSize(fontSize);
|
||||
|
||||
QString fontStyle = "Normal";
|
||||
currentIndex = m_ui->styleComboBox->currentIndex();
|
||||
if (currentIndex != -1)
|
||||
fontStyle = m_ui->styleComboBox->itemText(currentIndex);
|
||||
m_font.setBold(m_fontDatabase.bold(family, fontStyle));
|
||||
if (fontStyle.contains("Italic"))
|
||||
m_font.setStyle(QFont::StyleItalic);
|
||||
else if (fontStyle.contains("Oblique"))
|
||||
m_font.setStyle(QFont::StyleOblique);
|
||||
else
|
||||
m_font.setStyle(QFont::StyleNormal);
|
||||
|
||||
const int weight = m_fontDatabase.weight(family, fontStyle);
|
||||
if (weight >= 0) // Weight < 0 asserts...
|
||||
m_font.setWeight(weight);
|
||||
m_font.setStyleName(m_ui->styleComboBox->itemText(currentIndex));
|
||||
}
|
||||
|
||||
int GeneralSettingsPage::closestPointSizeIndex(int desiredPointSize) const
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFontDatabase>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include <QHelpEngine>
|
||||
@@ -58,8 +59,7 @@ int LocalHelpManager::m_currentFilterIndex = -1;
|
||||
|
||||
static const char kHelpHomePageKey[] = "Help/HomePage";
|
||||
static const char kFontFamilyKey[] = "Help/FallbackFontFamily";
|
||||
static const char kFontStyleKey[] = "Help/FallbackFontStyle";
|
||||
static const char kFontWeightKey[] = "Help/FallbackFontWeight";
|
||||
static const char kFontStyleNameKey[] = "Help/FallbackFontStyleName";
|
||||
static const char kFontSizeKey[] = "Help/FallbackFontSize";
|
||||
static const char kStartOptionKey[] = "Help/StartOption";
|
||||
static const char kContextHelpOptionKey[] = "Help/ContextHelpOption";
|
||||
@@ -68,8 +68,12 @@ static const char kLastShownPagesKey[] = "Help/LastShownPages";
|
||||
static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom";
|
||||
static const char kLastSelectedTabKey[] = "Help/LastSelectedTab";
|
||||
|
||||
// TODO remove some time after 4.1
|
||||
static const char kFontStyleKey[] = "Help/FallbackFontStyle";
|
||||
static const char kFontWeightKey[] = "Help/FallbackFontWeight";
|
||||
static const QFont::Style kDefaultFallbackFontStyle = QFont::StyleNormal;
|
||||
static const int kDefaultFallbackFontWeight = QFont::Normal;
|
||||
|
||||
static const int kDefaultFallbackFontSize = 14;
|
||||
|
||||
static QString defaultFallbackFontFamily()
|
||||
@@ -81,6 +85,13 @@ static QString defaultFallbackFontFamily()
|
||||
return "Arial";
|
||||
}
|
||||
|
||||
static QString defaultFallbackFontStyleName(const QString &fontFamily)
|
||||
{
|
||||
const QStringList styles = QFontDatabase().styles(fontFamily);
|
||||
QTC_ASSERT(!styles.isEmpty(), return "Regular");
|
||||
return styles.first();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void setOrRemoveSetting(const char *key, const T &value, const T &defaultValue)
|
||||
{
|
||||
@@ -138,19 +149,32 @@ QFont LocalHelpManager::fallbackFont()
|
||||
{
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
const QString family = settings->value(kFontFamilyKey, defaultFallbackFontFamily()).toString();
|
||||
const int size = settings->value(kFontSizeKey, kDefaultFallbackFontSize).toInt();
|
||||
QFont font(family, size);
|
||||
// TODO remove reading of old settings some time after 4.1
|
||||
if (settings->contains(kFontStyleKey) && settings->contains(kFontWeightKey)) {
|
||||
const QFont::Style style = QFont::Style(settings->value(kFontStyleKey, kDefaultFallbackFontStyle).toInt());
|
||||
const int weight = settings->value(kFontWeightKey, kDefaultFallbackFontWeight).toInt();
|
||||
const int size = settings->value(kFontSizeKey, kDefaultFallbackFontSize).toInt();
|
||||
QFont font(family, size, weight);
|
||||
font.setStyle(style);
|
||||
font.setWeight(weight);
|
||||
} else {
|
||||
const QString styleName = settings->value(kFontStyleNameKey,
|
||||
defaultFallbackFontStyleName(font.family())).toString();
|
||||
font.setStyleName(styleName);
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
void LocalHelpManager::setFallbackFont(const QFont &font)
|
||||
{
|
||||
{
|
||||
// TODO remove removal of old settings some time after 4.1
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
settings->remove(kFontStyleKey);
|
||||
settings->remove(kFontWeightKey);
|
||||
}
|
||||
setOrRemoveSetting(kFontFamilyKey, font.family(), defaultFallbackFontFamily());
|
||||
setOrRemoveSetting(kFontStyleKey, font.style(), kDefaultFallbackFontStyle);
|
||||
setOrRemoveSetting(kFontWeightKey, font.weight(), kDefaultFallbackFontWeight);
|
||||
setOrRemoveSetting(kFontStyleNameKey, font.styleName(), defaultFallbackFontStyleName(font.family()));
|
||||
setOrRemoveSetting(kFontSizeKey, font.pointSize(), kDefaultFallbackFontSize);
|
||||
emit m_instance->fallbackFontChanged(font);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user