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 | #ifndef QQUICKLABSPLATFORMFILEDIALOG_P_H |
5 | #define QQUICKLABSPLATFORMFILEDIALOG_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquicklabsplatformdialog_p.h" |
19 | #include <QtCore/qurl.h> |
20 | #include <QtQml/qqml.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QQuickLabsPlatformFileNameFilter; |
25 | |
26 | class QQuickLabsPlatformFileDialog : public QQuickLabsPlatformDialog |
27 | { |
28 | Q_OBJECT |
29 | QML_NAMED_ELEMENT(FileDialog) |
30 | QML_EXTENDED_NAMESPACE(QFileDialogOptions) |
31 | Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode NOTIFY fileModeChanged FINAL) |
32 | Q_PROPERTY(QUrl file READ file WRITE setFile NOTIFY fileChanged FINAL) |
33 | Q_PROPERTY(QList<QUrl> files READ files WRITE setFiles NOTIFY filesChanged FINAL) |
34 | Q_PROPERTY(QUrl currentFile READ currentFile WRITE setCurrentFile NOTIFY currentFileChanged FINAL) |
35 | Q_PROPERTY(QList<QUrl> currentFiles READ currentFiles WRITE setCurrentFiles NOTIFY currentFilesChanged FINAL) |
36 | Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged FINAL) |
37 | Q_PROPERTY(QFileDialogOptions::FileDialogOptions options READ options WRITE setOptions RESET resetOptions NOTIFY optionsChanged FINAL) |
38 | Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters RESET resetNameFilters NOTIFY nameFiltersChanged FINAL) |
39 | Q_PROPERTY(QQuickLabsPlatformFileNameFilter *selectedNameFilter READ selectedNameFilter CONSTANT FINAL) |
40 | Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix RESET resetDefaultSuffix NOTIFY defaultSuffixChanged FINAL) |
41 | Q_PROPERTY(QString acceptLabel READ acceptLabel WRITE setAcceptLabel RESET resetAcceptLabel NOTIFY acceptLabelChanged FINAL) |
42 | Q_PROPERTY(QString rejectLabel READ rejectLabel WRITE setRejectLabel RESET resetRejectLabel NOTIFY rejectLabelChanged FINAL) |
43 | |
44 | public: |
45 | explicit QQuickLabsPlatformFileDialog(QObject *parent = nullptr); |
46 | |
47 | enum FileMode { |
48 | OpenFile, |
49 | OpenFiles, |
50 | SaveFile |
51 | }; |
52 | Q_ENUM(FileMode) |
53 | |
54 | FileMode fileMode() const; |
55 | void setFileMode(FileMode fileMode); |
56 | |
57 | QUrl file() const; |
58 | void setFile(const QUrl &file); |
59 | |
60 | QList<QUrl> files() const; |
61 | void setFiles(const QList<QUrl> &files); |
62 | |
63 | QUrl currentFile() const; |
64 | void setCurrentFile(const QUrl &file); |
65 | |
66 | QList<QUrl> currentFiles() const; |
67 | void setCurrentFiles(const QList<QUrl> &files); |
68 | |
69 | QUrl folder() const; |
70 | void setFolder(const QUrl &folder); |
71 | |
72 | QFileDialogOptions::FileDialogOptions options() const; |
73 | void setOptions(QFileDialogOptions::FileDialogOptions options); |
74 | void resetOptions(); |
75 | |
76 | QStringList nameFilters() const; |
77 | void setNameFilters(const QStringList &filters); |
78 | void resetNameFilters(); |
79 | |
80 | QQuickLabsPlatformFileNameFilter *selectedNameFilter() const; |
81 | |
82 | QString defaultSuffix() const; |
83 | void setDefaultSuffix(const QString &suffix); |
84 | void resetDefaultSuffix(); |
85 | |
86 | QString acceptLabel() const; |
87 | void setAcceptLabel(const QString &label); |
88 | void resetAcceptLabel(); |
89 | |
90 | QString rejectLabel() const; |
91 | void setRejectLabel(const QString &label); |
92 | void resetRejectLabel(); |
93 | |
94 | Q_SIGNALS: |
95 | void fileModeChanged(); |
96 | void fileChanged(); |
97 | void filesChanged(); |
98 | void currentFileChanged(); |
99 | void currentFilesChanged(); |
100 | void folderChanged(); |
101 | void optionsChanged(); |
102 | void nameFiltersChanged(); |
103 | void defaultSuffixChanged(); |
104 | void acceptLabelChanged(); |
105 | void rejectLabelChanged(); |
106 | |
107 | protected: |
108 | bool useNativeDialog() const override; |
109 | void onCreate(QPlatformDialogHelper *dialog) override; |
110 | void onShow(QPlatformDialogHelper *dialog) override; |
111 | void onHide(QPlatformDialogHelper *dialog) override; |
112 | void accept() override; |
113 | |
114 | private: |
115 | QUrl addDefaultSuffix(const QUrl &file) const; |
116 | QList<QUrl> addDefaultSuffixes(const QList<QUrl> &files) const; |
117 | |
118 | FileMode m_fileMode; |
119 | QList<QUrl> m_files; |
120 | bool m_firstShow = true; |
121 | QSharedPointer<QFileDialogOptions> m_options; |
122 | mutable QQuickLabsPlatformFileNameFilter *m_selectedNameFilter; |
123 | }; |
124 | |
125 | class QQuickLabsPlatformFileNameFilter : public QObject |
126 | { |
127 | Q_OBJECT |
128 | QML_ANONYMOUS |
129 | Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged FINAL) |
130 | Q_PROPERTY(QString name READ name NOTIFY nameChanged FINAL) |
131 | Q_PROPERTY(QStringList extensions READ extensions NOTIFY extensionsChanged FINAL) |
132 | |
133 | public: |
134 | explicit QQuickLabsPlatformFileNameFilter(QObject *parent = nullptr); |
135 | |
136 | int index() const; |
137 | void setIndex(int index); |
138 | |
139 | QString name() const; |
140 | QStringList extensions() const; |
141 | |
142 | QSharedPointer<QFileDialogOptions> options() const; |
143 | void setOptions(const QSharedPointer<QFileDialogOptions> &options); |
144 | |
145 | void update(const QString &filter); |
146 | |
147 | Q_SIGNALS: |
148 | void indexChanged(int index); |
149 | void nameChanged(const QString &name); |
150 | void extensionsChanged(const QStringList &extensions); |
151 | |
152 | private: |
153 | QStringList nameFilters() const; |
154 | QString nameFilter(int index) const; |
155 | |
156 | int m_index; |
157 | QString m_name; |
158 | QStringList m_extensions; |
159 | QSharedPointer<QFileDialogOptions> m_options; |
160 | }; |
161 | |
162 | QT_END_NAMESPACE |
163 | |
164 | QML_DECLARE_TYPE(QQuickLabsPlatformFileDialog) |
165 | |
166 | #endif // QQUICKLABSPLATFORMFILEDIALOG_P_H |
167 |