diff --git a/interface/src/ImportDialog.cpp b/interface/src/ImportDialog.cpp index c276a4da6b..192e7fbf86 100644 --- a/interface/src/ImportDialog.cpp +++ b/interface/src/ImportDialog.cpp @@ -16,14 +16,13 @@ const QString WINDOW_NAME = QObject::tr("Import Voxels"); const QString IMPORT_BUTTON_NAME = QObject::tr("Import"); +const QString LOADING_BUTTON_NAME = QObject::tr("Loading ..."); +const QString PLACE_BUTTON_NAME = QObject::tr("Place voxels"); const QString IMPORT_INFO = QObject::tr("Import %1 as voxels"); const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel"); -const QString INFO_LABEL_TEXT = QObject::tr("
" - "This will load the selected file into Hifi and allow you
" - "to place it with %1-V; you must be in select or
" - "add mode (S or V keys will toggle mode) to place.
"); -const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + +const QString DOWNLOAD_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); const int SHORT_FILE_EXTENSION = 4; const int SECOND_INDEX_LETTER = 1; @@ -66,7 +65,7 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const { if (info.isDir()) { if (info.absoluteFilePath() == QDir::homePath()) { return QIcon("resources/icons/home.svg"); - } else if (info.absoluteFilePath() == DESKTOP_LOCATION) { + } else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)) { return QIcon("resources/icons/desktop.svg"); } else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)) { return QIcon("resources/icons/documents.svg"); @@ -95,10 +94,11 @@ QString HiFiIconProvider::type(const QFileInfo &info) const { } ImportDialog::ImportDialog(QWidget* parent) : - QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL), + QFileDialog(parent, WINDOW_NAME, DOWNLOAD_LOCATION, NULL), + _progressBar(this), _importButton(IMPORT_BUTTON_NAME, this), _cancelButton(CANCEL_BUTTON_NAME, this), - fileAccepted(false) { + _mode(importMode) { setOption(QFileDialog::DontUseNativeDialog, true); setFileMode(QFileDialog::ExistingFile); @@ -107,96 +107,89 @@ ImportDialog::ImportDialog(QWidget* parent) : setImportTypes(); setLayout(); - connect(&_importButton, SIGNAL(pressed()), SLOT(import())); - connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); - - connect(&_cancelButton, SIGNAL(pressed()), SLOT(close())); - connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); -} - -ImportDialog::~ImportDialog() { - deleteLater(); -} - -void ImportDialog::import() { - fileAccepted = true; - emit accepted(); -} - -void ImportDialog::accept() { - // do nothing if import is not enable - if (!_importButton.isEnabled()) { - return; - } + _progressBar.setRange(0, 100); - if (!fileAccepted) { - fileAccepted = true; - emit accepted(); - } else { - QFileDialog::accept(); - } -} - -void ImportDialog::reject() { - QFileDialog::reject(); -} - -int ImportDialog::exec() { - // deselect selected file - selectFile(" "); - return QFileDialog::exec(); + connect(&_importButton, SIGNAL(pressed()), SLOT(accept())); + connect(&_cancelButton, SIGNAL(pressed()), SIGNAL(canceled())); + connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); } void ImportDialog::reset() { - _importButton.setEnabled(false); + setMode(importMode); + _progressBar.setValue(0); } -void ImportDialog::saveCurrentFile(QString filename) { - if (!filename.isEmpty() && QFileInfo(filename).isFile()) { - _currentFile = filename; - _importButton.setEnabled(true); - } else { - _currentFile.clear(); - _importButton.setEnabled(false); +void ImportDialog::setMode(dialogMode mode) { + _mode = mode; + + switch (_mode) { + case loadingMode: + _importButton.setEnabled(false); + _importButton.setText(LOADING_BUTTON_NAME); + findChild("sidebar")->setEnabled(false); + findChild("treeView")->setEnabled(false); + findChild("backButton")->setEnabled(false); + findChild("forwardButton")->setEnabled(false); + findChild("toParentButton")->setEnabled(false); + break; + case placeMode: + _progressBar.setValue(100); + _importButton.setEnabled(true); + _importButton.setText(PLACE_BUTTON_NAME); + findChild("sidebar")->setEnabled(false); + findChild("treeView")->setEnabled(false); + findChild("backButton")->setEnabled(false); + findChild("forwardButton")->setEnabled(false); + findChild("toParentButton")->setEnabled(false); + break; + case importMode: + default: + _progressBar.setValue(0); + _importButton.setEnabled(true); + _importButton.setText(IMPORT_BUTTON_NAME); + findChild("sidebar")->setEnabled(true); + findChild("treeView")->setEnabled(true); + findChild("backButton")->setEnabled(true); + findChild("forwardButton")->setEnabled(true); + findChild("toParentButton")->setEnabled(true); + break; } } +void ImportDialog::setProgressBarValue(int value) { + _progressBar.setValue(value); +} + +void ImportDialog::accept() { + emit accepted(); +} + +void ImportDialog::saveCurrentFile(QString filename) { + _currentFile = QFileInfo(filename).isFile() ? filename : ""; +} +#include void ImportDialog::setLayout() { - -#ifdef Q_OS_MAC - QString cmdString = ("Command"); -#else - QString cmdString = ("Control"); -#endif - QLabel* infoLabel = new QLabel(QString(INFO_LABEL_TEXT).arg(cmdString)); - infoLabel->setObjectName("infoLabel"); - QGridLayout* gridLayout = (QGridLayout*) layout(); - gridLayout->addWidget(infoLabel, 2, 0, 2, 1); + gridLayout->addWidget(&_progressBar, 2, 0, 2, 1); gridLayout->addWidget(&_cancelButton, 2, 1, 2, 1); gridLayout->addWidget(&_importButton, 2, 2, 2, 1); - + // set ObjectName used in qss for styling + _progressBar.setObjectName("progressBar"); _importButton.setObjectName("importButton"); _cancelButton.setObjectName("cancelButton"); // set fixed size _importButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); _cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + _progressBar.setFixedHeight(7); + _progressBar.setTextVisible(false); // hide unused embedded widgets in QFileDialog QWidget* widget = findChild("lookInCombo"); widget->hide(); - - widget = findChild("backButton"); - widget->hide(); - - widget = findChild("forwardButton"); - widget->hide(); - - widget = findChild("toParentButton"); - widget->hide(); - + widget = findChild("newFolderButton"); widget->hide(); @@ -230,8 +223,18 @@ void ImportDialog::setLayout() { widget = findChild("treeView"); widget->setAttribute(Qt::WA_MacShowFocusRect, false); - + switchToResourcesParentIfRequired(); + + QIcon icon = QIcon("resources/icons/backButton.svg"); + QPushButton* button = (QPushButton*) findChild("backButton"); + //button->setIcon(icon); + + button = (QPushButton*) findChild("forwardButton"); + button = (QPushButton*) findChild("toParentButton"); + + + QFile styleSheet("resources/styles/import_dialog.qss"); if (styleSheet.open(QIODevice::ReadOnly)) { setStyleSheet(styleSheet.readAll()); @@ -281,11 +284,6 @@ void ImportDialog::setImportTypes() { setIconProvider(new HiFiIconProvider(iconsMap)); setNameFilter(importFormatsFilterList); -#ifdef Q_OS_MAC - QString cmdString = ("Command"); -#else - QString cmdString = ("Control"); -#endif setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo)); } } diff --git a/interface/src/ImportDialog.h b/interface/src/ImportDialog.h index 5cfc49e51e..910cd8f789 100644 --- a/interface/src/ImportDialog.h +++ b/interface/src/ImportDialog.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -26,37 +27,42 @@ public: QHash iconsMap; }; +enum dialogMode { + importMode, + loadingMode, + placeMode +}; + class ImportDialog : public QFileDialog { Q_OBJECT public: ImportDialog(QWidget* parent = NULL); - ~ImportDialog(); - void reset(); - + QString getCurrentFile() const { return _currentFile; } - + dialogMode getMode() const { return _mode; } + void setMode(dialogMode mode); + signals: - void accepted(); - + void canceled(); + public slots: - int exec(); - void import(); - void accept(); - void reject(); + void setProgressBarValue(int value); private slots: - void saveCurrentFile(QString); + void accept(); + void saveCurrentFile(QString filename); private: QString _currentFile; + QProgressBar _progressBar; QPushButton _importButton; QPushButton _cancelButton; - + dialogMode _mode; + void setLayout(); void setImportTypes(); - bool fileAccepted; }; #endif /* defined(__hifi__ImportDialog__) */