ModelSelector implementation

This commit is contained in:
Atlante45 2015-03-10 11:49:07 +01:00
parent 60867cc931
commit f55e9b6c1c
2 changed files with 108 additions and 0 deletions

View file

@ -9,4 +9,81 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QDialogButtonBox>
#include <QComboBox>
#include <QFileDialog>
#include <QFormLayout>
#include <QPushButton>
#include <QStandardPaths>
#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<QString> 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());
}
}

View file

@ -12,4 +12,35 @@
#ifndef hifi_ModelSelector_h
#define hifi_ModelSelector_h
#include <QDialog>
#include <QFileInfo>
#include <SettingHandle.h>
#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