1 | // Copyright (C) 2021 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 QQUICKFILEDIALOGIMPL_P_H |
5 | #define QQUICKFILEDIALOGIMPL_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 <QtQuick/private/qquicklistview_p.h> |
19 | #include <QtQuickTemplates2/private/qquickdialog_p.h> |
20 | |
21 | #include "qtquickdialogs2quickimplglobal_p.h" |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QQuickComboBox; |
26 | class QQuickDialogButtonBox; |
27 | class QQuickTextField; |
28 | class QQuickLabel; |
29 | |
30 | class QQuickFileDialogImplAttached; |
31 | class QQuickFileDialogImplAttachedPrivate; |
32 | class QQuickFileDialogImplPrivate; |
33 | class QQuickFileNameFilter; |
34 | class QQuickFolderBreadcrumbBar; |
35 | |
36 | class Q_QUICKDIALOGS2QUICKIMPL_PRIVATE_EXPORT QQuickFileDialogImpl : public QQuickDialog |
37 | { |
38 | Q_OBJECT |
39 | Q_PROPERTY(QUrl currentFolder READ currentFolder WRITE setCurrentFolder NOTIFY currentFolderChanged FINAL) |
40 | Q_PROPERTY(QUrl selectedFile READ selectedFile WRITE setSelectedFile NOTIFY selectedFileChanged FINAL) |
41 | Q_PROPERTY(QStringList nameFilters READ nameFilters NOTIFY nameFiltersChanged FINAL) |
42 | Q_PROPERTY(QQuickFileNameFilter *selectedNameFilter READ selectedNameFilter CONSTANT) |
43 | Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY selectedFileChanged FINAL) |
44 | QML_NAMED_ELEMENT(FileDialogImpl) |
45 | QML_ATTACHED(QQuickFileDialogImplAttached) |
46 | QML_ADDED_IN_VERSION(6, 2) |
47 | Q_MOC_INCLUDE(<QtQuickDialogs2Utils/private/qquickfilenamefilter_p.h>) |
48 | Q_MOC_INCLUDE(<QtQuickDialogs2QuickImpl/private/qquickfolderbreadcrumbbar_p.h>) |
49 | |
50 | public: |
51 | explicit QQuickFileDialogImpl(QObject *parent = nullptr); |
52 | |
53 | static QQuickFileDialogImplAttached *qmlAttachedProperties(QObject *object); |
54 | |
55 | enum class SetReason { |
56 | // Either user interaction or e.g. a change in ListView's currentIndex after changing its model. |
57 | External, |
58 | // As a result of the user setting an initial selectedFile. |
59 | Internal |
60 | }; |
61 | |
62 | QUrl currentFolder() const; |
63 | void setCurrentFolder(const QUrl ¤tFolder, SetReason setReason = SetReason::External); |
64 | |
65 | QUrl selectedFile() const; |
66 | void setSelectedFile(const QUrl &file); |
67 | void setInitialCurrentFolderAndSelectedFile(const QUrl &file); |
68 | |
69 | QSharedPointer<QFileDialogOptions> options() const; |
70 | void setOptions(const QSharedPointer<QFileDialogOptions> &options); |
71 | |
72 | QStringList nameFilters() const; |
73 | void resetNameFilters(); |
74 | |
75 | QQuickFileNameFilter *selectedNameFilter() const; |
76 | |
77 | void setAcceptLabel(const QString &label); |
78 | void setRejectLabel(const QString &label); |
79 | |
80 | QString fileName() const; |
81 | void setFileName(const QString &fileName); |
82 | |
83 | public Q_SLOTS: |
84 | void selectNameFilter(const QString &filter); |
85 | |
86 | Q_SIGNALS: |
87 | void currentFolderChanged(const QUrl &folderUrl); |
88 | void selectedFileChanged(const QUrl &selectedFileUrl); |
89 | void nameFiltersChanged(); |
90 | void fileSelected(const QUrl &fileUrl); |
91 | void filterSelected(const QString &filter); |
92 | |
93 | private: |
94 | void componentComplete() override; |
95 | void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override; |
96 | |
97 | Q_DISABLE_COPY(QQuickFileDialogImpl) |
98 | Q_DECLARE_PRIVATE(QQuickFileDialogImpl) |
99 | }; |
100 | |
101 | class Q_QUICKDIALOGS2QUICKIMPL_PRIVATE_EXPORT QQuickFileDialogImplAttached : public QObject |
102 | { |
103 | Q_OBJECT |
104 | Q_PROPERTY(QQuickDialogButtonBox *buttonBox READ buttonBox WRITE setButtonBox NOTIFY buttonBoxChanged FINAL) |
105 | Q_PROPERTY(QQuickComboBox *nameFiltersComboBox READ nameFiltersComboBox WRITE setNameFiltersComboBox NOTIFY nameFiltersComboBoxChanged) |
106 | Q_PROPERTY(QQuickListView *fileDialogListView READ fileDialogListView WRITE setFileDialogListView NOTIFY fileDialogListViewChanged) |
107 | Q_PROPERTY(QQuickFolderBreadcrumbBar *breadcrumbBar READ breadcrumbBar WRITE setBreadcrumbBar NOTIFY breadcrumbBarChanged) |
108 | Q_PROPERTY(QQuickLabel *fileNameLabel READ fileNameLabel WRITE setFileNameLabel NOTIFY fileNameLabelChanged FINAL) |
109 | Q_PROPERTY(QQuickTextField *fileNameTextField READ fileNameTextField WRITE setFileNameTextField NOTIFY fileNameTextFieldChanged FINAL) |
110 | Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquickdialogbuttonbox_p.h>) |
111 | Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquickcombobox_p.h>) |
112 | Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquicktextfield_p.h>) |
113 | Q_MOC_INCLUDE(<QtQuickTemplates2/private/qquicklabel_p.h>) |
114 | |
115 | public: |
116 | explicit QQuickFileDialogImplAttached(QObject *parent = nullptr); |
117 | |
118 | QQuickDialogButtonBox *buttonBox() const; |
119 | void setButtonBox(QQuickDialogButtonBox *buttonBox); |
120 | |
121 | QQuickComboBox *nameFiltersComboBox() const; |
122 | void setNameFiltersComboBox(QQuickComboBox *nameFiltersComboBox); |
123 | |
124 | QString selectedNameFilter() const; |
125 | void selectNameFilter(const QString &filter); |
126 | |
127 | QQuickListView *fileDialogListView() const; |
128 | void setFileDialogListView(QQuickListView *fileDialogListView); |
129 | |
130 | QQuickFolderBreadcrumbBar *breadcrumbBar() const; |
131 | void setBreadcrumbBar(QQuickFolderBreadcrumbBar *breadcrumbBar); |
132 | |
133 | QQuickLabel *fileNameLabel() const; |
134 | void setFileNameLabel(QQuickLabel *fileNameLabel); |
135 | |
136 | QQuickTextField *fileNameTextField() const; |
137 | void setFileNameTextField(QQuickTextField *fileNameTextField); |
138 | |
139 | Q_SIGNALS: |
140 | void buttonBoxChanged(); |
141 | void nameFiltersComboBoxChanged(); |
142 | void fileDialogListViewChanged(); |
143 | void breadcrumbBarChanged(); |
144 | void fileNameLabelChanged(); |
145 | void fileNameTextFieldChanged(); |
146 | |
147 | private: |
148 | Q_DISABLE_COPY(QQuickFileDialogImplAttached) |
149 | Q_DECLARE_PRIVATE(QQuickFileDialogImplAttached) |
150 | }; |
151 | |
152 | QT_END_NAMESPACE |
153 | |
154 | QML_DECLARE_TYPE(QQuickFileDialogImpl) |
155 | |
156 | #endif // QQUICKFILEDIALOGIMPL_P_H |
157 | |