diff options
author | Kevin Ottens <ervin@kde.org> | 2013-04-29 14:18:40 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-13 12:11:21 +0200 |
commit | 64a2e00e376888d5cb29afc461ac2ad69862f074 (patch) | |
tree | f48fbe2132a6b254ca804290338e3bc2b78010ea /src/widgets | |
parent | 587a15739b6b225c16ef6cb58f651e40e97687ca (diff) |
Allow to filter the type of fonts displayed
QFontComboBox had convenient filtering options but somehow not
QFontDialog, so provide the same type of flags and a similar behavior.
Change-Id: Ia8efabc60ae795673c772ff8ed63fd49244a5bb9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: David Faure (KDE) <faure@kde.org>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/dialogs/qfontdialog.cpp | 28 | ||||
-rw-r--r-- | src/widgets/dialogs/qfontdialog.h | 6 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index 313b475f1f..b989ea7c86 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -479,7 +479,22 @@ void QFontDialogPrivate::updateFamilies() enum match_t { MATCH_NONE = 0, MATCH_LAST_RESORT = 1, MATCH_APP = 2, MATCH_FAMILY = 3 }; - QStringList familyNames = fdb.families(writingSystem); + const QFontDialog::FontDialogOptions scalableMask = (QFontDialog::ScalableFonts | QFontDialog::NonScalableFonts); + const QFontDialog::FontDialogOptions spacingMask = (QFontDialog::ProportionalFonts | QFontDialog::MonospacedFonts); + const QFontDialog::FontDialogOptions options = q->options(); + + QStringList familyNames; + foreach (const QString &family, fdb.families(writingSystem)) { + if ((options & scalableMask) && (options & scalableMask) != scalableMask) { + if (bool(options & QFontDialog::ScalableFonts) != fdb.isSmoothlyScalable(family)) + continue; + } + if ((options & spacingMask) && (options & spacingMask) != spacingMask) { + if (bool(options & QFontDialog::MonospacedFonts) != fdb.isFixedPitch(family)) + continue; + } + familyNames << family; + } familyList->model()->setStringList(familyNames); @@ -837,10 +852,21 @@ QFont QFontDialog::selectedFont() const This enum specifies various options that affect the look and feel of a font dialog. + For instance, it allows to specify which type of font should be + displayed. If none are specified all fonts available will be listed. + + Note that the font filtering options might not be supported on some + platforms (e.g. Mac). They are always supported by the non native + dialog (used on Windows or Linux). + \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".) \value DontUseNativeDialog Use Qt's standard font dialog on the Mac instead of Apple's native font panel. (Currently, the native dialog is never used, but this is likely to change in future Qt releases.) + \value ScalableFonts Show scalable fonts + \value NonScalableFonts Show non scalable fonts + \value MonospacedFonts Show monospaced fonts + \value ProportionalFonts Show proportional fonts \sa options, setOption(), testOption() */ diff --git a/src/widgets/dialogs/qfontdialog.h b/src/widgets/dialogs/qfontdialog.h index c2d930bc1e..9956987cfe 100644 --- a/src/widgets/dialogs/qfontdialog.h +++ b/src/widgets/dialogs/qfontdialog.h @@ -64,7 +64,11 @@ class Q_WIDGETS_EXPORT QFontDialog : public QDialog public: enum FontDialogOption { NoButtons = 0x00000001, - DontUseNativeDialog = 0x00000002 + DontUseNativeDialog = 0x00000002, + ScalableFonts = 0x00000004, + NonScalableFonts = 0x00000008, + MonospacedFonts = 0x00000010, + ProportionalFonts = 0x00000020 }; Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption) |