24QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
26 qCDebug(lcQuickPlatformColorDialog)
27 <<
"creating non-native Qt Quick ColorDialog with parent" << parent;
33 auto qmlContext = ::qmlContext(parent);
35 qmlWarning(parent) <<
"No QQmlContext for QQuickPlatformColorDialog; can't create "
36 "non-native ColorDialog implementation";
40 const auto dialogQmlUrl = QUrl(QStringLiteral(
41 "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/ColorDialog.qml"));
42 QQmlComponent colorDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
43 if (!colorDialogComponent.isReady()) {
44 qmlWarning(parent) <<
"Failed to load non-native ColorDialog implementation:\n"
45 << colorDialogComponent.errorString();
49 m_dialog = qobject_cast<QQuickColorDialogImpl *>(colorDialogComponent.create());
51 qmlWarning(parent) <<
"Failed to create an instance of the non-native ColorDialog:\n"
52 << colorDialogComponent.errorString();
56 m_dialog->setParent(
this);
58 connect(m_dialog, &QQuickDialog::accepted,
this, &QPlatformDialogHelper::accept);
59 connect(m_dialog, &QQuickDialog::rejected,
this, &QPlatformDialogHelper::reject);
61 connect(m_dialog, &QQuickColorDialogImpl::colorChanged,
this,
62 &QQuickPlatformColorDialog::currentColorChanged);
87bool QQuickPlatformColorDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality,
90 qCDebug(lcQuickPlatformColorDialog)
91 <<
"show called with flags" << flags <<
"modality" << modality <<
"parent" << parent;
93 if (!m_dialog || !parent)
96 auto quickWindow = qobject_cast<QQuickWindow *>(parent);
99 qmlInfo(
this->parent()) <<
"Parent window (" << parent
100 <<
") of non-native dialog is not a QQuickWindow";
104 m_dialog->setParent(parent);
105 m_dialog->resetParentItem();
107 auto popupPrivate = QQuickPopupPrivate::get(m_dialog);
108 popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
110 QSharedPointer<QColorDialogOptions> options = QPlatformColorDialogHelper::options();
112 m_dialog->setTitle(options->windowTitle());
113 m_dialog->setOptions(options);
114 m_dialog->setWindowModality(modality);