1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Dialogs module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qquickplatformfontdialog_p.h"
41#include "qquickitem.h"
42
43#include <private/qguiapplication_p.h>
44#include <QWindow>
45#include <QQuickView>
46#include <QQuickWindow>
47
48QT_BEGIN_NAMESPACE
49
50/*!
51 \qmltype FontDialog
52 \instantiates QQuickPlatformFontDialog1
53 \inqmlmodule QtQuick.Dialogs
54 \ingroup qtquick-visual
55 \ingroup qtquickdialogs
56 \brief Dialog component for choosing a font.
57 \since 5.2
58
59 FontDialog allows the user to select a font. The dialog is initially
60 invisible. You need to set the properties as desired first, then set
61 \l visible to true or call \l open().
62
63 Here is a minimal example to open a font dialog and exit after the user
64 chooses a font:
65
66 \qml
67 import QtQuick 2.2
68 import QtQuick.Dialogs 1.1
69
70 FontDialog {
71 id: fontDialog
72 title: "Please choose a font"
73 font: Qt.font({ family: "Arial", pointSize: 24, weight: Font.Normal })
74 onAccepted: {
75 console.log("You chose: " + fontDialog.font)
76 Qt.quit()
77 }
78 onRejected: {
79 console.log("Canceled")
80 Qt.quit()
81 }
82 Component.onCompleted: visible = true
83 }
84 \endqml
85
86 A FontDialog window is automatically transient for its parent window. So
87 whether you declare the dialog inside an \l Item or inside a \l Window, the
88 dialog will appear centered over the window containing the item, or over
89 the Window that you declared.
90
91 The implementation of FontDialog will be a platform font dialog if
92 possible. If that isn't possible, then it will try to instantiate a
93 \l QFontDialog. If that also isn't possible, then it will fall back to a QML
94 implementation, DefaultFontDialog.qml. In that case you can customize the
95 appearance by editing this file. DefaultFontDialog.qml contains a Rectangle
96 to hold the dialog's contents, because certain embedded systems do not
97 support multiple top-level windows. When the dialog becomes visible, it
98 will automatically be wrapped in a Window if possible, or simply reparented
99 on top of the main window if there can only be one window.
100*/
101
102/*!
103 \qmlsignal QtQuick::Dialogs::FontDialog::accepted
104
105 The \a accepted signal is emitted when the user has finished using the
106 dialog. You can then inspect the \a font property to get the selection.
107
108 Example:
109
110 \qml
111 FontDialog {
112 onAccepted: { console.log("Selected font: " + font) }
113 }
114 \endqml
115
116 The corresponding handler is \c onAccepted.
117*/
118
119/*!
120 \qmlsignal QtQuick::Dialogs::FontDialog::rejected
121
122 The \a rejected signal is emitted when the user has dismissed the dialog,
123 either by closing the dialog window or by pressing the Cancel button.
124
125 The corresponding handler is \c onRejected.
126*/
127
128/*!
129 \class QQuickPlatformFontDialog1
130 \inmodule QtQuick.Dialogs
131 \internal
132
133 \brief The QQuickPlatformFontDialog1 class provides a font dialog
134
135 The dialog is implemented via the QQuickPlatformFontDialog1Helper when possible;
136 otherwise it falls back to a QFontDialog or a QML implementation.
137
138 \since 5.2
139*/
140
141/*!
142 Constructs a file dialog with parent window \a parent.
143*/
144QQuickPlatformFontDialog1::QQuickPlatformFontDialog1(QObject *parent) :
145 QQuickAbstractFontDialog(parent)
146{
147}
148
149/*!
150 Destroys the file dialog.
151*/
152QQuickPlatformFontDialog1::~QQuickPlatformFontDialog1()
153{
154 if (m_dlgHelper)
155 m_dlgHelper->hide();
156 delete m_dlgHelper;
157}
158
159QPlatformFontDialogHelper *QQuickPlatformFontDialog1::helper()
160{
161 QQuickItem *parentItem = qobject_cast<QQuickItem *>(object: parent());
162 if (parentItem)
163 m_parentWindow = parentItem->window();
164
165 if ( !m_dlgHelper && QGuiApplicationPrivate::platformTheme()->
166 usePlatformNativeDialog(type: QPlatformTheme::FontDialog) ) {
167 m_dlgHelper = static_cast<QPlatformFontDialogHelper *>(QGuiApplicationPrivate::platformTheme()
168 ->createPlatformDialogHelper(type: QPlatformTheme::FontDialog));
169 if (!m_dlgHelper)
170 return m_dlgHelper;
171 connect(sender: m_dlgHelper, SIGNAL(accept()), receiver: this, SLOT(accept()));
172 connect(sender: m_dlgHelper, SIGNAL(reject()), receiver: this, SLOT(reject()));
173 connect(sender: m_dlgHelper, SIGNAL(currentFontChanged(QFont)), receiver: this, SLOT(setCurrentFont(QFont)));
174 connect(sender: m_dlgHelper, SIGNAL(fontSelected(QFont)), receiver: this, SLOT(setFont(QFont)));
175 }
176
177 return m_dlgHelper;
178}
179
180/*!
181 \qmlproperty bool FontDialog::visible
182
183 This property holds whether the dialog is visible. By default this is
184 false.
185
186 \sa modality
187*/
188
189/*!
190 \qmlproperty Qt::WindowModality FontDialog::modality
191
192 Whether the dialog should be shown modal with respect to the window
193 containing the dialog's parent Item, modal with respect to the whole
194 application, or non-modal.
195
196 By default it is \c Qt.NonModal.
197
198 Modality does not mean that there are any blocking calls to wait for the
199 dialog to be accepted or rejected; it's only that the user will be
200 prevented from interacting with the parent window and/or the application
201 windows at the same time.
202
203 You probably need to write an onAccepted handler if you wish to change a
204 font after the user has pressed the OK button, or an onCurrentFontChanged
205 handler if you wish to react to every change the user makes while the
206 dialog is open.
207*/
208
209/*!
210 \qmlmethod void FontDialog::open()
211
212 Shows the dialog to the user. It is equivalent to setting \l visible to
213 true.
214*/
215
216/*!
217 \qmlmethod void FontDialog::close()
218
219 Closes the dialog.
220*/
221
222/*!
223 \qmlproperty string FontDialog::title
224
225 The title of the dialog window.
226*/
227
228/*!
229 \qmlproperty bool FontDialog::scalableFonts
230
231 Whether the dialog will show scalable fonts or not.
232*/
233
234/*!
235 \qmlproperty bool FontDialog::nonScalableFonts
236
237 Whether the dialog will show non scalable fonts or not.
238*/
239
240/*!
241 \qmlproperty bool FontDialog::monospacedFonts
242
243 Whether the dialog will show monospaced fonts or not.
244*/
245
246/*!
247 \qmlproperty bool FontDialog::proportionalFonts
248
249 Whether the dialog will show proportional fonts or not.
250*/
251
252/*!
253 \qmlproperty font FontDialog::font
254
255 The font which the user selected and accepted.
256*/
257
258/*!
259 \qmlproperty font FontDialog::currentFont
260
261 The font which the user selected.
262
263 \since 5.3
264*/
265
266QT_END_NAMESPACE
267

source code of qtquickcontrols/src/dialogs/qquickplatformfontdialog.cpp