Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickfontdialog.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qquickfontdialog_p.h"
6
7
#
include
<
QtCore
/
qloggingcategory
.
h
>
8
#
if
QT_CONFIG
(
quick_listview
)
&&
QT_CONFIG
(
quick_draganddrop
)
9
#
include
<
QtQuickDialogs2QuickImpl
/
private
/
qquickplatformfontdialog_p
.
h
>
10
#
include
<
QtQuickDialogs2QuickImpl
/
private
/
qquickfontdialogimpl_p
.
h
>
11
#
endif
12
13
QT_BEGIN_NAMESPACE
14
15
/*!
16
\qmltype FontDialog
17
\inherits Dialog
18
//! \nativetype QQuickFontDialog
19
\inqmlmodule QtQuick.Dialogs
20
\since 6.2
21
\brief A font dialog.
22
23
The FontDialog type provides a QML API for font dialogs.
24
25
\image qtquickdialogs-fontdialog-gtk.png {The user is able to view and select different fonts via the font dialog}
26
27
To show a font dialog, construct an instance of FontDialog, set the
28
desired properties, and call \l {Dialog::}{open()}. The \l currentFont
29
property can be used to determine the currently selected font in the
30
dialog. The \l selectedFont property is updated only after the final selection
31
has been made by accepting the dialog.
32
33
\code
34
MenuItem {
35
text: "Font"
36
onTriggered: fontDialog.open()
37
}
38
39
FontDialog {
40
id: fontDialog
41
currentFont.family: document.font
42
}
43
44
MyDocument {
45
id: document
46
font: fontDialog.selectedFont
47
}
48
\endcode
49
50
\section2 Availability
51
52
A native platform font dialog is currently available on the following platforms:
53
54
\list
55
\li iOS
56
\li Linux (when running with the GTK+ platform theme)
57
\li macOS
58
\endlist
59
60
\include includes/fallback.qdocinc
61
*/
62
63
Q_LOGGING_CATEGORY(lcFontDialog,
"qt.quick.dialogs.fontdialog"
)
64
65
QQuickFontDialog::QQuickFontDialog(QObject *parent)
66
: QQuickAbstractDialog(QQuickDialogType::FontDialog, parent),
67
m_options(QFontDialogOptions::create())
68
{
69
}
70
71
/*!
72
\qmlproperty font QtQuick.Dialogs::FontDialog::currentFont
73
\deprecated [6.3] Use \l selectedFont instead.
74
75
This property holds the currently selected font in the dialog.
76
77
The \c currentFont property is updated while the user is selecting
78
fonts in the dialog, even before the final selection has been made.
79
80
\sa selectedFont
81
*/
82
83
QFont QQuickFontDialog::currentFont()
const
84
{
85
return
selectedFont();
86
}
87
88
void
QQuickFontDialog::setCurrentFont(
const
QFont &font)
89
{
90
setSelectedFont(font);
91
}
92
93
/*!
94
\qmlproperty font QtQuick.Dialogs::FontDialog::selectedFont
95
96
This property holds the currently selected font in the dialog.
97
98
The \c selectedFont property is updated while the user is selecting
99
fonts in the dialog, even before the final selection has been made.
100
101
The \l {Dialog::}{accepted()} signal can be handled to get the final selection.
102
When the user has clicked \uicontrol Select (or \uicontrol Open, depending on
103
platform) to accept a font, a signal handler for the
104
\l {Dialog::}{accepted()} signal can query the selectedFont property to
105
get the final font that was selected by the user.
106
107
\sa currentFont, {Dialog::}{accepted()}
108
*/
109
110
QFont QQuickFontDialog::selectedFont()
const
111
{
112
return
m_selectedFont;
113
}
114
115
void
QQuickFontDialog::setSelectedFont(
const
QFont &font)
116
{
117
if
(font == m_selectedFont)
118
return
;
119
120
m_selectedFont = font;
121
122
emit selectedFontChanged();
123
emit currentFontChanged();
124
}
125
126
/*!
127
\qmlproperty flags QtQuick.Dialogs::FontDialog::options
128
129
This property holds the various options that affect the look and feel of the dialog.
130
131
By default, no options are set, meaning all font types are shown and the dialog displays
132
standard \uicontrol Select and \uicontrol Cancel buttons.
133
134
Options should be set before showing the dialog. Setting them while the dialog is
135
visible is not guaranteed to have an immediate effect on the dialog (depending on
136
the option and on the platform).
137
138
Available options:
139
\value FontDialog.ScalableFonts Show scalable fonts.
140
\value FontDialog.NonScalableFonts Show non-scalable fonts.
141
\value FontDialog.MonospacedFonts Show monospaced fonts.
142
\value FontDialog.ProportionalFonts Show proportional fonts.
143
\value FontDialog.NoButtons Don't display \uicontrol Open and \uicontrol Cancel buttons (useful
144
for "live dialogs").
145
\value FontDialog.DontUseNativeDialog Forces the dialog to use a non-native quick implementation.
146
*/
147
148
QFontDialogOptions::FontDialogOptions QQuickFontDialog::options()
const
149
{
150
return
m_options->options();
151
}
152
153
void
QQuickFontDialog::setOptions(QFontDialogOptions::FontDialogOptions options)
154
{
155
if
(options == m_options->options())
156
return
;
157
158
m_options->setOptions(options);
159
emit optionsChanged();
160
}
161
162
void
QQuickFontDialog::resetOptions()
163
{
164
setOptions({});
165
}
166
167
bool
QQuickFontDialog::useNativeDialog()
const
168
{
169
return
QQuickAbstractDialog::useNativeDialog()
170
&& !(m_options->testOption(QFontDialogOptions::DontUseNativeDialog));
171
}
172
173
void
QQuickFontDialog::onCreate(QPlatformDialogHelper *dialog)
174
{
175
if
(QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(dialog)) {
176
connect(fontDialog, &QPlatformFontDialogHelper::currentFontChanged,
this
,
177
[
this
, fontDialog]() { setSelectedFont(fontDialog->currentFont()); });
178
connect(
this
, &QQuickFontDialog::selectedFontChanged,
this
,
179
[
this
, fontDialog]() { fontDialog->setCurrentFont(m_selectedFont); });
180
fontDialog->setOptions(m_options);
181
}
182
}
183
184
void
QQuickFontDialog::onShow(QPlatformDialogHelper *dialog)
185
{
186
m_options->setWindowTitle(title());
187
if
(QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(dialog)) {
188
fontDialog->setOptions(m_options);
// setOptions only assigns a member and isn't virtual
189
fontDialog->setCurrentFont(m_selectedFont);
190
}
191
#
if
QT_CONFIG
(
quick_listview
)
&&
QT_CONFIG
(
quick_draganddrop
)
192
if
(QQuickPlatformFontDialog *fontDialog = qobject_cast<QQuickPlatformFontDialog *>(dialog))
193
fontDialog->dialog()->setPopupType(m_popupType);
194
#
endif
195
196
QQuickAbstractDialog::onShow(dialog);
197
}
198
199
QT_END_NAMESPACE
200
201
#
include
"moc_qquickfontdialog_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickdialogs
quickdialogs
qquickfontdialog.cpp
Generated on
for Qt by
1.18.0