More work on attachment interface.

This commit is contained in:
Andrzej Kapolka 2014-05-05 13:41:50 -07:00
parent e898b4a900
commit 65e34f9697
4 changed files with 89 additions and 12 deletions

View file

@ -15,6 +15,7 @@
#include <QFormLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QVBoxLayout>
#include "Application.h"
@ -29,6 +30,14 @@ AttachmentsDialog::AttachmentsDialog() :
QVBoxLayout* layout = new QVBoxLayout();
setLayout(layout);
QScrollArea* area = new QScrollArea();
layout->addWidget(area);
area->setWidgetResizable(true);
QWidget* container = new QWidget();
container->setLayout(_attachments = new QVBoxLayout());
container->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
area->setWidget(container);
foreach (const AttachmentData& data, Application::getInstance()->getAvatar()->getAttachmentData()) {
addAttachment(data);
}
@ -40,47 +49,99 @@ AttachmentsDialog::AttachmentsDialog() :
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
layout->addWidget(buttons);
connect(buttons, SIGNAL(accepted()), SLOT(deleteLater()));
setMinimumSize(600, 600);
}
void AttachmentsDialog::updateAttachmentData() {
QVector<AttachmentData> data;
for (int i = 0; i < _attachments->count(); i++) {
data.append(static_cast<AttachmentPanel*>(_attachments->itemAt(i)->widget())->getAttachmentData());
}
Application::getInstance()->getAvatar()->setAttachmentData(data);
}
void AttachmentsDialog::addAttachment(const AttachmentData& data) {
QVBoxLayout* layout = static_cast<QVBoxLayout*>(this->layout());
layout->insertWidget(layout->count() - 2, new AttachmentPanel(data));
_attachments->addWidget(new AttachmentPanel(this, data));
}
AttachmentPanel::AttachmentPanel(const AttachmentData& data) {
static QDoubleSpinBox* createTranslationBox(AttachmentsDialog* dialog, float value) {
QDoubleSpinBox* box = new QDoubleSpinBox();
box->setSingleStep(0.01);
box->setMinimum(-FLT_MAX);
box->setMaximum(FLT_MAX);
box->setValue(value);
dialog->connect(box, SIGNAL(valueChanged(double)), SLOT(updateAttachmentData()));
return box;
}
static QDoubleSpinBox* createRotationBox(AttachmentsDialog* dialog, float value) {
QDoubleSpinBox* box = new QDoubleSpinBox();
box->setMinimum(-180.0);
box->setMaximum(180.0);
box->setWrapping(true);
box->setValue(value);
dialog->connect(box, SIGNAL(valueChanged(double)), SLOT(updateAttachmentData()));
return box;
}
AttachmentPanel::AttachmentPanel(AttachmentsDialog* dialog, const AttachmentData& data) {
QFormLayout* layout = new QFormLayout();
setLayout(layout);
QHBoxLayout* urlBox = new QHBoxLayout();
layout->addRow("Model URL:", urlBox);
urlBox->addWidget(_modelURL = new QLineEdit(data.modelURL.toString()), 1);
_modelURL->setText(data.modelURL.toString());
dialog->connect(_modelURL, SIGNAL(returnPressed()), SLOT(updateAttachmentData()));
QPushButton* chooseURL = new QPushButton("Choose");
urlBox->addWidget(chooseURL);
connect(chooseURL, SIGNAL(clicked(bool)), SLOT(chooseModelURL()));
layout->addRow("Joint:", _jointName = new QComboBox());
QSharedPointer<NetworkGeometry> geometry = Application::getInstance()->getAvatar()->getSkeletonModel().getGeometry();
if (geometry && geometry->isLoaded()) {
foreach (const FBXJoint& joint, geometry->getFBXGeometry().joints) {
_jointName->addItem(joint.name);
}
}
_jointName->setCurrentText(data.jointName);
dialog->connect(_jointName, SIGNAL(currentIndexChanged(int)), SLOT(updateAttachmentData()));
QHBoxLayout* translationBox = new QHBoxLayout();
translationBox->addWidget(_translationX = new QDoubleSpinBox());
translationBox->addWidget(_translationY = new QDoubleSpinBox());
translationBox->addWidget(_translationZ = new QDoubleSpinBox());
translationBox->addWidget(_translationX = createTranslationBox(dialog, data.translation.x));
translationBox->addWidget(_translationY = createTranslationBox(dialog, data.translation.y));
translationBox->addWidget(_translationZ = createTranslationBox(dialog, data.translation.z));
layout->addRow("Translation:", translationBox);
QHBoxLayout* rotationBox = new QHBoxLayout();
rotationBox->addWidget(_rotationX = new QDoubleSpinBox());
rotationBox->addWidget(_rotationY = new QDoubleSpinBox());
rotationBox->addWidget(_rotationZ = new QDoubleSpinBox());
glm::vec3 eulers = glm::degrees(safeEulerAngles(data.rotation));
rotationBox->addWidget(_rotationX = createRotationBox(dialog, eulers.x));
rotationBox->addWidget(_rotationY = createRotationBox(dialog, eulers.y));
rotationBox->addWidget(_rotationZ = createRotationBox(dialog, eulers.z));
layout->addRow("Rotation:", rotationBox);
layout->addRow("Scale:", _scale = new QDoubleSpinBox());
_scale->setSingleStep(0.01);
_scale->setMaximum(FLT_MAX);
_scale->setValue(data.scale);
dialog->connect(_scale, SIGNAL(valueChanged(double)), SLOT(updateAttachmentData()));
QPushButton* remove = new QPushButton("Delete");
layout->addRow(remove);
connect(remove, SIGNAL(clicked(bool)), SLOT(deleteLater()));
}
AttachmentData AttachmentPanel::getAttachmentData() const {
AttachmentData data;
data.modelURL = _modelURL->text();
data.jointName = _jointName->currentText();
data.translation = glm::vec3(_translationX->value(), _translationY->value(), _translationZ->value());
data.rotation = glm::quat(glm::radians(glm::vec3(_rotationX->value(), _rotationY->value(), _rotationZ->value())));
data.scale = _scale->value();
return data;
}
void AttachmentPanel::chooseModelURL() {
ModelsBrowser modelBrowser(ATTACHMENT_MODEL, this);
connect(&modelBrowser, SIGNAL(selected(QString)), SLOT(setModelURL(const QString&)));
@ -89,4 +150,5 @@ void AttachmentPanel::chooseModelURL() {
void AttachmentPanel::setModelURL(const QString& url) {
_modelURL->setText(url);
emit _modelURL->returnPressed();
}

View file

@ -19,6 +19,7 @@
class QComboBox;
class QDoubleSpinner;
class QLineEdit;
class QVBoxLayout;
/// Allows users to edit the avatar attachments.
class AttachmentsDialog : public QDialog {
@ -28,9 +29,17 @@ public:
AttachmentsDialog();
public slots:
void updateAttachmentData();
private slots:
void addAttachment(const AttachmentData& data = AttachmentData());
private:
QVBoxLayout* _attachments;
};
/// A panel controlling a single attachment.
@ -39,7 +48,9 @@ class AttachmentPanel : public QWidget {
public:
AttachmentPanel(const AttachmentData& data = AttachmentData());
AttachmentPanel(AttachmentsDialog* dialog, const AttachmentData& data = AttachmentData());
AttachmentData getAttachmentData() const;
private slots:

View file

@ -662,8 +662,6 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) {
void AvatarData::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
_attachmentData = attachmentData;
qDebug() << "Changing attachment data for avatar.";
}
void AvatarData::setDisplayName(const QString& displayName) {
@ -775,6 +773,10 @@ void AvatarData::updateJointMappings() {
}
}
AttachmentData::AttachmentData() :
scale(1.0f) {
}
bool AttachmentData::operator==(const AttachmentData& other) const {
return modelURL == other.modelURL && jointName == other.jointName && translation == other.translation &&
rotation == other.rotation && scale == other.scale;

View file

@ -324,6 +324,8 @@ public:
glm::quat rotation;
float scale;
AttachmentData();
bool operator==(const AttachmentData& other) const;
};