From 9bd3c7d8f53e1c98baba52dc3d2acc8aa82bbd45 Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Fri, 16 Apr 2010 12:54:49 +0200
Subject: [PATCH] Added logic to handle fonts where QtFontDatabase returns an
 empty list of point-sizes.

The added logic is that if the font has more than one style, to ask for the point-sizes
of the first style. If that's also empty, return the list of standard point-sizes.

Task-number: QTCREATORBUG-1153
---
 src/plugins/texteditor/fontsettingspage.cpp | 20 ++++++++++++++++++--
 src/plugins/texteditor/fontsettingspage.h   |  2 ++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp
index b89b7e109a0..0f9f8c9e221 100644
--- a/src/plugins/texteditor/fontsettingspage.cpp
+++ b/src/plugins/texteditor/fontsettingspage.cpp
@@ -382,8 +382,7 @@ void FontSettingsPage::updatePointSizes()
             oldSize = d_ptr->m_value.fontSize();
         d_ptr->ui.sizeComboBox->clear();
     }
-    QFontDatabase db;
-    const QList<int> sizeLst = db.pointSizes(d_ptr->ui.familyComboBox->currentText());
+    const QList<int> sizeLst = pointSizesForSelectedFont();
     int idx = 0;
     int i = 0;
     for (; i < sizeLst.count(); ++i) {
@@ -395,6 +394,23 @@ void FontSettingsPage::updatePointSizes()
         d_ptr->ui.sizeComboBox->setCurrentIndex(idx);
 }
 
+QList<int> FontSettingsPage::pointSizesForSelectedFont() const
+{
+    QFontDatabase db;
+    const QString familyName = d_ptr->ui.familyComboBox->currentText();
+    QList<int> sizeLst = db.pointSizes(familyName);
+    if (!sizeLst.isEmpty())
+        return sizeLst;
+
+    QStringList styles = db.styles(familyName);
+    if (!styles.isEmpty())
+        sizeLst = db.pointSizes(familyName, styles.first());
+    if (sizeLst.isEmpty())
+        sizeLst = QFontDatabase::standardSizes();
+
+    return sizeLst;
+}
+
 void FontSettingsPage::fontSizeSelected(const QString &sizeString)
 {
     bool ok = true;
diff --git a/src/plugins/texteditor/fontsettingspage.h b/src/plugins/texteditor/fontsettingspage.h
index d7255579780..9269d6bcac2 100644
--- a/src/plugins/texteditor/fontsettingspage.h
+++ b/src/plugins/texteditor/fontsettingspage.h
@@ -36,6 +36,7 @@
 
 #include "texteditoroptionspage.h"
 
+#include <QtCore/QList>
 #include <QtCore/QString>
 
 QT_BEGIN_NAMESPACE
@@ -117,6 +118,7 @@ private slots:
 private:
     void maybeSaveColorScheme();
     void updatePointSizes();
+    QList<int> pointSizesForSelectedFont() const;
     void refreshColorSchemeList();
 
     Internal::FontSettingsPagePrivate *d_ptr;
-- 
GitLab