diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-06-18 14:45:56 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-06-27 13:07:49 +0000 |
commit | 4960f639e338e36b595667f02e2b5fac51aaa07a (patch) | |
tree | 2d1d6784cfe24d96312e67e0090a60f1edf48a50 /src/imports/platform/widgets | |
parent | beb7d695a8051bb800f6f595140c4b5e1c5c15bc (diff) |
Platform: add FileDialog and FolderDialog
Change-Id: I4328c273e48139d6ddd5a3d3c8492d06f48a5c24
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/platform/widgets')
-rw-r--r-- | src/imports/platform/widgets/qwidgetplatformfiledialog.cpp | 152 | ||||
-rw-r--r-- | src/imports/platform/widgets/qwidgetplatformfiledialog_p.h | 84 | ||||
-rw-r--r-- | src/imports/platform/widgets/widgets.pri | 2 |
3 files changed, 238 insertions, 0 deletions
diff --git a/src/imports/platform/widgets/qwidgetplatformfiledialog.cpp b/src/imports/platform/widgets/qwidgetplatformfiledialog.cpp new file mode 100644 index 00000000..22e9c78a --- /dev/null +++ b/src/imports/platform/widgets/qwidgetplatformfiledialog.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Platform module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwidgetplatformfiledialog_p.h" +#include "qwidgetplatformdialog_p.h" +#include "qwidgetplatform_p.h" + +#include <QtWidgets/qfiledialog.h> + +QT_BEGIN_NAMESPACE + +QWidgetPlatformFileDialog::QWidgetPlatformFileDialog(QObject *parent) +{ + setParent(parent); + + static bool available = QWidgetPlatform::isAvailable("file dialog"); + if (available) { + m_dialog.reset(new QFileDialog); + connect(m_dialog.data(), &QDialog::accepted, this, &QPlatformDialogHelper::accept); + connect(m_dialog.data(), &QDialog::rejected, this, &QPlatformDialogHelper::reject); + + connect(m_dialog.data(), &QFileDialog::fileSelected, [this](const QString &file) { + emit fileSelected(QUrl::fromLocalFile(file)); + }); + connect(m_dialog.data(), &QFileDialog::filesSelected, [this](const QList<QString> &files) { + QList<QUrl> urls; + urls.reserve(files.count()); + for (const QString &file : files) + urls += QUrl::fromLocalFile(file); + emit filesSelected(urls); + }); + connect(m_dialog.data(), &QFileDialog::currentChanged, [this](const QString &path) { + emit currentChanged(QUrl::fromLocalFile(path)); + }); + connect(m_dialog.data(), &QFileDialog::directoryEntered, this, &QWidgetPlatformFileDialog::directoryEntered); + connect(m_dialog.data(), &QFileDialog::filterSelected, this, &QWidgetPlatformFileDialog::filterSelected); + } +} + +QWidgetPlatformFileDialog::~QWidgetPlatformFileDialog() +{ +} + +bool QWidgetPlatformFileDialog::defaultNameFilterDisables() const +{ + return false; // TODO: ? +} + +void QWidgetPlatformFileDialog::setDirectory(const QUrl &directory) +{ + if (m_dialog) + m_dialog->setDirectory(directory.toLocalFile()); +} + +QUrl QWidgetPlatformFileDialog::directory() const +{ + return m_dialog ? m_dialog->directoryUrl() : QUrl(); +} + +void QWidgetPlatformFileDialog::selectFile(const QUrl &filename) +{ + if (m_dialog) + m_dialog->selectUrl(filename); +} + +QList<QUrl> QWidgetPlatformFileDialog::selectedFiles() const +{ + return m_dialog ? m_dialog->selectedUrls() : QList<QUrl>(); +} + +void QWidgetPlatformFileDialog::setFilter() +{ + // TODO: ? +} + +void QWidgetPlatformFileDialog::selectNameFilter(const QString &filter) +{ + if (m_dialog) + m_dialog->selectNameFilter(filter); +} + +QString QWidgetPlatformFileDialog::selectedNameFilter() const +{ + return m_dialog ? m_dialog->selectedNameFilter() : QString(); +} + +void QWidgetPlatformFileDialog::exec() +{ + if (m_dialog) + m_dialog->exec(); +} + +bool QWidgetPlatformFileDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) +{ + if (!m_dialog) + return false; + + QSharedPointer<QFileDialogOptions> options = QPlatformFileDialogHelper::options(); + m_dialog->setWindowTitle(options->windowTitle()); + m_dialog->setAcceptMode(static_cast<QFileDialog::AcceptMode>(options->acceptMode())); + m_dialog->setFileMode(static_cast<QFileDialog::FileMode>(options->fileMode())); + m_dialog->setOptions(static_cast<QFileDialog::Options>(int(options->options()))); + m_dialog->setNameFilters(options->nameFilters()); + m_dialog->setDefaultSuffix(options->defaultSuffix()); + if (options->isLabelExplicitlySet(QFileDialogOptions::Accept)) + m_dialog->setLabelText(QFileDialog::Accept, options->labelText(QFileDialogOptions::Accept)); + if (options->isLabelExplicitlySet(QFileDialogOptions::Reject)) + m_dialog->setLabelText(QFileDialog::Reject, options->labelText(QFileDialogOptions::Reject)); + + return QWidgetPlatformDialog::show(m_dialog.data(), flags, modality, parent); +} + +void QWidgetPlatformFileDialog::hide() +{ + if (m_dialog) + m_dialog->hide(); +} + +QT_END_NAMESPACE diff --git a/src/imports/platform/widgets/qwidgetplatformfiledialog_p.h b/src/imports/platform/widgets/qwidgetplatformfiledialog_p.h new file mode 100644 index 00000000..743bc571 --- /dev/null +++ b/src/imports/platform/widgets/qwidgetplatformfiledialog_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Platform module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWIDGETPLATFORMFILEDIALOG_P_H +#define QWIDGETPLATFORMFILEDIALOG_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtGui/qpa/qplatformdialoghelper.h> + +QT_BEGIN_NAMESPACE + +class QFileDialog; + +class QWidgetPlatformFileDialog : public QPlatformFileDialogHelper +{ + Q_OBJECT + +public: + explicit QWidgetPlatformFileDialog(QObject *parent = nullptr); + ~QWidgetPlatformFileDialog(); + + bool defaultNameFilterDisables() const override; + void setDirectory(const QUrl &directory) override; + QUrl directory() const override; + void selectFile(const QUrl &filename) override; + QList<QUrl> selectedFiles() const override; + void setFilter() override; + void selectNameFilter(const QString &filter) override; + QString selectedNameFilter() const override; + + void exec() override; + bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override; + void hide() override; + +private: + QScopedPointer<QFileDialog> m_dialog; +}; + +QT_END_NAMESPACE + +#endif // QWIDGETPLATFORMFILEDIALOG_P_H diff --git a/src/imports/platform/widgets/widgets.pri b/src/imports/platform/widgets/widgets.pri index e09e3166..c904e924 100644 --- a/src/imports/platform/widgets/widgets.pri +++ b/src/imports/platform/widgets/widgets.pri @@ -5,6 +5,7 @@ HEADERS += \ $$PWD/qwidgetplatform_p.h \ $$PWD/qwidgetplatformcolordialog_p.h \ $$PWD/qwidgetplatformdialog_p.h \ + $$PWD/qwidgetplatformfiledialog_p.h \ $$PWD/qwidgetplatformfontdialog_p.h \ $$PWD/qwidgetplatformmenu_p.h \ $$PWD/qwidgetplatformmenuitem_p.h \ @@ -14,6 +15,7 @@ HEADERS += \ SOURCES += \ $$PWD/qwidgetplatformcolordialog.cpp \ $$PWD/qwidgetplatformdialog.cpp \ + $$PWD/qwidgetplatformfiledialog.cpp \ $$PWD/qwidgetplatformfontdialog.cpp \ $$PWD/qwidgetplatformmenu.cpp \ $$PWD/qwidgetplatformmenuitem.cpp \ |