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
qquickplatformfontdialog.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
"qquickplatformfontdialog_p.h"
6
7
#
include
<
QtCore
/
qloggingcategory
.
h
>
8
#
include
<
QtGui
/
qwindow
.
h
>
9
#
include
<
QtQml
/
qqmlcontext
.
h
>
10
#
include
<
QtQml
/
qqmlinfo
.
h
>
11
#
include
<
QtQml
/
qqmlcomponent
.
h
>
12
#
include
<
QtQuick
/
qquickwindow
.
h
>
13
#
include
<
QtQuickTemplates2
/
private
/
qquickdialog_p
.
h
>
14
#
include
<
QtQuickTemplates2
/
private
/
qquickdialog_p_p
.
h
>
15
#
include
<
QtQuickTemplates2
/
private
/
qquickpopup_p_p
.
h
>
16
#
include
<
QtQuickTemplates2
/
private
/
qquickpopupanchors_p
.
h
>
17
18
#
include
"qquickfontdialogimpl_p.h"
19
20
QT_BEGIN_NAMESPACE
21
22
Q_STATIC_LOGGING_CATEGORY(lcQuickPlatformFontDialog,
"qt.quick.dialogs.quickplatformfontdialog"
)
23
24
/*!
25
\class QQuickPlatformFontDialog
26
\internal
27
28
An interface that QQuickFontDialog can use to access the non-native Qt Quick FontDialog.
29
30
Both this and the native implementations are created in QQuickAbstractDialog::create().
31
32
*/
33
QQuickPlatformFontDialog::QQuickPlatformFontDialog(QObject *parent)
34
{
35
qCDebug(lcQuickPlatformFontDialog)
36
<<
"creating non-native Qt Quick FontDialog with parent"
<< parent;
37
38
// Set a parent so that we get deleted if we can't be shown for whatever reason.
39
// Our eventual parent should be the window, though.
40
setParent(parent);
41
42
auto
qmlContext = ::qmlContext(parent);
43
if
(!qmlContext) {
44
qmlWarning(parent) <<
"No QQmlContext for QQuickPlatformFontDialog; can't create "
45
"non-native FontDialog implementation"
;
46
return
;
47
}
48
49
const
auto
dialogQmlUrl = QUrl(QStringLiteral(
50
"qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/FontDialog.qml"
));
51
52
QQmlComponent fontDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
53
if
(!fontDialogComponent.isReady()) {
54
qmlWarning(parent) <<
"Failed to load non-native FontDialog implementation:\n"
55
<< fontDialogComponent.errorString();
56
return
;
57
}
58
59
m_dialog = qobject_cast<QQuickFontDialogImpl *>(fontDialogComponent.create());
60
61
if
(!m_dialog) {
62
qmlWarning(parent) <<
"Failed to create an instance of the non-native FontDialog:\n"
63
<< fontDialogComponent.errorString();
64
return
;
65
}
66
67
m_dialog->setParent(
this
);
68
69
connect(m_dialog, &QQuickDialog::accepted,
this
, &QPlatformDialogHelper::accept);
70
connect(m_dialog, &QQuickDialog::rejected,
this
, &QPlatformDialogHelper::reject);
71
72
connect(m_dialog, &QQuickFontDialogImpl::currentFontChanged,
73
this
, &QQuickPlatformFontDialog::currentFontChanged);
74
}
75
76
bool
QQuickPlatformFontDialog::isValid()
const
77
{
78
return
m_dialog;
79
}
80
81
void
QQuickPlatformFontDialog::setCurrentFont(
const
QFont &font)
82
{
83
if
(m_dialog) {
84
if
(!m_dialog->options())
85
m_dialog->setOptions(QPlatformFontDialogHelper::options());
86
m_dialog->setCurrentFont(font,
true
);
87
}
88
}
89
90
QFont QQuickPlatformFontDialog::currentFont()
const
91
{
92
return
m_dialog ? m_dialog->currentFont() : QFont();
93
}
94
95
void
QQuickPlatformFontDialog::exec()
96
{
97
qCWarning(lcQuickPlatformFontDialog)
98
<<
"exec() is not supported for the Qt Quick FontDialog fallback"
;
99
}
100
101
bool
QQuickPlatformFontDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality,
102
QWindow *parent)
103
{
104
qCDebug(lcQuickPlatformFontDialog)
105
<<
"show called with flags"
<< flags <<
"modality"
<< modality <<
"parent"
<< parent;
106
107
if
(!isValid())
108
return
false
;
109
110
if
(!parent)
111
return
false
;
112
113
auto
quickWindow = qobject_cast<QQuickWindow *>(parent);
114
if
(!quickWindow) {
115
qmlInfo(
this
->parent()) <<
"Parent window ("
<< parent
116
<<
") of non-native dialog is not a QQuickWindow"
;
117
return
false
;
118
}
119
m_dialog->setParent(parent);
120
m_dialog->resetParentItem();
121
122
auto
popupPrivate = QQuickPopupPrivate::get(m_dialog);
123
popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
124
popupPrivate->setPopupWindowFlags(flags);
125
126
QSharedPointer<QFontDialogOptions> options = QPlatformFontDialogHelper::options();
127
m_dialog->setTitle(options->windowTitle());
128
m_dialog->setOptions(options);
129
130
m_dialog->init();
131
m_dialog->setWindowModality(modality);
132
m_dialog->open();
133
return
true
;
134
}
135
136
void
QQuickPlatformFontDialog::hide()
137
{
138
if
(isValid())
139
m_dialog->close();
140
}
141
142
QQuickFontDialogImpl *QQuickPlatformFontDialog::dialog()
const
143
{
144
return
m_dialog;
145
}
146
147
QT_END_NAMESPACE
148
149
#
include
"moc_qquickplatformfontdialog_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickdialogs
quickdialogsquickimpl
qquickplatformfontdialog.cpp
Generated on
for Qt by
1.18.0