Showing the changes to interface/src/ImportDialog.cpp (1 of 2 files). Show all
Unified · Split
| @@ -10,12 +10,7 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <QStandardPaths> |
| 11 | 11 | #include <QGridLayout> |
| 12 | 12 | #include <QSplitter> |
| 13 | −#include <QFile> | |
| 14 | −#include <QFileInfo> | |
| 15 | −#include <QDir> | |
| 16 | − | |
| 17 | 13 | #include <QApplication> |
| 18 | −#include <QStyle> | |
| 19 | 14 | #include <QJsonDocument> |
| 20 | 15 | #include <QJsonArray> |
| 21 | 16 | #include <QJsonObject> |
| @@ -24,10 +19,6 @@ const QString WINDOW_NAME = QObject::tr("Import Voxels"); · 2 unmodified lines | ||
| 24 | 19 | const QString IMPORT_BUTTON_NAME = QObject::tr("Import"); |
| 25 | 20 | const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels"); |
| 26 | 21 | const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel"); |
| 27 | −const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Octree Files, " | |
| 28 | − "Square PNG, " | |
| 29 | − "Schematic Files " | |
| 30 | − "(*.svo *.png *.schematic)"); | |
| 31 | 22 | const QString INFO_LABEL_TEXT = QObject::tr("This will load selected file into Hifi and\n" |
| 32 | 23 | "allow you to place it with Command V"); |
| 33 | 24 | |
| @@ -88,59 +79,16 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const { · 54 unmodified lines | ||
| 88 | 79 | return QIcon("resources/icons/file.svg"); |
| 89 | 80 | } |
| 90 | 81 | |
| 91 | −ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL), | |
| 92 | −_importButton(IMPORT_BUTTON_NAME, this), | |
| 93 | −_cancelButton(CANCEL_BUTTON_NAME, this) { | |
| 82 | +ImportDialog::ImportDialog(QWidget *parent) : | |
| 83 | + QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL), | |
| 84 | + _importButton(IMPORT_BUTTON_NAME, this), | |
| 85 | + _cancelButton(CANCEL_BUTTON_NAME, this) { | |
| 94 | 86 | |
| 95 | 87 | setOption(QFileDialog::DontUseNativeDialog, true); |
| 96 | 88 | setFileMode(QFileDialog::ExistingFile); |
| 97 | 89 | setViewMode(QFileDialog::Detail); |
| 98 | 90 | |
| 99 | − switchToResourcesParentIfRequired(); | |
| 100 | − QFile config("resources/config/config.json"); | |
| 101 | − config.open(QFile::ReadOnly | QFile::Text); | |
| 102 | − QJsonDocument document = QJsonDocument::fromJson(config.readAll()); | |
| 103 | − if (!document.isNull() && !document.isEmpty()) { | |
| 104 | − | |
| 105 | − QString importFormatsInfo; | |
| 106 | − QStringList importFormatsFilterList; | |
| 107 | − QHash<QString, QString> iconsMap; | |
| 108 | − | |
| 109 | − QJsonObject config = document.object(); | |
| 110 | − if (!config.isEmpty()) { | |
| 111 | − QJsonArray fileFormats = config["importFormats"].toArray(); | |
| 112 | − int ff = 0; | |
| 113 | − foreach (const QJsonValue& fileFormat, fileFormats) { | |
| 114 | − QJsonObject fileFormatObject = fileFormat.toObject(); | |
| 115 | − | |
| 116 | − QString ext(fileFormatObject["extension"].toString()); | |
| 117 | − QString description(fileFormatObject.value("description").toString()); | |
| 118 | − QString icon(fileFormatObject.value("icon").toString()); | |
| 119 | − | |
| 120 | − if (ff > 0) { | |
| 121 | − importFormatsInfo.append(","); | |
| 122 | − } | |
| 123 | − | |
| 124 | − if (ff == fileFormats.count() - 1) { | |
| 125 | − importFormatsInfo.append(" or"); | |
| 126 | − } | |
| 127 | − | |
| 128 | − importFormatsFilterList.append(QString("%1 (*.%2)").arg(description, ext)); | |
| 129 | − importFormatsInfo.append(" .").append(ext); | |
| 130 | − iconsMap[ext] = icon; | |
| 131 | − ff++; | |
| 132 | − } | |
| 133 | − } | |
| 134 | − | |
| 135 | − // set custom file icons | |
| 136 | − setIconProvider(new HiFiIconProvider(iconsMap)); | |
| 137 | − | |
| 138 | − setNameFilters(importFormatsFilterList); | |
| 139 | − | |
| 140 | − setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo)); | |
| 141 | − setLabelText(QFileDialog::FileName, INFO_LABEL_TEXT); | |
| 142 | − | |
| 143 | − } | |
| 91 | + setImportTypes(); | |
| 144 | 92 | setLayout(); |
| 145 | 93 | |
| 146 | 94 | QGridLayout* gridLayout = (QGridLayout*) layout(); |
| @@ -150,7 +98,6 @@ _cancelButton(CANCEL_BUTTON_NAME, this) { · 3 unmodified lines | ||
| 150 | 98 | connect(&_importButton, SIGNAL(pressed()), SLOT(import())); |
| 151 | 99 | connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); |
| 152 | 100 | connect(&_cancelButton, SIGNAL(pressed()), SLOT(close())); |
| 153 | − | |
| 154 | 101 | } |
| 155 | 102 | |
| 156 | 103 | ImportDialog::~ImportDialog() { |
| @@ -183,7 +130,7 @@ void ImportDialog::saveCurrentFile(QString filename) { · 26 unmodified lines | ||
| 183 | 130 | _currentFile = filename; |
| 184 | 131 | _importButton.setEnabled(true); |
| 185 | 132 | } else { |
| 186 | − _currentFile = ""; | |
| 133 | + _currentFile.clear(); | |
| 187 | 134 | _importButton.setEnabled(false); |
| 188 | 135 | } |
| 189 | 136 | } |
| @@ -198,7 +145,7 @@ void ImportDialog::setLayout() { · 8 unmodified lines | ||
| 198 | 145 | _importButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
| 199 | 146 | _cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
| 200 | 147 | |
| 201 | − // hide unused embeded widgets in QFileDialog | |
| 148 | + // hide unused embedded widgets in QFileDialog | |
| 202 | 149 | QWidget* widget = findChild<QWidget*>("lookInCombo"); |
| 203 | 150 | widget->hide(); |
| 204 | 151 | |
| @@ -253,3 +200,52 @@ void ImportDialog::setLayout() { · 48 unmodified lines | ||
| 253 | 200 | } |
| 254 | 201 | |
| 255 | 202 | } |
| 203 | + | |
| 204 | +void ImportDialog::setImportTypes() { | |
| 205 | + | |
| 206 | + switchToResourcesParentIfRequired(); | |
| 207 | + QFile config("resources/config/config.json"); | |
| 208 | + config.open(QFile::ReadOnly | QFile::Text); | |
| 209 | + QJsonDocument document = QJsonDocument::fromJson(config.readAll()); | |
| 210 | + if (!document.isNull() && !document.isEmpty()) { | |
| 211 | + | |
| 212 | + QString importFormatsInfo; | |
| 213 | + QStringList importFormatsFilterList; | |
| 214 | + QHash<QString, QString> iconsMap; | |
| 215 | + | |
| 216 | + QJsonObject configObject = document.object(); | |
| 217 | + if (!configObject.isEmpty()) { | |
| 218 | + QJsonArray fileFormats = configObject["importFormats"].toArray(); | |
| 219 | + int ff = 0; | |
| 220 | + foreach (const QJsonValue& fileFormat, fileFormats) { | |
| 221 | + QJsonObject fileFormatObject = fileFormat.toObject(); | |
| 222 | + | |
| 223 | + QString ext(fileFormatObject["extension"].toString()); | |
| 224 | + QString description(fileFormatObject.value("description").toString()); | |
| 225 | + QString icon(fileFormatObject.value("icon").toString()); | |
| 226 | + | |
| 227 | + if (ff > 0) { | |
| 228 | + importFormatsInfo.append(","); | |
| 229 | + } | |
| 230 | + | |
| 231 | + // set ' or' on last import type text | |
| 232 | + if (ff == fileFormats.count() - 1) { | |
| 233 | + importFormatsInfo.append(" or"); | |
| 234 | + } | |
| 235 | + | |
| 236 | + importFormatsFilterList.append(QString("%1 (*.%2)").arg(description, ext)); | |
| 237 | + importFormatsInfo.append(" .").append(ext); | |
| 238 | + iconsMap[ext] = icon; | |
| 239 | + ff++; | |
| 240 | + } | |
| 241 | + } | |
| 242 | + | |
| 243 | + // set custom file icons | |
| 244 | + setIconProvider(new HiFiIconProvider(iconsMap)); | |
| 245 | + | |
| 246 | + setNameFilters(importFormatsFilterList); | |
| 247 | + | |
| 248 | + setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo)); | |
| 249 | + setLabelText(QFileDialog::FileName, INFO_LABEL_TEXT); | |
| 250 | + } | |
| 251 | +} | |