From cc543f4313ad76c9752b9be6c1f19089c03fe4ad Mon Sep 17 00:00:00 2001 From: stojce Date: Tue, 7 Jan 2014 00:41:11 +0100 Subject: [PATCH] Added custom icons (QFileIconProvider) --- interface/resources/icons/computer.svg | 13 +++ interface/resources/icons/desktop.svg | 18 ++++ interface/resources/icons/documents.svg | 16 ++++ interface/resources/icons/file.svg | 15 +++ interface/resources/icons/folder.svg | 12 +++ interface/resources/icons/home.svg | 17 ++++ interface/resources/icons/jpg.svg | 13 +++ interface/resources/icons/png.svg | 13 +++ interface/resources/icons/schematic.svg | 19 ++++ interface/resources/icons/svo.svg | 19 ++++ interface/resources/styles/import_dialog.qss | 37 ++++++++ interface/src/ImportDialog.cpp | 99 +++++++++++++++++--- interface/src/ImportDialog.h | 9 +- 13 files changed, 287 insertions(+), 13 deletions(-) create mode 100644 interface/resources/icons/computer.svg create mode 100644 interface/resources/icons/desktop.svg create mode 100644 interface/resources/icons/documents.svg create mode 100644 interface/resources/icons/file.svg create mode 100644 interface/resources/icons/folder.svg create mode 100644 interface/resources/icons/home.svg create mode 100644 interface/resources/icons/jpg.svg create mode 100644 interface/resources/icons/png.svg create mode 100644 interface/resources/icons/schematic.svg create mode 100644 interface/resources/icons/svo.svg diff --git a/interface/resources/icons/computer.svg b/interface/resources/icons/computer.svg new file mode 100644 index 0000000000..6bad8c3ad1 --- /dev/null +++ b/interface/resources/icons/computer.svg @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/interface/resources/icons/desktop.svg b/interface/resources/icons/desktop.svg new file mode 100644 index 0000000000..6cfe9f4e22 --- /dev/null +++ b/interface/resources/icons/desktop.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/interface/resources/icons/documents.svg b/interface/resources/icons/documents.svg new file mode 100644 index 0000000000..aaaf3acbca --- /dev/null +++ b/interface/resources/icons/documents.svg @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/interface/resources/icons/file.svg b/interface/resources/icons/file.svg new file mode 100644 index 0000000000..f268de7520 --- /dev/null +++ b/interface/resources/icons/file.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/interface/resources/icons/folder.svg b/interface/resources/icons/folder.svg new file mode 100644 index 0000000000..093add7b53 --- /dev/null +++ b/interface/resources/icons/folder.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/interface/resources/icons/home.svg b/interface/resources/icons/home.svg new file mode 100644 index 0000000000..9a1c39afd0 --- /dev/null +++ b/interface/resources/icons/home.svg @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/interface/resources/icons/jpg.svg b/interface/resources/icons/jpg.svg new file mode 100644 index 0000000000..902c530d59 --- /dev/null +++ b/interface/resources/icons/jpg.svg @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/interface/resources/icons/png.svg b/interface/resources/icons/png.svg new file mode 100644 index 0000000000..902c530d59 --- /dev/null +++ b/interface/resources/icons/png.svg @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/interface/resources/icons/schematic.svg b/interface/resources/icons/schematic.svg new file mode 100644 index 0000000000..16cd6839a3 --- /dev/null +++ b/interface/resources/icons/schematic.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/interface/resources/icons/svo.svg b/interface/resources/icons/svo.svg new file mode 100644 index 0000000000..16cd6839a3 --- /dev/null +++ b/interface/resources/icons/svo.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/interface/resources/styles/import_dialog.qss b/interface/resources/styles/import_dialog.qss index 3c4d46de47..3757abaac7 100644 --- a/interface/resources/styles/import_dialog.qss +++ b/interface/resources/styles/import_dialog.qss @@ -6,14 +6,29 @@ * Copyright (c) 2014 High Fidelity, Inc. All rights reserved. */ +* { + font-family: Helvetica, Arial, sans-serif; +} + +QLabel { + font-size: 16px; +} + QSidebar, QTreeView { border: 1px solid #E5E5E5; + font-size: 14px; } QTreeView { border-left: none; } +QSidebar::item { + margin-top: 10px; + padding-top: 5px; + padding-bottom: 0; +} + QSplitter::handle, QDialog { background-color: white; } @@ -36,4 +51,26 @@ QPushButton#cancelButton { background: #FFFFFF; } +QTreeView QHeaderView:section { + border-left: none; + border-top: none; + border-bottom: 1px solid #E5E5E5; + border-right: 1px solid #E5E5E5; + background: white; + color: #666666; + padding: 10px 20px; + font-size: 22px; + font-weight: bold; +} +QTreeView::item { + padding: 5px 0; +} + +QListView::item:selected, +QListView::item:selected:active, +QTreeView::item:selected, +QTreeView::item:selected:active { + background: #BDE4E3; + color: #333333; +} diff --git a/interface/src/ImportDialog.cpp b/interface/src/ImportDialog.cpp index ea55839770..ab90ba2032 100644 --- a/interface/src/ImportDialog.cpp +++ b/interface/src/ImportDialog.cpp @@ -10,9 +10,18 @@ #include #include #include +#include +#include +#include + +#include + +#include +#include const QString WINDOW_NAME = QObject::tr("Import Voxels"); const QString IMPORT_BUTTON_NAME = QObject::tr("Import"); +const QString IMPORT_INFO = QObject::tr("Import .svo, .schematic, or .png as voxels"); const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel"); const QString IMPORT_FILE_TYPES = QObject::tr("Sparse Voxel Octree Files, " "Square PNG, " @@ -23,10 +32,76 @@ const QString INFO_LABEL_TEXT = QObject::tr("This will load selected file into H const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); +QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const { + + switchToResourcesParentIfRequired(); + + // types + // Computer, Desktop, Trashcan, Network, Drive, Folder, File + + QString typeString; + + switch (type) { + case QFileIconProvider::Computer: + typeString = "computer"; + break; + + case QFileIconProvider::Desktop: + typeString = "desktop"; + break; + case QFileIconProvider::Trashcan: + typeString = "folder"; + break; + + case QFileIconProvider::Network: + typeString = "folder"; + break; + + case QFileIconProvider::Drive: + typeString = "folder"; + break; + + case QFileIconProvider::Folder: + typeString = "folder"; + break; + + default: + typeString = "file"; + break; + } + + QIcon ico = QIcon("resources/icons/" + typeString + ".svg"); + ico.pixmap(QSize(50, 50)); + return ico; +} + +QIcon HiFiIconProvider::icon(const QFileInfo &info) const { + switchToResourcesParentIfRequired(); + const QString ext = info.suffix().toLower(); + + if (info.isDir()) { + if (info.absoluteFilePath() == QDir::homePath()) { + return QIcon("resources/icons/home.svg"); + } else if (info.absoluteFilePath() == DESKTOP_LOCATION) { + return QIcon("resources/icons/desktop.svg"); + } else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)) { + return QIcon("resources/icons/documents.svg"); + } + return QIcon("resources/icons/folder.svg"); + } + + QFileInfo iconFile = QFileInfo("resources/icons/" + ext + ".svg"); + qDebug() << "Icon type: " << iconFile.filePath(); + if (iconFile.exists()) { + return QIcon(iconFile.filePath()); + } + + return QIcon("resources/icons/file.svg"); +} + ImportDialog::ImportDialog(QWidget *parent) : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES), _importButton(IMPORT_BUTTON_NAME, this), _cancelButton(CANCEL_BUTTON_NAME, this), -_importLabel(IMPORT_BUTTON_NAME), _infoLabel(INFO_LABEL_TEXT) { setOption(QFileDialog::DontUseNativeDialog, true); @@ -34,12 +109,13 @@ _infoLabel(INFO_LABEL_TEXT) { setViewMode(QFileDialog::Detail); setLayout(); + QLabel* _importLabel = findChild("lookInLabel"); + _importLabel->setText(IMPORT_INFO); + QGridLayout* gridLayout = (QGridLayout*) layout(); - gridLayout->addWidget(&_importLabel, 0, 0); - gridLayout->addWidget(&_infoLabel, 2, 0); - gridLayout->addWidget(&_cancelButton, 2, 1); - gridLayout->addWidget(&_importButton, 2, 2); - gridLayout->setColumnStretch(3, 1); + gridLayout->addWidget(&_infoLabel, 2, 0, Qt::AlignLeft); + gridLayout->addWidget(&_cancelButton, 2, 1, Qt::AlignRight); + gridLayout->addWidget(&_importButton, 2, 2, Qt::AlignRight); connect(&_importButton, SIGNAL(pressed()), SLOT(import())); connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); @@ -84,10 +160,7 @@ void ImportDialog::setLayout() { _cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // hide unused embeded widgets in QFileDialog - QWidget* widget = findChild("lookInLabel"); - widget->hide(); - - widget = findChild("lookInCombo"); + QWidget* widget = findChild("lookInCombo"); widget->hide(); widget = findChild("backButton"); @@ -122,22 +195,24 @@ void ImportDialog::setLayout() { widget = findChild("buttonBox"); widget->hide(); - + QSplitter *splitter = findChild("splitter"); splitter->setHandleWidth(0); // remove blue outline on Mac widget = findChild("sidebar"); widget->setAttribute(Qt::WA_MacShowFocusRect, false); + widget = findChild("treeView"); widget->setAttribute(Qt::WA_MacShowFocusRect, false); // set custom file icons - // setIconProvider(new HiFiIconProvider()); + setIconProvider(new HiFiIconProvider()); switchToResourcesParentIfRequired(); QFile styleSheet("resources/styles/import_dialog.qss"); if (styleSheet.open(QIODevice::ReadOnly)) { setStyleSheet(styleSheet.readAll()); } + } diff --git a/interface/src/ImportDialog.h b/interface/src/ImportDialog.h index d666917c50..eb8b6ba20f 100644 --- a/interface/src/ImportDialog.h +++ b/interface/src/ImportDialog.h @@ -12,8 +12,16 @@ #include #include #include +#include + #include +class HiFiIconProvider : public QFileIconProvider { +public: + virtual QIcon icon(IconType type) const; + virtual QIcon icon(const QFileInfo &info) const; +}; + class ImportDialog : public QFileDialog { Q_OBJECT @@ -41,7 +49,6 @@ private: QString _currentFile; QPushButton _importButton; QPushButton _cancelButton; - QLabel _importLabel; QLabel _infoLabel; void setLayout();