1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Labs Platform module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qwidgetplatformfiledialog_p.h"
38#include "qwidgetplatformdialog_p.h"
39
40#include <QtWidgets/qfiledialog.h>
41
42QT_BEGIN_NAMESPACE
43
44QWidgetPlatformFileDialog::QWidgetPlatformFileDialog(QObject *parent)
45 : m_dialog(new QFileDialog)
46{
47 setParent(parent);
48
49 connect(sender: m_dialog.data(), signal: &QDialog::accepted, receiver: this, slot: &QPlatformDialogHelper::accept);
50 connect(sender: m_dialog.data(), signal: &QDialog::rejected, receiver: this, slot: &QPlatformDialogHelper::reject);
51
52 connect(sender: m_dialog.data(), signal: &QFileDialog::fileSelected, slot: [this](const QString &file) {
53 emit fileSelected(file: QUrl::fromLocalFile(localfile: file));
54 });
55 connect(sender: m_dialog.data(), signal: &QFileDialog::filesSelected, slot: [this](const QList<QString> &files) {
56 QList<QUrl> urls;
57 urls.reserve(alloc: files.count());
58 for (const QString &file : files)
59 urls += QUrl::fromLocalFile(localfile: file);
60 emit filesSelected(files: urls);
61 });
62 connect(sender: m_dialog.data(), signal: &QFileDialog::currentChanged, slot: [this](const QString &path) {
63 emit currentChanged(path: QUrl::fromLocalFile(localfile: path));
64 });
65 connect(sender: m_dialog.data(), signal: &QFileDialog::directoryEntered, receiver: this, slot: &QWidgetPlatformFileDialog::directoryEntered);
66 connect(sender: m_dialog.data(), signal: &QFileDialog::filterSelected, receiver: this, slot: &QWidgetPlatformFileDialog::filterSelected);
67}
68
69QWidgetPlatformFileDialog::~QWidgetPlatformFileDialog()
70{
71}
72
73bool QWidgetPlatformFileDialog::defaultNameFilterDisables() const
74{
75 return false; // TODO: ?
76}
77
78void QWidgetPlatformFileDialog::setDirectory(const QUrl &directory)
79{
80 m_dialog->setDirectory(directory.toLocalFile());
81}
82
83QUrl QWidgetPlatformFileDialog::directory() const
84{
85 return m_dialog->directoryUrl();
86}
87
88void QWidgetPlatformFileDialog::selectFile(const QUrl &filename)
89{
90 m_dialog->selectUrl(url: filename);
91}
92
93QList<QUrl> QWidgetPlatformFileDialog::selectedFiles() const
94{
95 return m_dialog->selectedUrls();
96}
97
98void QWidgetPlatformFileDialog::setFilter()
99{
100 // TODO: ?
101}
102
103void QWidgetPlatformFileDialog::selectNameFilter(const QString &filter)
104{
105 m_dialog->selectNameFilter(filter);
106}
107
108QString QWidgetPlatformFileDialog::selectedNameFilter() const
109{
110 return m_dialog->selectedNameFilter();
111}
112
113void QWidgetPlatformFileDialog::exec()
114{
115 m_dialog->exec();
116}
117
118bool QWidgetPlatformFileDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
119{
120 QSharedPointer<QFileDialogOptions> options = QPlatformFileDialogHelper::options();
121 m_dialog->setWindowTitle(options->windowTitle());
122 m_dialog->setAcceptMode(static_cast<QFileDialog::AcceptMode>(options->acceptMode()));
123 m_dialog->setFileMode(static_cast<QFileDialog::FileMode>(options->fileMode()));
124 m_dialog->setOptions(static_cast<QFileDialog::Options>(int(options->options())) | QFileDialog::DontUseNativeDialog);
125 m_dialog->setNameFilters(options->nameFilters());
126 m_dialog->setDefaultSuffix(options->defaultSuffix());
127 if (options->isLabelExplicitlySet(label: QFileDialogOptions::Accept))
128 m_dialog->setLabelText(label: QFileDialog::Accept, text: options->labelText(label: QFileDialogOptions::Accept));
129 if (options->isLabelExplicitlySet(label: QFileDialogOptions::Reject))
130 m_dialog->setLabelText(label: QFileDialog::Reject, text: options->labelText(label: QFileDialogOptions::Reject));
131
132 return QWidgetPlatformDialog::show(dialog: m_dialog.data(), flags, modality, parent);
133}
134
135void QWidgetPlatformFileDialog::hide()
136{
137 m_dialog->hide();
138}
139
140QT_END_NAMESPACE
141

source code of qtquickcontrols2/src/imports/platform/widgets/qwidgetplatformfiledialog.cpp