mirror of
https://github.com/lubosz/overte.git
synced 2025-04-09 01:22:36 +02:00
Add import configuration
remove unused icons remove redundant QLabels
This commit is contained in:
parent
5b678cb24d
commit
d5e07a5c75
8 changed files with 83 additions and 60 deletions
19
interface/resources/config/config.json
Normal file
19
interface/resources/config/config.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"importFormats" : [
|
||||
{
|
||||
"extension": "png",
|
||||
"description": "Square PNG",
|
||||
"icon": "raster.svg"
|
||||
},
|
||||
{
|
||||
"extension": "svo",
|
||||
"description": "Sparse Voxel Octree Files",
|
||||
"icon": "voxel.svg"
|
||||
},
|
||||
{
|
||||
"extension": "schematic",
|
||||
"description": "Schematic Files",
|
||||
"icon": "voxel.svg"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 17.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="24px" height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
|
||||
<g>
|
||||
<path fill="#666666" d="M15.049,10.75c0,0.688-0.562,1.25-1.25,1.25h-12.5c-0.688,0-1.25-0.562-1.25-1.25v-9.5
|
||||
C0.049,0.562,0.611,0,1.299,0h12.5c0.688,0,1.25,0.562,1.25,1.25V10.75z M1.299,1c-0.133,0-0.25,0.117-0.25,0.25v9.5
|
||||
c0,0.133,0.117,0.25,0.25,0.25h12.5c0.133,0,0.25-0.117,0.25-0.25v-9.5c0-0.133-0.117-0.25-0.25-0.25H1.299z M3.549,5
|
||||
c-0.828,0-1.5-0.672-1.5-1.5S2.72,2,3.549,2s1.5,0.672,1.5,1.5S4.377,5,3.549,5z M13.049,10h-11V8.5l2.5-2.5l1.25,1.25l4-4
|
||||
l3.25,3.25V10z"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 961 B |
Before Width: | Height: | Size: 961 B After Width: | Height: | Size: 961 B |
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 17.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="24px" height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#666666" d="M13.402,4.612c0-0.098-0.052-0.188-0.137-0.237c-0.085-0.049-0.189-0.049-0.274,0L7.704,7.428
|
||||
C7.423,7.59,7.25,7.89,7.25,8.215v6.105c0,0.098,0.052,0.188,0.137,0.237c0.085,0.049,0.189,0.049,0.274,0l5.085-2.936
|
||||
c0.407-0.235,0.657-0.668,0.657-1.138V4.612z"/>
|
||||
<path fill="#666666" d="M0.41,4.375c-0.085-0.049-0.189-0.049-0.274,0C0.052,4.424,0,4.514,0,4.612c0,0,0,0,0,0v5.872
|
||||
c0,0.469,0.25,0.903,0.657,1.138l5.085,2.936c0,0,0,0,0,0c0.085,0.049,0.189,0.049,0.274,0c0.085-0.049,0.136-0.139,0.136-0.237
|
||||
V8.215c0-0.325-0.173-0.625-0.455-0.787L0.41,4.375z"/>
|
||||
</g>
|
||||
<path fill="#666666" d="M12.443,3.586c0.085-0.049,0.137-0.139,0.137-0.237c0-0.098-0.052-0.188-0.137-0.237c0,0,0,0,0,0
|
||||
L7.358,0.176c-0.407-0.235-0.907-0.235-1.313,0L0.959,3.112c0,0,0,0,0,0C0.874,3.161,0.822,3.251,0.822,3.349
|
||||
c0,0.098,0.052,0.188,0.137,0.237l5.287,3.053c0.281,0.162,0.628,0.162,0.909,0L12.443,3.586z"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
@ -42,7 +42,6 @@ QTreeView {
|
|||
|
||||
QSidebar::item {
|
||||
margin-top: 10px;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
|
@ -68,10 +67,6 @@ QTreeView::item {
|
|||
height: 30px;
|
||||
}
|
||||
|
||||
QListView::item::icon {
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
QListView::item:selected,
|
||||
QListView::item:selected:active,
|
||||
QTreeView::item:selected,
|
||||
|
|
|
@ -12,16 +12,17 @@
|
|||
#include <QSplitter>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStyle>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
const QString WINDOW_NAME = QObject::tr("Import Voxels");
|
||||
const QString IMPORT_BUTTON_NAME = QObject::tr("Import");
|
||||
const QString IMPORT_INFO = QObject::tr("<b>Import</b> .svo, .schematic, or .png as voxels");
|
||||
const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels");
|
||||
const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel");
|
||||
const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Octree Files, "
|
||||
"Square PNG, "
|
||||
|
@ -69,10 +70,8 @@ QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const {
|
|||
typeString = "file";
|
||||
break;
|
||||
}
|
||||
|
||||
QIcon ico = QIcon("resources/icons/" + typeString + ".svg");
|
||||
ico.pixmap(QSize(50, 50));
|
||||
return ico;
|
||||
|
||||
return QIcon ("resources/icons/" + typeString + ".svg");
|
||||
}
|
||||
|
||||
QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
||||
|
@ -90,8 +89,7 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
|||
return QIcon("resources/icons/folder.svg");
|
||||
}
|
||||
|
||||
QFileInfo iconFile = QFileInfo("resources/icons/" + ext + ".svg");
|
||||
qDebug() << "Icon type: " << iconFile.filePath();
|
||||
QFileInfo iconFile("resources/icons/" + ext + ".svg");
|
||||
if (iconFile.exists()) {
|
||||
return QIcon(iconFile.filePath());
|
||||
}
|
||||
|
@ -99,31 +97,74 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
|||
return QIcon("resources/icons/file.svg");
|
||||
}
|
||||
|
||||
ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),
|
||||
ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL),
|
||||
_importButton(IMPORT_BUTTON_NAME, this),
|
||||
_cancelButton(CANCEL_BUTTON_NAME, this),
|
||||
_infoLabel(INFO_LABEL_TEXT) {
|
||||
_cancelButton(CANCEL_BUTTON_NAME, this) {
|
||||
|
||||
setOption(QFileDialog::DontUseNativeDialog, true);
|
||||
setFileMode(QFileDialog::ExistingFile);
|
||||
setViewMode(QFileDialog::Detail);
|
||||
|
||||
switchToResourcesParentIfRequired();
|
||||
QFile config("resources/config/config.json");
|
||||
config.open(QFile::ReadOnly | QFile::Text);
|
||||
QJsonDocument document = QJsonDocument::fromJson(config.readAll());
|
||||
if (!document.isNull() && !document.isEmpty()) {
|
||||
|
||||
QString importFormatsInfo;
|
||||
QStringList importFormatsFilterList;
|
||||
QHash<QString, QString> iconsMap;
|
||||
|
||||
QJsonObject config = document.object();
|
||||
if (!config.isEmpty()) {
|
||||
QJsonArray fileFormats = config["importFormats"].toArray();
|
||||
int ff = 0;
|
||||
foreach (const QJsonValue& fileFormat, fileFormats) {
|
||||
QJsonObject fileFormatObject = fileFormat.toObject();
|
||||
|
||||
QString ext(fileFormatObject["extension"].toString());
|
||||
QString description(fileFormatObject.value("description").toString());
|
||||
QString icon(fileFormatObject.value("icon").toString());
|
||||
|
||||
if (ff > 0) {
|
||||
importFormatsInfo.append(",");
|
||||
}
|
||||
|
||||
if (ff == fileFormats.count() - 1) {
|
||||
importFormatsInfo.append(" or");
|
||||
}
|
||||
|
||||
importFormatsFilterList.append(QString("%1 (*.%2)").arg(description, ext));
|
||||
importFormatsInfo.append(" .").append(ext);
|
||||
iconsMap[ext] = icon;
|
||||
ff++;
|
||||
}
|
||||
}
|
||||
|
||||
// set custom file icons
|
||||
setIconProvider(new HiFiIconProvider(iconsMap));
|
||||
|
||||
setNameFilters(importFormatsFilterList);
|
||||
|
||||
setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo));
|
||||
setLabelText(QFileDialog::FileName, INFO_LABEL_TEXT);
|
||||
|
||||
}
|
||||
setLayout();
|
||||
QLabel* _importLabel = findChild<QLabel*>("lookInLabel");
|
||||
_importLabel->setText(IMPORT_INFO);
|
||||
|
||||
QGridLayout* gridLayout = (QGridLayout*) layout();
|
||||
gridLayout->addWidget(&_infoLabel, 2, 0);
|
||||
gridLayout->addWidget(&_cancelButton, 2, 1);
|
||||
gridLayout->addWidget(&_importButton, 2, 2);
|
||||
|
||||
connect(&_importButton, SIGNAL(pressed()), SLOT(import()));
|
||||
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
||||
connect(&_cancelButton, SIGNAL(pressed()), SLOT(close()));
|
||||
|
||||
|
||||
resize(QSize(790, 477));
|
||||
}
|
||||
|
||||
ImportDialog::~ImportDialog() {
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void ImportDialog::import() {
|
||||
|
@ -153,7 +194,7 @@ void ImportDialog::saveCurrentFile(QString filename) {
|
|||
|
||||
void ImportDialog::setLayout() {
|
||||
|
||||
// set ObjectName used in qss
|
||||
// set ObjectName used in qss for styling
|
||||
_importButton.setObjectName("importButton");
|
||||
_cancelButton.setObjectName("cancelButton");
|
||||
|
||||
|
@ -186,9 +227,6 @@ void ImportDialog::setLayout() {
|
|||
widget = findChild<QWidget*>("fileNameEdit");
|
||||
widget->hide();
|
||||
|
||||
widget = findChild<QWidget*>("fileNameLabel");
|
||||
widget->hide();
|
||||
|
||||
widget = findChild<QWidget*>("fileTypeCombo");
|
||||
widget->hide();
|
||||
|
||||
|
@ -208,8 +246,9 @@ void ImportDialog::setLayout() {
|
|||
widget = findChild<QWidget*>("treeView");
|
||||
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
|
||||
// set custom file icons
|
||||
setIconProvider(new HiFiIconProvider());
|
||||
// remove reference to treeView
|
||||
// widget = NULL;
|
||||
// widget->deleteLater();
|
||||
|
||||
switchToResourcesParentIfRequired();
|
||||
QFile styleSheet("resources/styles/import_dialog.qss");
|
||||
|
|
|
@ -13,13 +13,16 @@
|
|||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QFileIconProvider>
|
||||
#include <QHash>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
|
||||
class HiFiIconProvider : public QFileIconProvider {
|
||||
public:
|
||||
HiFiIconProvider(const QHash<QString, QString> map) { iconsMap = map; };
|
||||
virtual QIcon icon(IconType type) const;
|
||||
virtual QIcon icon(const QFileInfo &info) const;
|
||||
QHash<QString, QString> iconsMap;
|
||||
};
|
||||
|
||||
class ImportDialog : public QFileDialog {
|
||||
|
@ -49,7 +52,6 @@ private:
|
|||
QString _currentFile;
|
||||
QPushButton _importButton;
|
||||
QPushButton _cancelButton;
|
||||
QLabel _infoLabel;
|
||||
|
||||
void setLayout();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue