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 "qquickqfontdialog_p.h"
41#include "qquickitem.h"
42
43#include <private/qguiapplication_p.h>
44#include <private/qqmlcontext_p.h>
45#include <QWindow>
46#include <QQuickWindow>
47#include <QFontDialog>
48
49QT_BEGIN_NAMESPACE
50
51class QFontDialogHelper : public QPlatformFontDialogHelper
52{
53public:
54 QFontDialogHelper() :
55 QPlatformFontDialogHelper()
56 {
57 connect(sender: &m_dialog, SIGNAL(currentFontChanged(QFont)), receiver: this, SIGNAL(currentFontChanged(QFont)));
58 connect(sender: &m_dialog, SIGNAL(fontSelected(QFont)), receiver: this, SIGNAL(fontSelected(QFont)));
59 connect(sender: &m_dialog, SIGNAL(accepted()), receiver: this, SIGNAL(accept()));
60 connect(sender: &m_dialog, SIGNAL(rejected()), receiver: this, SIGNAL(reject()));
61 }
62
63 void setCurrentFont(const QFont &font) override { m_dialog.setCurrentFont(font); }
64 QFont currentFont() const override { return m_dialog.currentFont(); }
65
66 void exec() override { m_dialog.exec(); }
67
68 bool show(Qt::WindowFlags f, Qt::WindowModality m, QWindow *parent) override {
69 m_dialog.winId();
70 QWindow *window = m_dialog.windowHandle();
71 Q_ASSERT(window);
72 window->setTransientParent(parent);
73 window->setFlags(f);
74 m_dialog.windowHandle()->setTransientParent(parent);
75 m_dialog.windowHandle()->setFlags(f);
76 m_dialog.setWindowModality(m);
77 m_dialog.setWindowTitle(QPlatformFontDialogHelper::options()->windowTitle());
78 m_dialog.setOptions((QFontDialog::FontDialogOptions)((int)(QPlatformFontDialogHelper::options()->options())));
79 m_dialog.show();
80 return m_dialog.isVisible();
81 }
82
83 void hide() override { m_dialog.hide(); }
84
85private:
86 QFontDialog m_dialog;
87};
88
89/*!
90 \qmltype QtFontDialog
91 \instantiates QQuickQFontDialog
92 \inqmlmodule QtQuick.PrivateWidgets
93 \ingroup qtquick-visual
94 \brief Dialog component for choosing files from a local filesystem.
95 \since 5.2
96 \internal
97
98 QtFontDialog provides a means to instantiate and manage a QFontDialog.
99 It is not recommended to be used directly; it is an implementation
100 detail of \l FontDialog in the \l QtQuick.Dialogs module.
101
102 To use this type, you will need to import the module with the following line:
103 \code
104 import QtQuick.PrivateWidgets 1.1
105 \endcode
106*/
107
108/*!
109 \qmlsignal QtQuick::Dialogs::FontDialog::accepted
110
111 The \a accepted signal is emitted when the user has finished using the
112 dialog. You can then inspect the \a filePath or \a filePaths properties to
113 get the selection.
114
115 Example:
116
117 \qml
118 FontDialog {
119 onAccepted: { console.log("Selected file: " + filePath) }
120 }
121 \endqml
122
123 The corresponding handler is \c onAccepted.
124*/
125
126/*!
127 \qmlsignal QtQuick::Dialogs::FontDialog::rejected
128
129 The \a rejected signal is emitted when the user has dismissed the dialog,
130 either by closing the dialog window or by pressing the Cancel button.
131
132 The corresponding handler is \c onRejected.
133*/
134
135/*!
136 \class QQuickQFontDialog
137 \inmodule QtQuick.PrivateWidgets
138 \internal
139
140 \brief The QQuickQFontDialog class is a wrapper for a QFontDialog.
141
142 \since 5.2
143*/
144
145/*!
146 Constructs a file dialog with parent window \a parent.
147*/
148QQuickQFontDialog::QQuickQFontDialog(QObject *parent)
149 : QQuickAbstractFontDialog(parent)
150{
151}
152
153/*!
154 Destroys the file dialog.
155*/
156QQuickQFontDialog::~QQuickQFontDialog()
157{
158 if (m_dlgHelper)
159 m_dlgHelper->hide();
160 delete m_dlgHelper;
161}
162
163QPlatformFontDialogHelper *QQuickQFontDialog::helper()
164{
165 QQuickItem *parentItem = qobject_cast<QQuickItem *>(object: parent());
166 if (parentItem)
167 m_parentWindow = parentItem->window();
168
169 if (!m_dlgHelper) {
170 m_dlgHelper = new QFontDialogHelper();
171 connect(sender: m_dlgHelper, SIGNAL(currentFontChanged(QFont)), receiver: this, SLOT(setFont(QFont)));
172 connect(sender: m_dlgHelper, SIGNAL(fontSelected(QFont)), receiver: this, SLOT(setFont(QFont)));
173 connect(sender: m_dlgHelper, SIGNAL(accept()), receiver: this, SLOT(accept()));
174 connect(sender: m_dlgHelper, SIGNAL(reject()), receiver: this, SLOT(reject()));
175 }
176
177 return m_dlgHelper;
178}
179
180QT_END_NAMESPACE
181

source code of qtquickcontrols/src/widgets/qquickqfontdialog.cpp