-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileDialog.cpp
More file actions
71 lines (61 loc) · 2.13 KB
/
Copy pathfileDialog.cpp
File metadata and controls
71 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "filedialog.h"
// Define the static member
const QString FileDialog::filters =
"Video Files (*.mp4 *.avi *.mkv *.mov);;"
"MP4 (*.mp4);;"
"AVI (*.avi);;"
"MKV (*.mkv);;"
"MOV (*.mov);;"
"Image Files (*.jpg *.jpeg *.png *.bmp *.tif *.tiff *.webp *.ppm *.pgm *.pbm *.hdr *.exr *.sr *.ras);;"
"JPEG (*.jpg *.jpeg);;"
"PNG (*.png);;"
"BMP (*.bmp);;"
"TIFF (*.tif *.tiff);;"
"WebP (*.webp);;"
"PPM/PGM/PBM (*.ppm *.pgm *.pbm);;"
"HDR (*.hdr);;"
"OpenEXR (*.exr);;"
"Sun Raster (*.sr *.ras);;"
"All Files (*.*)";
std::unordered_set<std::wstring> videoExtentions = { L".mp4", L".avi", L".mkv", L".mov" };
std::unordered_set<std::wstring> imageExtentions = {
L".jpg", L".jpeg", L".png", L".bmp", L".tif", L".tiff", L".webp",
L".ppm", L".pgm", L".pbm", L".hdr", L".exr", L".sr", L".ras"
};
// Helper functions (local to .cpp file)
namespace {
QString toQString(const std::wstring& wstr) {
return QString::fromStdWString(wstr);
}
std::wstring toStdWString(const QString& qstr) {
return qstr.toStdWString();
}
}
std::wstring FileDialog::OpenFileDialog(const std::wstring& selectedFilter) {
QString selected = toQString(selectedFilter);
QString file = QFileDialog::getOpenFileName(
nullptr, // Parent widget
"Open File", // Dialog title
"", // Default directory
filters, // Use the class-static filters
&selected // Preselect a filter
);
file.remove('"');
return file.toStdWString();
}
std::wstring FileDialog::SaveFileDialog(const std::wstring& selectedFilter,
const std::wstring& defaultName) {
QString selected = toQString(selectedFilter);
// Get native dialog without quotes
QFileDialog dialog;
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setNameFilter(filters);
dialog.selectNameFilter(selected);
dialog.selectFile(toQString(defaultName));
if (!dialog.exec()) {
return L""; // User cancelled
}
QString file = dialog.selectedFiles().first();
file.remove('"');
return QDir::toNativeSeparators(file).toStdWString();
}