Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtCore/qloggingcategory.h>
7#include <QtGui/qwindow.h>
8#include <QtQml/qqmlcontext.h>
9#include <QtQml/qqmlinfo.h>
10#include <QtQuick/qquickwindow.h>
11#include <QtQuickTemplates2/private/qquickdialog_p.h>
12#include <QtQuickTemplates2/private/qquickpopup_p_p.h>
13#include <QtQuickTemplates2/private/qquickpopupanchors_p.h>
14
16
18
19Q_LOGGING_CATEGORY(lcQuickPlatformFontDialog, "qt.quick.dialogs.quickplatformfontdialog")
20
21
31{
32 qCDebug(lcQuickPlatformFontDialog)
33 << "creating non-native Qt Quick FontDialog with parent" << parent;
34
35 // Set a parent so that we get deleted if we can't be shown for whatever reason.
36 // Our eventual parent should be the window, though.
37 setParent(parent);
38
39 auto qmlContext = ::qmlContext(parent);
40 if (!qmlContext) {
41 qmlWarning(parent) << "No QQmlContext for QQuickPlatformFontDialog; can't create "
42 "non-native FontDialog implementation";
43 return;
44 }
45
46 const auto dialogQmlUrl = QUrl(QStringLiteral(
47 "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/FontDialog.qml"));
48
49 QQmlComponent fontDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
50 if (!fontDialogComponent.isReady()) {
51 qmlWarning(parent) << "Failed to load non-native FontDialog implementation:\n"
52 << fontDialogComponent.errorString();
53 return;
54 }
55
56 m_dialog = qobject_cast<QQuickFontDialogImpl *>(fontDialogComponent.create());
57
58 if (!m_dialog) {
59 qmlWarning(parent) << "Failed to create an instance of the non-native FontDialog:\n"
60 << fontDialogComponent.errorString();
61 return;
62 }
63
64 m_dialog->setParent(this);
65
68
71}
72
74{
75 return m_dialog;
76}
77
79{
80 if (m_dialog) {
81 if (!m_dialog->options())
83 m_dialog->setCurrentFont(font, true);
84 }
85}
86
88{
89 return m_dialog ? m_dialog->currentFont() : QFont();
90}
91
93{
94 qCWarning(lcQuickPlatformFontDialog)
95 << "exec() is not supported for the Qt Quick FontDialog fallback";
96}
97
99 QWindow *parent)
100{
101 qCDebug(lcQuickPlatformFontDialog)
102 << "show called with flags" << flags << "modality" << modality << "parent" << parent;
103
104 if (!isValid())
105 return false;
106
107 if (!parent)
108 return false;
109
110 auto quickWindow = qobject_cast<QQuickWindow *>(parent);
111 if (!quickWindow) {
112 qmlInfo(this->parent()) << "Parent window (" << parent
113 << ") of non-native dialog is not a QQuickWindow";
114 return false;
115 }
116 m_dialog->setParent(parent);
117 m_dialog->resetParentItem();
118
119 auto popupPrivate = QQuickPopupPrivate::get(m_dialog);
120 popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
121
122 QSharedPointer<QFontDialogOptions> options = QPlatformFontDialogHelper::options();
123 m_dialog->setTitle(options->windowTitle());
124 m_dialog->setOptions(options);
125
126 m_dialog->init();
127
128 m_dialog->open();
129 return true;
130}
131
133{
134 if (isValid())
135 m_dialog->close();
136}
137
139{
140 return m_dialog;
141}
142
144
145#include "moc_qquickplatformfontdialog_p.cpp"
\reentrant
Definition qfont.h:22
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
const QSharedPointer< QFontDialogOptions > & options() const
void currentFontChanged(const QFont &font)
The QQmlComponent class encapsulates a QML component definition.
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
void setTitle(const QString &title)
void accepted()
void rejected()
QSharedPointer< QFontDialogOptions > options() const
void currentFontChanged(const QFont &font)
void setCurrentFont(const QFont &font, bool selectInListViews=false)
void setOptions(const QSharedPointer< QFontDialogOptions > &options)
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override
QQuickFontDialogImpl * dialog() const
virtual void setCurrentFont(const QFont &font) override
virtual QFont currentFont() const override
static QQuickPopupPrivate * get(QQuickPopup *popup)
void close()
\qmlmethod void QtQuick.Controls::Popup::close()
void open()
\qmlmethod void QtQuick.Controls::Popup::open()
\inmodule QtCore
Definition qurl.h:94
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
WindowModality
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLbitfield flags
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define QStringLiteral(str)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
file setParent(multiPart)