KWidgetsAddons

kfontchooserdialog.cpp
1/*
2 SPDX-FileCopyrightText: 1996 Bernd Johannes Wuebben <wuebben@kde.org>
3 SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org>
4 SPDX-FileCopyrightText: 1999 Mario Weilguni <mweilguni@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "kfontchooserdialog.h"
10
11#include <QDialogButtonBox>
12#include <QPointer>
13#include <QVBoxLayout>
14
15class KFontChooserDialogPrivate
16{
17public:
18 KFontChooser *m_fontChooser = nullptr;
19};
20
22 : QDialog(parent)
23 , d(new KFontChooserDialogPrivate)
24{
25 setWindowTitle(tr("Select Font", "@title:window"));
26 d->m_fontChooser = new KFontChooser(flags, this);
27 d->m_fontChooser->setMinVisibleItems(8);
28 d->m_fontChooser->setObjectName(QStringLiteral("fontChooser"));
29
31
33 QVBoxLayout *mainLayout = new QVBoxLayout(this);
34 mainLayout->addWidget(d->m_fontChooser);
35 mainLayout->addWidget(buttonBox);
36
39}
40
41KFontChooserDialog::~KFontChooserDialog() = default;
42
43void KFontChooserDialog::setFont(const QFont &font, bool onlyFixed)
44{
45 d->m_fontChooser->setFont(font, onlyFixed);
46}
47
49{
50 return d->m_fontChooser->font();
51}
52
53// If the styleName property is set for a QFont, using setBold(true) would
54// lead to Qt using an "emboldended"/synthetic font style instead of using
55// the bold style provided by the font itself; the latter looks better than
56// the former, also accorgin to upstream, the styleName property is useful
57// for fancy font styles, so there is no point in setting it for "Regular"
58// fonts. For more details see:
59// https://bugreports.qt.io/browse/QTBUG-63792
60// https://bugs.kde.org/show_bug.cgi?id=378523
61static void stripRegularStyleName(QFont &font)
62{
63 if (font.weight() == QFont::Normal //
64 && (font.styleName() == QLatin1String("Regular") //
65 || font.styleName() == QLatin1String("Normal") //
66 || font.styleName() == QLatin1String("Book") //
67 || font.styleName() == QLatin1String("Roman"))) {
68 font.setStyleName(QString());
69 }
70}
71
72// static
74{
76 dialog->setObjectName(QStringLiteral("Font Selector"));
77 dialog->setFont(theFont, flags & KFontChooser::FixedFontsOnly);
78
79 const int result = dialog->exec();
80 if (result == Accepted) {
81 theFont = dialog->d->m_fontChooser->font();
82 diffFlags = dialog->d->m_fontChooser->fontDiffFlags();
83 stripRegularStyleName(theFont);
84 }
85 delete dialog;
86 return result;
87}
88
89// static
91{
93 dialog->setObjectName(QStringLiteral("Font Selector"));
94 dialog->setFont(theFont, flags & KFontChooser::FixedFontsOnly);
95
96 const int result = dialog->exec();
97 if (result == Accepted) {
98 theFont = dialog->d->m_fontChooser->font();
99 stripRegularStyleName(theFont);
100 }
101 delete dialog;
102 return result;
103}
104
105#include "moc_kfontchooserdialog.cpp"
void setFont(const QFont &font, bool onlyFixed=false)
Sets the currently selected font in the dialog.
void fontSelected(const QFont &font)
Emitted whenever the currently selected font changes.
static int getFontDiff(QFont &theFont, KFontChooser::FontDiffFlags &diffFlags, const KFontChooser::DisplayFlags &flags=KFontChooser::NoDisplayFlags, QWidget *parent=nullptr)
Creates a modal font difference dialog, lets the user choose a selection of changes that should be ma...
static int getFont(QFont &theFont, const KFontChooser::DisplayFlags &flags=KFontChooser::NoDisplayFlags, QWidget *parent=nullptr)
Creates a modal font dialog, lets the user choose a font, and returns when the dialog is closed.
KFontChooserDialog(const KFontChooser::DisplayFlags &flags=KFontChooser::NoDisplayFlags, QWidget *parent=nullptr)
Constructs a font selection dialog.
A font selection widget.
@ ShowDifferences
Display the font differences interfaces.
@ FixedFontsOnly
Only show monospaced/fixed-width fonts, excluding proportional fonts, (the checkbox to toggle showing...
void fontSelected(const QFont &font)
Emitted when the selected font changes.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void accept()
virtual void reject()
int result() const const
void setStyleName(const QString &styleName)
QString styleName() const const
Weight weight() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.