API Documentation
Loading...
Searching...
No Matches
FileChooserDialog.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: FileChooserDialog
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/QCustomStackedWidget.h>
35#include <NDEVR/File.h>
36#include <NDEVR/FileFormat.h>
37#include <NDEVR/Buffer.h>
38#include <NDEVR/UUID.h>
39#include <NDEVR/INIInterface.h>
40#include <QWidget>
41#include <functional>
42#include <QPointer>
43#include <QIcon>
44class QHBoxLayout;
45#if NDEVR_SUPPORTS_THREADING
46class QThread;
47#endif
48namespace NDEVR
49{
50
51 class INIFactory;
52 class Button;
53 class QCustomTableWidget;
54 class Thread;
55 class Toggle;
56 class ButtonGallery;
57 class QCustomLineEdit;
58 class QCustomComboBox;
59 class QCustomMessageBox;
60 class FolderCreatorWidget;
62 {
63 QPointer<Button> button;
64 QPointer<QCustomTableWidget> table;
66 };
67 class NDEVR_WIDGETS_API FileChooserDialog : public QWidget, public INIInterface
68 {
69 Q_OBJECT
70 public:
71#if NDEVR_SUPPORTS_THREADING
72 friend class ImageCacheThread;
73#endif
75 {
76 e_browser
77 , e_recents
78 , e_favorites
79 };
80 FileChooserDialog(bool save_dialog = false, QWidget *parent = nullptr);
81 FileChooserDialog(const File& ini_location, bool save_dialog = false, QWidget *parent = nullptr);
83 void setOptions(const Buffer<FileFormat>& extensions, bool save_dialog);
84 QSize sizeHint() const override;
85 Buffer<File> getSelected() const;
86 //Should be used normally to correctly show the dialog in the most reasonable way
87 void autoShowDialog(PopupInfo info = PopupInfo());
88 void autoHideDialog(PopupInfo info = PopupInfo());
89 const Buffer<FileRequest>& getSelectedRequests() const;
90 void setAllowAny(bool allow_any) { m_allow_any = allow_any; }
91 bool isSaveDialog() const { return m_save_dialog; }
92 void setCurrentDirectory(const File& current_directory);
93 void setFallbackDirectory(const File& file);
94 void setSaveContent(const Buffer<UUID>& save_content) { m_save_content = save_content; }
95 const Buffer<UUID>& saveContent() const { return m_save_content; }
96 void showModifiedTime(bool show_modified_time);
97 void showAccessedTime(bool show_accessed_time);
98 void showFileSize(bool show_modified_time);
99 void setShowRecents(bool show_recent);
100 void setCurrentFileName(const String& name);
101 void setCurrentFile(const File& file);
102 void setCurrentExtension(const String& extension, bool update_format_to_first_match);
103 bool event(QEvent* e) override;
104 bool isFolderBrowser() const;
105 bool showRecents() const { return m_show_recents; };
106 bool showFavorites() const;
107 void prepareForINI(INIFactory& factory) override;
108 void finishReadingINI(INIFactory& factory) override;
109 void selectFileNameField();
110 void setAdditionalFavorites(Buffer<File> favorites);
111 void browseFile(PopupInfo popup_origin = PopupInfo());
112 void setIconProvider(const std::function<String(const FileRequest&)>& icon_provider);
113 void setCanReadCallback(const std::function<bool(const FileFormat&, const File&)>& callback);
114 TranslatedString actionName() const;
115 void setActionName(const TranslatedString& action_name);
116 void addToRecents(const Buffer<File>& files);
117 void addToRecents(const File& file);
118 TranslatedString windowTitle() const;
119 void showRecents();
120 const File& currentDirectory() const { return m_current_directory; };
121 void setNativeParent(QWidget* native_parent);
122 protected:
123 void postResolveIcons();
124 void browseFileNative();
125 void retranslate();
126 void updateGallery(Button* b);
127 void hidePopupDialog();
128 void autoSelectFavoritesItem();
129 FileFormat currentSelectedFormat() const;
130 void updateBrowserWidgets();
131 void SetupForBrowser();
132 void SetupForFavorites();
133 QWidget* createRequestWidget(File item);
134 QWidget* createNavigationButtons();
135 QWidget* createBottomPanel();
136 QWidget* createfavoritesPanel();
137 QWidget* settingsDialog();
138 String extensionsString(const String& delimiter = ";;") const;
139 void addItem(ButtonGallery* gallery, QCustomTableWidget* table, uint04 index, const File& item);
140 void removeFromRecents(File item);
141 void clearRecents();
142 void finishBrowse();
143 void setup();
144 FileFormat getFileFormat(const QString& file, const QString& string) const;
145 FileFormat getFileFormatFromExtension(const String& ext) const;
146 FileFormat getFileFormat(const File& file);
147 Buffer<File> filterFiles(const Buffer<File>& all_files) const;
148 bool checkFileAgainstFilter(const File& file, const FileFormat& selected_format) const;
149 const Buffer<File>& currentDirectoryFiles() const;
150 const Buffer<File> favoriteFiles() const;
151 void setIsFileChooser(bool is_file_chooser);
152 void onFileChosen(File file);
153 private slots:
154 void contextMenu(const QPoint &pos);
155 void browsingFinished();
156 void updateFilesSlot();
157 signals:
161 private:
162 void _setDisplayMode(DisplayMode mode);
163 QIcon _getIconCallback(const File& file);
164 String _getIconID(const File& file);
165 void _setCurrentDirectory(const File& dir);
166 void onUserReadyToFinish(bool was_browsing);
167 void onUserFinish();
168 void setFileIcon(File file, QIcon icon);
169 void showFiles(ButtonGallery* gallery, QCustomTableWidget* table, const Buffer<File>& files);
170 QCustomTableWidget* createTable(bool is_favorites = false);
171 virtual void getINI(INIFactory& factory) override;
172 bool getSelectedFilters(QString & selected_filter, QString & default_suffix);
173 void resolveIcons();
174 void resolveIcon(const File& file);
175 private:
176 Buffer<File> m_recent_files;
177 Dictionary<File, FileCachedData> m_program_managed_data;
178 mutable Buffer<File> m_current_directory_files;
179 Buffer<File> m_additional_favorites;
180 Dictionary<File, QIcon> m_cached_icons;
181 Dictionary<File, IconCacheWidget> m_cached_icon_locations;
182 File m_current_directory;
183 File m_fallback_directory;
184 String m_current_file_name;
185 String m_current_file_extension;
186 Buffer<FileFormat> m_filter;
187
188 QHBoxLayout* m_top_layout;
189 String m_last_dir;
190 bool m_save_dialog;
191 bool m_show_recents = true;
192 bool m_touch_prefer_gallery = true;
193 bool m_desktop_prefer_gallery = false;
194 bool m_show_hidden = false;
195 bool m_show_extensions = true;
196 bool m_show_favorites;
197 DisplayMode m_display_mode;
198 FolderCreatorWidget* m_folder_creation_widget;
199 QCustomTableWidget* m_file_table;
200 QCustomTableWidget* m_favorites_table;
201 ButtonGallery* m_file_gallery;
202 QCustomStackedWidget* m_view_stack;
203 Button* m_browse_button;
204 Button* m_database_button;
205 Button* m_view_toggle;
206 Button* m_accept_button;
207 Button* m_new_folder_button;
208 Button* m_up_level_button;
209 Button* m_favorites_button;
210 QWidget* m_navigation_buttons;
211 QWidget* m_bottom_buttons;
212 QWidget* m_favorites_panel;
213 QCustomComboBox* m_file_types_combo;
214 QCustomLineEdit* m_location_label;
215
216 QCustomLineEdit* m_file_name_line_edit;
217 QCustomMessageBox* m_override_file_message_box;
218 QCustomMessageBox* m_invalid_file_message_box;
219 Buffer<UUID> m_save_content;
220 QIcon m_loading_icon;
221 QWidget* m_popup_dialog;
222 QWidget* m_settings_dialog;
223
224 TranslatedString m_action_name;
225
226 Buffer<File> m_pending_icons;
227#if NDEVR_SUPPORTS_THREADING
228 QThread* m_icon_thread = nullptr;
229#endif
230 QWidget* m_native_parent = nullptr;
231 std::function<String(const FileRequest&)> m_icon_provider;
232 std::function<bool(const FileFormat&, const File&)> m_can_read_callback;
233 protected:
236 void updateTableIconSize(QCustomTableWidget* table);
237 bool m_neeeds_to_update = false;
238 };
239}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:81
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Button.h:60
Definition Dictionary.h:48
Definition FileChooserDialog.h:68
void setSaveContent(const Buffer< UUID > &save_content)
Definition FileChooserDialog.h:94
void setAllowAny(bool allow_any)
Definition FileChooserDialog.h:90
bool isSaveDialog() const
Definition FileChooserDialog.h:91
DisplayMode
Definition FileChooserDialog.h:75
bool m_allow_any
Definition FileChooserDialog.h:235
const File & currentDirectory() const
Definition FileChooserDialog.h:120
Buffer< FileRequest > m_selected_files
Definition FileChooserDialog.h:234
bool showRecents() const
Definition FileChooserDialog.h:105
const Buffer< UUID > & saveContent() const
Definition FileChooserDialog.h:95
Definition FileFormat.h:38
Definition File.h:47
Definition FileChooserDialog.cpp:47
Definition INIReader.h:57
Definition INIInterface.h:40
Definition QCustomCombobox.h:47
Definition QCustomLineEdit.h:118
Definition QCustomMessageBox.h:54
Definition QCustomStackedWidget.h:142
Definition QCustomTableWidget.h:41
Definition String.h:40
Definition TranslatedString.h:9
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
Definition BaseValues.hpp:272
Definition FileFormat.h:67
Definition FileChooserDialog.h:62
uint04 table_index
Definition FileChooserDialog.h:65
QPointer< Button > button
Definition FileChooserDialog.h:63
QPointer< QCustomTableWidget > table
Definition FileChooserDialog.h:64
Definition PopupInfo.h:10