remove unused icons remove redundant QLabels
Showing the changes to interface/src/ImportDialog.cpp (1 of 8 files). Show all
Unified · Split
| @@ -12,16 +12,17 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <QSplitter> |
| 13 | 13 | #include <QFile> |
| 14 | 14 | #include <QFileInfo> |
| 15 | −#include <QMetaEnum> | |
| 16 | − | |
| 17 | 15 | #include <QDir> |
| 18 | 16 | |
| 19 | 17 | #include <QApplication> |
| 20 | 18 | #include <QStyle> |
| 19 | +#include <QJsonDocument> | |
| 20 | +#include <QJsonArray> | |
| 21 | +#include <QJsonObject> | |
| 21 | 22 | |
| 22 | 23 | const QString WINDOW_NAME = QObject::tr("Import Voxels"); |
| 23 | 24 | const QString IMPORT_BUTTON_NAME = QObject::tr("Import"); |
| 24 | −const QString IMPORT_INFO = QObject::tr("<b>Import</b> .svo, .schematic, or .png as voxels"); | |
| 25 | +const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels"); | |
| 25 | 26 | const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel"); |
| 26 | 27 | const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Octree Files, " |
| 27 | 28 | "Square PNG, " |
| @@ -69,10 +70,8 @@ QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const { · 41 unmodified lines | ||
| 69 | 70 | typeString = "file"; |
| 70 | 71 | break; |
| 71 | 72 | } |
| 72 | − | |
| 73 | − QIcon ico = QIcon("resources/icons/" + typeString + ".svg"); | |
| 74 | − ico.pixmap(QSize(50, 50)); | |
| 75 | − return ico; | |
| 73 | + | |
| 74 | + return QIcon ("resources/icons/" + typeString + ".svg"); | |
| 76 | 75 | } |
| 77 | 76 | |
| 78 | 77 | QIcon HiFiIconProvider::icon(const QFileInfo &info) const { |
| @@ -90,8 +89,7 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const { · 11 unmodified lines | ||
| 90 | 89 | return QIcon("resources/icons/folder.svg"); |
| 91 | 90 | } |
| 92 | 91 | |
| 93 | − QFileInfo iconFile = QFileInfo("resources/icons/" + ext + ".svg"); | |
| 94 | − qDebug() << "Icon type: " << iconFile.filePath(); | |
| 92 | + QFileInfo iconFile("resources/icons/" + ext + ".svg"); | |
| 95 | 93 | if (iconFile.exists()) { |
| 96 | 94 | return QIcon(iconFile.filePath()); |
| 97 | 95 | } |
| @@ -99,31 +97,74 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const { · 1 unmodified line | ||
| 99 | 97 | return QIcon("resources/icons/file.svg"); |
| 100 | 98 | } |
| 101 | 99 | |
| 102 | −ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES), | |
| 100 | +ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL), | |
| 103 | 101 | _importButton(IMPORT_BUTTON_NAME, this), |
| 104 | −_cancelButton(CANCEL_BUTTON_NAME, this), | |
| 105 | −_infoLabel(INFO_LABEL_TEXT) { | |
| 102 | +_cancelButton(CANCEL_BUTTON_NAME, this) { | |
| 106 | 103 | |
| 107 | 104 | setOption(QFileDialog::DontUseNativeDialog, true); |
| 108 | 105 | setFileMode(QFileDialog::ExistingFile); |
| 109 | 106 | setViewMode(QFileDialog::Detail); |
| 110 | 107 | |
| 108 | + switchToResourcesParentIfRequired(); | |
| 109 | + QFile config("resources/config/config.json"); | |
| 110 | + config.open(QFile::ReadOnly | QFile::Text); | |
| 111 | + QJsonDocument document = QJsonDocument::fromJson(config.readAll()); | |
| 112 | + if (!document.isNull() && !document.isEmpty()) { | |
| 113 | + | |
| 114 | + QString importFormatsInfo; | |
| 115 | + QStringList importFormatsFilterList; | |
| 116 | + QHash<QString, QString> iconsMap; | |
| 117 | + | |
| 118 | + QJsonObject config = document.object(); | |
| 119 | + if (!config.isEmpty()) { | |
| 120 | + QJsonArray fileFormats = config["importFormats"].toArray(); | |
| 121 | + int ff = 0; | |
| 122 | + foreach (const QJsonValue& fileFormat, fileFormats) { | |
| 123 | + QJsonObject fileFormatObject = fileFormat.toObject(); | |
| 124 | + | |
| 125 | + QString ext(fileFormatObject["extension"].toString()); | |
| 126 | + QString description(fileFormatObject.value("description").toString()); | |
| 127 | + QString icon(fileFormatObject.value("icon").toString()); | |
| 128 | + | |
| 129 | + if (ff > 0) { | |
| 130 | + importFormatsInfo.append(","); | |
| 131 | + } | |
| 132 | + | |
| 133 | + if (ff == fileFormats.count() - 1) { | |
| 134 | + importFormatsInfo.append(" or"); | |
| 135 | + } | |
| 136 | + | |
| 137 | + importFormatsFilterList.append(QString("%1 (*.%2)").arg(description, ext)); | |
| 138 | + importFormatsInfo.append(" .").append(ext); | |
| 139 | + iconsMap[ext] = icon; | |
| 140 | + ff++; | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + // set custom file icons | |
| 145 | + setIconProvider(new HiFiIconProvider(iconsMap)); | |
| 146 | + | |
| 147 | + setNameFilters(importFormatsFilterList); | |
| 148 | + | |
| 149 | + setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo)); | |
| 150 | + setLabelText(QFileDialog::FileName, INFO_LABEL_TEXT); | |
| 151 | + | |
| 152 | + } | |
| 111 | 153 | setLayout(); |
| 112 | − QLabel* _importLabel = findChild<QLabel*>("lookInLabel"); | |
| 113 | − _importLabel->setText(IMPORT_INFO); | |
| 114 | 154 | |
| 115 | 155 | QGridLayout* gridLayout = (QGridLayout*) layout(); |
| 116 | − gridLayout->addWidget(&_infoLabel, 2, 0); | |
| 117 | 156 | gridLayout->addWidget(&_cancelButton, 2, 1); |
| 118 | 157 | gridLayout->addWidget(&_importButton, 2, 2); |
| 119 | 158 | |
| 120 | 159 | connect(&_importButton, SIGNAL(pressed()), SLOT(import())); |
| 121 | 160 | connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); |
| 161 | + connect(&_cancelButton, SIGNAL(pressed()), SLOT(close())); | |
| 162 | + | |
| 122 | 163 | |
| 123 | − resize(QSize(790, 477)); | |
| 124 | 164 | } |
| 125 | 165 | |
| 126 | 166 | ImportDialog::~ImportDialog() { |
| 167 | + deleteLater(); | |
| 127 | 168 | } |
| 128 | 169 | |
| 129 | 170 | void ImportDialog::import() { |
| @@ -153,7 +194,7 @@ void ImportDialog::saveCurrentFile(QString filename) { · 23 unmodified lines | ||
| 153 | 194 | |
| 154 | 195 | void ImportDialog::setLayout() { |
| 155 | 196 | |
| 156 | − // set ObjectName used in qss | |
| 197 | + // set ObjectName used in qss for styling | |
| 157 | 198 | _importButton.setObjectName("importButton"); |
| 158 | 199 | _cancelButton.setObjectName("cancelButton"); |
| 159 | 200 | |
| @@ -186,9 +227,6 @@ void ImportDialog::setLayout() { · 26 unmodified lines | ||
| 186 | 227 | widget = findChild<QWidget*>("fileNameEdit"); |
| 187 | 228 | widget->hide(); |
| 188 | 229 | |
| 189 | − widget = findChild<QWidget*>("fileNameLabel"); | |
| 190 | − widget->hide(); | |
| 191 | − | |
| 192 | 230 | widget = findChild<QWidget*>("fileTypeCombo"); |
| 193 | 231 | widget->hide(); |
| 194 | 232 | |
| @@ -208,8 +246,9 @@ void ImportDialog::setLayout() { · 13 unmodified lines | ||
| 208 | 246 | widget = findChild<QWidget*>("treeView"); |
| 209 | 247 | widget->setAttribute(Qt::WA_MacShowFocusRect, false); |
| 210 | 248 | |
| 211 | − // set custom file icons | |
| 212 | − setIconProvider(new HiFiIconProvider()); | |
| 249 | + // remove reference to treeView | |
| 250 | +// widget = NULL; | |
| 251 | +// widget->deleteLater(); | |
| 213 | 252 | |
| 214 | 253 | switchToResourcesParentIfRequired(); |
| 215 | 254 | QFile styleSheet("resources/styles/import_dialog.qss"); |