From e32947d25245bdf5ca9b969e82c4e66de48957bb Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 25 Nov 2020 14:00:11 +0100 Subject: Make adjustments for using QFont::setFamilies() Since we only depend on using setFamilies() now instead of setFamily() then we can rely on the fact that it will be resolved correctly, so we can remove the code that was ensuring that family() would take precedence if families() was empty. Change-Id: Iea1464ec840dc76c04a4acae445cab367e03d3ca Reviewed-by: Volker Hilsheimer --- src/imports/controls/imagine/qquickimaginetheme.cpp | 2 +- src/imports/controls/material/qquickmaterialtheme.cpp | 19 ++++++++++--------- .../controls/universal/qquickuniversaltheme.cpp | 8 ++++---- .../qstyle/windows/qquickwindowsvistastyle.cpp | 4 ++-- src/quickcontrols2/qquickstyle.cpp | 2 +- src/quicktemplates2/qquickapplicationwindow.cpp | 3 --- src/quicktemplates2/qquickcontrol.cpp | 6 ------ src/quicktemplates2/qquicklabel.cpp | 3 --- src/quicktemplates2/qquicktextarea.cpp | 3 --- src/quicktemplates2/qquicktextfield.cpp | 3 --- src/quicktemplates2/qquicktheme.cpp | 2 -- tests/auto/font/tst_font.cpp | 6 +++--- .../tst_qquickmaterialstyleconf.cpp | 2 +- .../tst_qquickuniversalstyleconf.cpp | 2 +- 14 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/imports/controls/imagine/qquickimaginetheme.cpp b/src/imports/controls/imagine/qquickimaginetheme.cpp index a9722fa5..7bae036a 100644 --- a/src/imports/controls/imagine/qquickimaginetheme.cpp +++ b/src/imports/controls/imagine/qquickimaginetheme.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE void QQuickImagineTheme::initialize(QQuickTheme *theme) { QFont systemFont; - systemFont.setFamily(QLatin1String("Open Sans")); + systemFont.setFamilies(QStringList{QLatin1String("Open Sans")}); theme->setFont(QQuickTheme::System, systemFont); const QColor accentColor = QColor::fromRgb(0x4fc1e9); diff --git a/src/imports/controls/material/qquickmaterialtheme.cpp b/src/imports/controls/material/qquickmaterialtheme.cpp index f42c0a03..aec9e232 100644 --- a/src/imports/controls/material/qquickmaterialtheme.cpp +++ b/src/imports/controls/material/qquickmaterialtheme.cpp @@ -55,22 +55,23 @@ void QQuickMaterialTheme::initialize(QQuickTheme *theme) QFont editorFont; QFont font; - font.setFamily(QLatin1String("Roboto")); + font.setFamilies(QStringList{QLatin1String("Roboto")}); QString family = QFontInfo(font).family(); if (family != QLatin1String("Roboto")) { - font.setFamily(QLatin1String("Noto")); + font.setFamilies(QStringList{QLatin1String("Noto")}); family = QFontInfo(font).family(); } if (family == QLatin1String("Roboto") || family == QLatin1String("Noto")) { - systemFont.setFamily(family); - buttonFont.setFamily(family); - toolTipFont.setFamily(family); - itemViewFont.setFamily(family); - listViewFont.setFamily(family); - menuItemFont.setFamily(family); - editorFont.setFamily(family); + const QStringList families{family}; + systemFont.setFamilies(families); + buttonFont.setFamilies(families); + toolTipFont.setFamilies(families); + itemViewFont.setFamilies(families); + listViewFont.setFamilies(families); + menuItemFont.setFamilies(families); + editorFont.setFamilies(families); } const bool dense = QQuickMaterialStyle::variant() == QQuickMaterialStyle::Dense; diff --git a/src/imports/controls/universal/qquickuniversaltheme.cpp b/src/imports/controls/universal/qquickuniversaltheme.cpp index 041dce9e..46f7c52e 100644 --- a/src/imports/controls/universal/qquickuniversaltheme.cpp +++ b/src/imports/controls/universal/qquickuniversaltheme.cpp @@ -49,10 +49,10 @@ void QQuickUniversalTheme::initialize(QQuickTheme *theme) const QFont font(QLatin1String("Segoe UI")); if (QFontInfo(font).family() == QLatin1String("Segoe UI")) { - const QString family = font.family(); - systemFont.setFamily(family); - groupBoxTitleFont.setFamily(family); - tabButtonFont.setFamily(family); + const QStringList families{font.family()}; + systemFont.setFamilies(families); + groupBoxTitleFont.setFamilies(families); + tabButtonFont.setFamilies(families); } systemFont.setPixelSize(15); diff --git a/src/imports/nativestyle/qstyle/windows/qquickwindowsvistastyle.cpp b/src/imports/nativestyle/qstyle/windows/qquickwindowsvistastyle.cpp index c3a567bd..512f8291 100644 --- a/src/imports/nativestyle/qstyle/windows/qquickwindowsvistastyle.cpp +++ b/src/imports/nativestyle/qstyle/windows/qquickwindowsvistastyle.cpp @@ -2316,7 +2316,7 @@ void QWindowsVistaStyle::polish(QWidget *widget) #if QT_CONFIG(commandlinkbutton) else if (qobject_cast(widget)) { QFont buttonFont = widget->font(); - buttonFont.setFamily(QLatin1String("Segoe UI")); + buttonFont.setFamilies(QStringList{QLatin1String("Segoe UI")}); widget->setFont(buttonFont); } #endif // QT_CONFIG(commandlinkbutton) @@ -2401,7 +2401,7 @@ void QWindowsVistaStyle::unpolish(QWidget *widget) else if (qobject_cast(widget)) { QFont font = QApplication::font("QCommandLinkButton"); QFont widgetFont = widget->font(); - widgetFont.setFamily(font.family()); //Only family set by polish + widgetFont.setFamilies(font.families()); //Only family set by polish widget->setFont(widgetFont); } #endif // QT_CONFIG(commandlinkbutton) diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 40cbce2d..60c5397f 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -346,7 +346,7 @@ const QFont *QQuickStylePrivate::readFont(const QSharedPointer &setti QFont f; settings->beginGroup(QStringLiteral("Font")); - readValue(settings, QStringLiteral("Family"), [&f](const QVariant &var) { f.setFamily(var.toString()); }); + readValue(settings, QStringLiteral("Family"), [&f](const QVariant &var) { f.setFamilies(QStringList{var.toString()}); }); readValue(settings, QStringLiteral("PointSize"), [&f](const QVariant &var) { f.setPointSizeF(var.toReal()); }); readValue(settings, QStringLiteral("PixelSize"), [&f](const QVariant &var) { f.setPixelSize(var.toInt()); }); readValue(settings, QStringLiteral("StyleHint"), [&f](const QVariant &var) { f.setStyleHint(toEnumValue(var.toInt())); }); diff --git a/src/quicktemplates2/qquickapplicationwindow.cpp b/src/quicktemplates2/qquickapplicationwindow.cpp index c825a063..d4e0a769 100644 --- a/src/quicktemplates2/qquickapplicationwindow.cpp +++ b/src/quicktemplates2/qquickapplicationwindow.cpp @@ -615,9 +615,6 @@ void QQuickApplicationWindow::setFont(const QFont &font) return; QFont resolvedFont = font.resolve(QQuickTheme::font(QQuickTheme::System)); - // See comment in QQuickControlPrivate::inheritFont - if (font.families().isEmpty()) - resolvedFont.setFamilies(QStringList()); d->setFont_helper(resolvedFont); } diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 72d2f794..c07a097b 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -564,12 +564,6 @@ void QQuickControlPrivate::inheritFont(const QFont &font) const QFont defaultFont = q->defaultFont(); QFont resolvedFont = parentFont.resolve(defaultFont); - // Since resolving the font will put the family() into the - // families() list if it is empty then we need to unset it - // so it does not act as if the font has changed (when it - // has not actually changed) - if (defaultFont.families().isEmpty()) - resolvedFont.setFamilies(QStringList()); setFont_helper(resolvedFont); } diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index 183b0f80..2cf3be16 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -184,9 +184,6 @@ void QQuickLabelPrivate::inheritFont(const QFont &font) const QFont defaultFont = QQuickTheme::font(QQuickTheme::Label); QFont resolvedFont = parentFont.resolve(defaultFont); - // See comment in QQuickControlPrivate::inheritFont - if (defaultFont.families().isEmpty()) - resolvedFont.setFamilies(QStringList()); setFont_helper(resolvedFont); } diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index a740447f..bcc08c05 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -264,9 +264,6 @@ void QQuickTextAreaPrivate::inheritFont(const QFont &font) const QFont defaultFont = QQuickTheme::font(QQuickTheme::TextArea); QFont resolvedFont = parentFont.resolve(defaultFont); - // See comment in QQuickControlPrivate::inheritFont - if (defaultFont.families().isEmpty()) - resolvedFont.setFamilies(QStringList()); setFont_helper(resolvedFont); } diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index 47026e1b..06cbd5a2 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -226,9 +226,6 @@ void QQuickTextFieldPrivate::inheritFont(const QFont &font) const QFont defaultFont = QQuickTheme::font(QQuickTheme::TextField); QFont resolvedFont = parentFont.resolve(defaultFont); - // See comment in QQuickControlPrivate::inheritFont - if (defaultFont.families().isEmpty()) - resolvedFont.setFamilies(QStringList()); setFont_helper(resolvedFont); } diff --git a/src/quicktemplates2/qquicktheme.cpp b/src/quicktemplates2/qquicktheme.cpp index b80e87e6..5ddc6f30 100644 --- a/src/quicktemplates2/qquicktheme.cpp +++ b/src/quicktemplates2/qquicktheme.cpp @@ -166,8 +166,6 @@ void QQuickTheme::setFont(Scope scope, const QFont &font) { Q_D(QQuickTheme); d->fonts[scope] = QSharedPointer::create(d->defaultFont ? d->defaultFont->resolve(font) : font); - // See comment in QQuickControlPrivate::inheritFont - d->fonts[scope]->setFamilies(QStringList()); } void QQuickTheme::setPalette(Scope scope, const QPalette &palette) diff --git a/tests/auto/font/tst_font.cpp b/tests/auto/font/tst_font.cpp index aeaa49f8..976658b5 100644 --- a/tests/auto/font/tst_font.cpp +++ b/tests/auto/font/tst_font.cpp @@ -124,7 +124,7 @@ void tst_font::font_data() QFont customFont; customFont.setCapitalization(QFont::AllUppercase); - customFont.setFamily("Courier"); + customFont.setFamilies(QStringList{QLatin1String("Courier")}); customFont.setItalic(true); customFont.setPixelSize(60); customFont.setStrikeOut(true); @@ -198,7 +198,7 @@ void tst_font::inheritance() QCOMPARE(grandChild->property("font").value(), QFont()); QFont childFont; - childFont.setFamily("Arial"); + childFont.setFamilies(QStringList{QLatin1String("Arial")}); childFont.setPixelSize(80); childFont.setItalic(true); child->setProperty("font", childFont); @@ -206,7 +206,7 @@ void tst_font::inheritance() QCOMPARE(grandChild->property("font").value(), childFont); QFont grandChildFont(childFont); - grandChildFont.setFamily("Times New Roman"); + grandChildFont.setFamilies(QStringList{QLatin1String("Times New Roman")}); grandChildFont.setUnderline(true); grandChild->setProperty("font", grandChildFont); QCOMPARE(child->property("font").value(), childFont); diff --git a/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp b/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp index 7612b99b..e0fd8fef 100644 --- a/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp +++ b/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp @@ -60,7 +60,7 @@ void tst_qquickmaterialstyleconf::conf() QVERIFY2(helper.ready, helper.failureMessage()); QFont customFont; - customFont.setFamily("Courier"); + customFont.setFamilies(QStringList{QLatin1String("Courier")}); customFont.setPixelSize(22); QQuickApplicationWindow *window = helper.appWindow; diff --git a/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp b/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp index 08eae67c..bef3b1cd 100644 --- a/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp +++ b/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp @@ -57,7 +57,7 @@ void tst_qquickuniversalstyleconf::conf() QVERIFY2(helper.ready, helper.failureMessage()); QFont customFont; - customFont.setFamily("Courier"); + customFont.setFamilies(QStringList{QLatin1String("Courier")}); customFont.setPixelSize(22); QQuickApplicationWindow *window = helper.appWindow; -- cgit v1.2.3