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>
This commit is contained in:
parent
587a15739b
commit
64a2e00e37
@ -163,7 +163,11 @@ class Q_GUI_EXPORT QFontDialogOptions
|
||||
public:
|
||||
enum FontDialogOption {
|
||||
NoButtons = 0x00000001,
|
||||
DontUseNativeDialog = 0x00000002
|
||||
DontUseNativeDialog = 0x00000002,
|
||||
ScalableFonts = 0x00000004,
|
||||
NonScalableFonts = 0x00000008,
|
||||
MonospacedFonts = 0x00000010,
|
||||
ProportionalFonts = 0x00000020
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)
|
||||
|
@ -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()
|
||||
*/
|
||||
|
@ -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)
|
||||
|
@ -67,12 +67,20 @@ FontDialogPanel::FontDialogPanel(QWidget *parent)
|
||||
, m_fontSizeBox(new QDoubleSpinBox)
|
||||
, m_noButtons(new QCheckBox(tr("Don't display OK/Cancel buttons")))
|
||||
, m_dontUseNativeDialog(new QCheckBox(tr("Don't use native dialog")))
|
||||
, m_scalableFilter(new QCheckBox(tr("Filter scalable fonts")))
|
||||
, m_nonScalableFilter(new QCheckBox(tr("Filter non scalable fonts")))
|
||||
, m_monospacedFilter(new QCheckBox(tr("Filter monospaced fonts")))
|
||||
, m_proportionalFilter(new QCheckBox(tr("Filter proportional fonts")))
|
||||
{
|
||||
// Options
|
||||
QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"), this);
|
||||
QVBoxLayout *optionsLayout = new QVBoxLayout(optionsGroupBox);
|
||||
optionsLayout->addWidget(m_noButtons);
|
||||
optionsLayout->addWidget(m_dontUseNativeDialog);
|
||||
optionsLayout->addWidget(m_scalableFilter);
|
||||
optionsLayout->addWidget(m_nonScalableFilter);
|
||||
optionsLayout->addWidget(m_monospacedFilter);
|
||||
optionsLayout->addWidget(m_proportionalFilter);
|
||||
|
||||
// Font
|
||||
QGroupBox *fontGroupBox = new QGroupBox(tr("Font"), this);
|
||||
@ -201,6 +209,10 @@ void FontDialogPanel::applySettings(QFontDialog *d) const
|
||||
{
|
||||
d->setOption(QFontDialog::NoButtons, m_noButtons->isChecked());
|
||||
d->setOption(QFontDialog::DontUseNativeDialog, m_dontUseNativeDialog->isChecked());
|
||||
d->setOption(QFontDialog::ScalableFonts, m_scalableFilter->isChecked());
|
||||
d->setOption(QFontDialog::NonScalableFonts, m_nonScalableFilter->isChecked());
|
||||
d->setOption(QFontDialog::MonospacedFonts, m_monospacedFilter->isChecked());
|
||||
d->setOption(QFontDialog::ProportionalFonts, m_proportionalFilter->isChecked());
|
||||
|
||||
QFont font = m_fontFamilyBox->currentFont();
|
||||
font.setPointSizeF(m_fontSizeBox->value());
|
||||
|
@ -77,6 +77,10 @@ private:
|
||||
QDoubleSpinBox *m_fontSizeBox;
|
||||
QCheckBox *m_noButtons;
|
||||
QCheckBox *m_dontUseNativeDialog;
|
||||
QCheckBox *m_scalableFilter;
|
||||
QCheckBox *m_nonScalableFilter;
|
||||
QCheckBox *m_monospacedFilter;
|
||||
QCheckBox *m_proportionalFilter;
|
||||
QPushButton *m_deleteNonModalDialogButton;
|
||||
QPushButton *m_deleteModalDialogButton;
|
||||
QString m_result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user