32QQuickPlatformFolderDialog::QQuickPlatformFolderDialog(QObject *parent)
34 qCDebug(lcQuickPlatformFolderDialog) <<
"creating non-native Qt Quick FolderDialog with parent" << parent;
40 auto qmlContext = ::qmlContext(parent);
42 qmlWarning(parent) <<
"No QQmlContext for QQuickPlatformFolderDialog; can't create non-native FolderDialog implementation";
46 const auto dialogQmlUrl = QUrl(QStringLiteral(
"qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/FolderDialog.qml"));
47 QQmlComponent folderDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
48 if (!folderDialogComponent.isReady()) {
49 qmlWarning(parent) <<
"Failed to load non-native FolderDialog implementation:\n" << folderDialogComponent.errorString();
52 m_dialog = qobject_cast<QQuickFolderDialogImpl*>(folderDialogComponent.create());
54 qmlWarning(parent) <<
"Failed to create an instance of the non-native FolderDialog:\n" << folderDialogComponent.errorString();
58 m_dialog->setParent(
this);
60 connect(m_dialog, &QQuickDialog::accepted,
this, &QPlatformDialogHelper::accept);
61 connect(m_dialog, &QQuickDialog::rejected,
this, &QPlatformDialogHelper::reject);
63 connect(m_dialog, &QQuickFolderDialogImpl::selectedFolderChanged,
this, &QQuickPlatformFolderDialog::currentChanged);
64 connect(m_dialog, &QQuickFolderDialogImpl::currentFolderChanged,
this, &QQuickPlatformFolderDialog::directoryEntered);
65 connect(m_dialog, &QQuickFolderDialogImpl::selectedFolderChanged,
this, &QQuickPlatformFolderDialog::fileSelected);
69 if (m_dialog->currentFolder().isEmpty())
70 m_dialog->setCurrentFolder(QUrl::fromLocalFile(QDir().absolutePath()));
131bool QQuickPlatformFolderDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
133 qCDebug(lcQuickPlatformFolderDialog) <<
"show called with flags" << flags <<
134 "modality" << modality <<
"parent" << parent;
141 auto quickWindow = qobject_cast<QQuickWindow*>(parent);
143 qmlInfo(
this->parent()) <<
"Parent window (" << parent <<
") of non-native dialog is not a QQuickWindow";
146 m_dialog->setParent(parent);
147 m_dialog->resetParentItem();
149 auto popupPrivate = QQuickPopupPrivate::get(m_dialog);
150 popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
152 QSharedPointer<QFileDialogOptions> options = QPlatformFileDialogHelper::options();
153 m_dialog->setTitle(options->windowTitle());
154 m_dialog->setOptions(options);
155 m_dialog->setAcceptLabel(options->isLabelExplicitlySet(QFileDialogOptions::Accept)
156 ? options->labelText(QFileDialogOptions::Accept) : QString());
157 m_dialog->setRejectLabel(options->isLabelExplicitlySet(QFileDialogOptions::Reject)
158 ? options->labelText(QFileDialogOptions::Reject) : QString());
159 m_dialog->setWindowModality(modality);