1// Copyright (C) 2017 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
4#include "qwidgetplatformfiledialog_p.h"
5#include "qwidgetplatformdialog_p.h"
6
7#include <QtWidgets/qfiledialog.h>
8
9QT_BEGIN_NAMESPACE
10
11QWidgetPlatformFileDialog::QWidgetPlatformFileDialog(QObject *parent)
12 : m_dialog(new QFileDialog)
13{
14 setParent(parent);
15
16 connect(sender: m_dialog.data(), signal: &QDialog::accepted, context: this, slot: &QPlatformDialogHelper::accept);
17 connect(sender: m_dialog.data(), signal: &QDialog::rejected, context: this, slot: &QPlatformDialogHelper::reject);
18
19 connect(sender: m_dialog.data(), signal: &QFileDialog::fileSelected, slot: [this](const QString &file) {
20 emit fileSelected(file: QUrl::fromLocalFile(localfile: file));
21 });
22 connect(sender: m_dialog.data(), signal: &QFileDialog::filesSelected, slot: [this](const QList<QString> &files) {
23 QList<QUrl> urls;
24 urls.reserve(asize: files.size());
25 for (const QString &file : files)
26 urls += QUrl::fromLocalFile(localfile: file);
27 emit filesSelected(files: urls);
28 });
29 connect(sender: m_dialog.data(), signal: &QFileDialog::currentChanged, slot: [this](const QString &path) {
30 emit currentChanged(path: QUrl::fromLocalFile(localfile: path));
31 });
32 connect(sender: m_dialog.data(), signal: &QFileDialog::directoryEntered, context: this, slot: &QWidgetPlatformFileDialog::directoryEntered);
33 connect(sender: m_dialog.data(), signal: &QFileDialog::filterSelected, context: this, slot: &QWidgetPlatformFileDialog::filterSelected);
34}
35
36QWidgetPlatformFileDialog::~QWidgetPlatformFileDialog()
37{
38}
39
40bool QWidgetPlatformFileDialog::defaultNameFilterDisables() const
41{
42 return false; // TODO: ?
43}
44
45void QWidgetPlatformFileDialog::setDirectory(const QUrl &directory)
46{
47 m_dialog->setDirectory(directory.toLocalFile());
48}
49
50QUrl QWidgetPlatformFileDialog::directory() const
51{
52 return m_dialog->directoryUrl();
53}
54
55void QWidgetPlatformFileDialog::selectFile(const QUrl &filename)
56{
57 m_dialog->selectUrl(url: filename);
58}
59
60QList<QUrl> QWidgetPlatformFileDialog::selectedFiles() const
61{
62 return m_dialog->selectedUrls();
63}
64
65void QWidgetPlatformFileDialog::setFilter()
66{
67 // TODO: ?
68}
69
70void QWidgetPlatformFileDialog::selectNameFilter(const QString &filter)
71{
72 m_dialog->selectNameFilter(filter);
73}
74
75QString QWidgetPlatformFileDialog::selectedNameFilter() const
76{
77 return m_dialog->selectedNameFilter();
78}
79
80void QWidgetPlatformFileDialog::exec()
81{
82 m_dialog->exec();
83}
84
85bool QWidgetPlatformFileDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
86{
87 QSharedPointer<QFileDialogOptions> options = QPlatformFileDialogHelper::options();
88 m_dialog->setWindowTitle(options->windowTitle());
89 m_dialog->setAcceptMode(static_cast<QFileDialog::AcceptMode>(options->acceptMode()));
90 m_dialog->setFileMode(static_cast<QFileDialog::FileMode>(options->fileMode()));
91 m_dialog->setOptions(static_cast<QFileDialog::Options>(int(options->options())) | QFileDialog::DontUseNativeDialog);
92 m_dialog->setNameFilters(options->nameFilters());
93 m_dialog->setDefaultSuffix(options->defaultSuffix());
94 if (options->isLabelExplicitlySet(label: QFileDialogOptions::Accept))
95 m_dialog->setLabelText(label: QFileDialog::Accept, text: options->labelText(label: QFileDialogOptions::Accept));
96 if (options->isLabelExplicitlySet(label: QFileDialogOptions::Reject))
97 m_dialog->setLabelText(label: QFileDialog::Reject, text: options->labelText(label: QFileDialogOptions::Reject));
98
99 return QWidgetPlatformDialog::show(dialog: m_dialog.data(), flags, modality, parent);
100}
101
102void QWidgetPlatformFileDialog::hide()
103{
104 m_dialog->hide();
105}
106
107QT_END_NAMESPACE
108
109#include "moc_qwidgetplatformfiledialog_p.cpp"
110

source code of qtdeclarative/src/labs/platform/widgets/qwidgetplatformfiledialog.cpp