From 65e34f9697defaef4e1ef854bcd9f1d19e2a453f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 5 May 2014 13:41:50 -0700 Subject: [PATCH] More work on attachment interface. --- interface/src/ui/AttachmentsDialog.cpp | 80 +++++++++++++++++++++++--- interface/src/ui/AttachmentsDialog.h | 13 ++++- libraries/avatars/src/AvatarData.cpp | 6 +- libraries/avatars/src/AvatarData.h | 2 + 4 files changed, 89 insertions(+), 12 deletions(-) diff --git a/interface/src/ui/AttachmentsDialog.cpp b/interface/src/ui/AttachmentsDialog.cpp index 34c1f251e1..38ef10625f 100644 --- a/interface/src/ui/AttachmentsDialog.cpp +++ b/interface/src/ui/AttachmentsDialog.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #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 data; + for (int i = 0; i < _attachments->count(); i++) { + data.append(static_cast(_attachments->itemAt(i)->widget())->getAttachmentData()); + } + Application::getInstance()->getAvatar()->setAttachmentData(data); } void AttachmentsDialog::addAttachment(const AttachmentData& data) { - QVBoxLayout* layout = static_cast(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 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(); } diff --git a/interface/src/ui/AttachmentsDialog.h b/interface/src/ui/AttachmentsDialog.h index e8c173f80a..c23bd2efb8 100644 --- a/interface/src/ui/AttachmentsDialog.h +++ b/interface/src/ui/AttachmentsDialog.h @@ -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: diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 485b5517f0..bbfff8f025 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -662,8 +662,6 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) { void AvatarData::setAttachmentData(const QVector& 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; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index a853706005..97fad639cd 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -324,6 +324,8 @@ public: glm::quat rotation; float scale; + AttachmentData(); + bool operator==(const AttachmentData& other) const; };