Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicklabsplatformfontdialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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
6
7#if QT_DEPRECATED_SINCE(6, 9)
8
9QT_BEGIN_NAMESPACE
10
11/*!
12 \qmltype FontDialog
13 \inherits Dialog
14//! \nativetype QQuickLabsPlatformFontDialog
15 \inqmlmodule Qt.labs.platform
16 \since 5.8
17 \deprecated [6.9] Use QtQuick.Dialogs::FontDialog instead.
18 \brief A native font dialog.
19
20 The FontDialog type provides a QML API for native platform font dialogs.
21
22 \image {qtlabsplatform-fontdialog-gtk.png} {A native font dialog}
23
24 To show a font dialog, construct an instance of FontDialog, set the
25 desired properties, and call \l {Dialog::}{open()}. The \l currentFont
26 property can be used to determine the currently selected font in the
27 dialog. The \l font property is updated only after the final selection
28 has been made by accepting the dialog.
29
30 \code
31 MenuItem {
32 text: "Font"
33 onTriggered: fontDialog.open()
34 }
35
36 FontDialog {
37 id: fontDialog
38 currentFont.family: document.font
39 }
40
41 MyDocument {
42 id: document
43 font: fontDialog.font
44 }
45 \endcode
46
47 \section2 Availability
48
49 A native platform font dialog is currently available on the following platforms:
50
51 \list
52 \li iOS
53 \li Linux (when running with the GTK+ platform theme)
54 \li macOS
55 \endlist
56
57 \input includes/widgets.qdocinc 1
58
59 \labs
60
61 \sa QtQuick.Dialogs::FontDialog
62*/
63
64QQuickLabsPlatformFontDialog::QQuickLabsPlatformFontDialog(QObject *parent)
65 : QQuickLabsPlatformDialog(QPlatformTheme::FontDialog, parent),
66 m_options(QFontDialogOptions::create())
67{
68}
69
70/*!
71 \qmlproperty font Qt.labs.platform::FontDialog::font
72
73 This property holds the final accepted font.
74
75 Unlike the \l currentFont property, the \c font property is not updated
76 while the user is selecting fonts in the dialog, but only after the final
77 selection has been made. That is, when the user has clicked \uicontrol OK
78 to accept a font. Alternatively, the \l {Dialog::}{accepted()} signal
79 can be handled to get the final selection.
80
81 \sa currentFont, {Dialog::}{accepted()}
82*/
83QFont QQuickLabsPlatformFontDialog::font() const
84{
85 return m_font;
86}
87
88void QQuickLabsPlatformFontDialog::setFont(const QFont &font)
89{
90 if (m_font == font)
91 return;
92
93 m_font = font;
94 setCurrentFont(font);
95 emit fontChanged();
96}
97
98/*!
99 \qmlproperty font Qt.labs.platform::FontDialog::currentFont
100
101 This property holds the currently selected font in the dialog.
102
103 Unlike the \l font property, the \c currentFont property is updated
104 while the user is selecting fonts in the dialog, even before the final
105 selection has been made.
106
107 \sa font
108*/
109QFont QQuickLabsPlatformFontDialog::currentFont() const
110{
111 if (QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(handle()))
112 return fontDialog->currentFont();
113 return m_currentFont;
114}
115
116void QQuickLabsPlatformFontDialog::setCurrentFont(const QFont &font)
117{
118 if (QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(handle()))
119 fontDialog->setCurrentFont(font);
120 m_currentFont = font;
121}
122
123/*!
124 \qmlproperty flags Qt.labs.platform::FontDialog::options
125
126 This property holds the various options that affect the look and feel of the dialog.
127
128 By default, all options are disabled.
129
130 Options should be set before showing the dialog. Setting them while the dialog is
131 visible is not guaranteed to have an immediate effect on the dialog (depending on
132 the option and on the platform).
133
134 Available options:
135 \value FontDialog.ScalableFonts Show scalable fonts.
136 \value FontDialog.NonScalableFonts Show non-scalable fonts.
137 \value FontDialog.MonospacedFonts Show monospaced fonts.
138 \value FontDialog.ProportionalFonts Show proportional fonts.
139 \value FontDialog.NoButtons Don't display \uicontrol OK and \uicontrol Cancel buttons (useful for "live dialogs").
140*/
141QFontDialogOptions::FontDialogOptions QQuickLabsPlatformFontDialog::options() const
142{
143 return m_options->options();
144}
145
146void QQuickLabsPlatformFontDialog::setOptions(QFontDialogOptions::FontDialogOptions options)
147{
148 if (options == m_options->options())
149 return;
150
151 m_options->setOptions(options);
152 emit optionsChanged();
153}
154
155bool QQuickLabsPlatformFontDialog::useNativeDialog() const
156{
157 return QQuickLabsPlatformDialog::useNativeDialog()
158 && !m_options->testOption(QFontDialogOptions::DontUseNativeDialog);
159}
160
161void QQuickLabsPlatformFontDialog::onCreate(QPlatformDialogHelper *dialog)
162{
163 if (QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(dialog)) {
164 connect(fontDialog, &QPlatformFontDialogHelper::currentFontChanged, this, &QQuickLabsPlatformFontDialog::currentFontChanged);
165 fontDialog->setOptions(m_options);
166 }
167}
168
169void QQuickLabsPlatformFontDialog::onShow(QPlatformDialogHelper *dialog)
170{
171 m_options->setWindowTitle(title());
172 if (QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(dialog))
173 fontDialog->setOptions(m_options);
174}
175
176void QQuickLabsPlatformFontDialog::accept()
177{
178 setFont(currentFont());
179 QQuickLabsPlatformDialog::accept();
180}
181
182QT_END_NAMESPACE
183
184#include "moc_qquicklabsplatformfontdialog_p.cpp"
185
186#endif // QT_DEPRECATED_SINCE(6, 9)