diff --git a/interface/src/ModelSelector.cpp b/interface/src/ModelSelector.cpp index 3ab0aaf21d..97c7f780e2 100644 --- a/interface/src/ModelSelector.cpp +++ b/interface/src/ModelSelector.cpp @@ -9,4 +9,81 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include +#include +#include +#include +#include + #include "ModelSelector.h" + +static const QString AVATAR_HEAD_STRING = "Avatar Head"; +static const QString AVATAR_BODY_STRING = "Avatar Body"; +static const QString AVATAR_ATTACHEMENT_STRING = "Avatar Attachment"; +static const QString ENTITY_MODEL_STRING = "Entity Model"; + +ModelSelector::ModelSelector() { + QFormLayout* form = new QFormLayout(this); + + setWindowTitle("Select Model"); + setLayout(form); + + _browseButton = new QPushButton("Browse", this); + connect(_browseButton, &QPushButton::clicked, this, &ModelSelector::browse); + form->addRow("Model File:", _browseButton); + + _modelType = new QComboBox(this); + _modelType->addItem(AVATAR_HEAD_STRING); + _modelType->addItem(AVATAR_BODY_STRING); + _modelType->addItem(AVATAR_ATTACHEMENT_STRING); + _modelType->addItem(ENTITY_MODEL_STRING); + form->addRow("Model Type:", _modelType); + + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + connect(buttons, &QDialogButtonBox::accepted, this, &ModelSelector::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); + form->addRow(buttons); +} + +QFileInfo ModelSelector::getFileInfo() const { + return _modelFile; +} + +ModelType ModelSelector::getModelType() const { + QString text = _modelType->currentText(); + + if (text == AVATAR_HEAD_STRING) { + return HEAD_MODEL; + } else if (text == AVATAR_BODY_STRING) { + return SKELETON_MODEL; + } else if (text == AVATAR_ATTACHEMENT_STRING) { + return ATTACHMENT_MODEL; + } else if (text == ENTITY_MODEL_STRING) { + return ENTITY_MODEL; + } else { + Q_UNREACHABLE(); + } +} + +void ModelSelector::accept() { + if (!_modelFile.isFile()) { + return; + } + QDialog::accept(); +} + +void ModelSelector::browse() { + static Setting::Handle lastModelBrowseLocation("LastModelBrowseLocation", + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); + QString filename = QFileDialog::getOpenFileName(NULL, "Select your model file ...", + lastModelBrowseLocation.get(), + "Model files (*.fst *.fbx)"); + QFileInfo fileInfo(filename); + + if (fileInfo.isFile() && fileInfo.completeSuffix().contains(QRegExp("fst|fbx"))) { + _modelFile = fileInfo; + _browseButton->setText(fileInfo.fileName()); + lastModelBrowseLocation.set(fileInfo.path()); + } +} \ No newline at end of file diff --git a/interface/src/ModelSelector.h b/interface/src/ModelSelector.h index 4865357598..aaa35e01c3 100644 --- a/interface/src/ModelSelector.h +++ b/interface/src/ModelSelector.h @@ -12,4 +12,35 @@ #ifndef hifi_ModelSelector_h #define hifi_ModelSelector_h +#include +#include + +#include + +#include "ui/ModelsBrowser.h" + +class QComboBox; +class QPushButton; + +class ModelSelector : public QDialog { + Q_OBJECT + +public: + ModelSelector(); + + QFileInfo getFileInfo() const; + ModelType getModelType() const; + + public slots: + virtual void accept(); + + private slots: + void browse(); + +private: + QFileInfo _modelFile; + QPushButton* _browseButton; + QComboBox* _modelType; +}; + #endif // hifi_ModelSelector_h \ No newline at end of file