mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:17:02 +02:00
More work on attachment interface.
This commit is contained in:
parent
e898b4a900
commit
65e34f9697
4 changed files with 89 additions and 12 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QScrollArea>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
@ -29,6 +30,14 @@ AttachmentsDialog::AttachmentsDialog() :
|
||||||
QVBoxLayout* layout = new QVBoxLayout();
|
QVBoxLayout* layout = new QVBoxLayout();
|
||||||
setLayout(layout);
|
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()) {
|
foreach (const AttachmentData& data, Application::getInstance()->getAvatar()->getAttachmentData()) {
|
||||||
addAttachment(data);
|
addAttachment(data);
|
||||||
}
|
}
|
||||||
|
@ -40,47 +49,99 @@ AttachmentsDialog::AttachmentsDialog() :
|
||||||
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||||
layout->addWidget(buttons);
|
layout->addWidget(buttons);
|
||||||
connect(buttons, SIGNAL(accepted()), SLOT(deleteLater()));
|
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) {
|
void AttachmentsDialog::addAttachment(const AttachmentData& data) {
|
||||||
QVBoxLayout* layout = static_cast<QVBoxLayout*>(this->layout());
|
_attachments->addWidget(new AttachmentPanel(this, data));
|
||||||
layout->insertWidget(layout->count() - 2, new AttachmentPanel(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();
|
QFormLayout* layout = new QFormLayout();
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
QHBoxLayout* urlBox = new QHBoxLayout();
|
QHBoxLayout* urlBox = new QHBoxLayout();
|
||||||
layout->addRow("Model URL:", urlBox);
|
layout->addRow("Model URL:", urlBox);
|
||||||
urlBox->addWidget(_modelURL = new QLineEdit(data.modelURL.toString()), 1);
|
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");
|
QPushButton* chooseURL = new QPushButton("Choose");
|
||||||
urlBox->addWidget(chooseURL);
|
urlBox->addWidget(chooseURL);
|
||||||
connect(chooseURL, SIGNAL(clicked(bool)), SLOT(chooseModelURL()));
|
connect(chooseURL, SIGNAL(clicked(bool)), SLOT(chooseModelURL()));
|
||||||
|
|
||||||
layout->addRow("Joint:", _jointName = new QComboBox());
|
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();
|
QHBoxLayout* translationBox = new QHBoxLayout();
|
||||||
translationBox->addWidget(_translationX = new QDoubleSpinBox());
|
translationBox->addWidget(_translationX = createTranslationBox(dialog, data.translation.x));
|
||||||
translationBox->addWidget(_translationY = new QDoubleSpinBox());
|
translationBox->addWidget(_translationY = createTranslationBox(dialog, data.translation.y));
|
||||||
translationBox->addWidget(_translationZ = new QDoubleSpinBox());
|
translationBox->addWidget(_translationZ = createTranslationBox(dialog, data.translation.z));
|
||||||
layout->addRow("Translation:", translationBox);
|
layout->addRow("Translation:", translationBox);
|
||||||
|
|
||||||
QHBoxLayout* rotationBox = new QHBoxLayout();
|
QHBoxLayout* rotationBox = new QHBoxLayout();
|
||||||
rotationBox->addWidget(_rotationX = new QDoubleSpinBox());
|
glm::vec3 eulers = glm::degrees(safeEulerAngles(data.rotation));
|
||||||
rotationBox->addWidget(_rotationY = new QDoubleSpinBox());
|
rotationBox->addWidget(_rotationX = createRotationBox(dialog, eulers.x));
|
||||||
rotationBox->addWidget(_rotationZ = new QDoubleSpinBox());
|
rotationBox->addWidget(_rotationY = createRotationBox(dialog, eulers.y));
|
||||||
|
rotationBox->addWidget(_rotationZ = createRotationBox(dialog, eulers.z));
|
||||||
layout->addRow("Rotation:", rotationBox);
|
layout->addRow("Rotation:", rotationBox);
|
||||||
|
|
||||||
layout->addRow("Scale:", _scale = new QDoubleSpinBox());
|
layout->addRow("Scale:", _scale = new QDoubleSpinBox());
|
||||||
_scale->setSingleStep(0.01);
|
_scale->setSingleStep(0.01);
|
||||||
_scale->setMaximum(FLT_MAX);
|
_scale->setMaximum(FLT_MAX);
|
||||||
|
_scale->setValue(data.scale);
|
||||||
|
dialog->connect(_scale, SIGNAL(valueChanged(double)), SLOT(updateAttachmentData()));
|
||||||
|
|
||||||
QPushButton* remove = new QPushButton("Delete");
|
QPushButton* remove = new QPushButton("Delete");
|
||||||
layout->addRow(remove);
|
layout->addRow(remove);
|
||||||
connect(remove, SIGNAL(clicked(bool)), SLOT(deleteLater()));
|
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() {
|
void AttachmentPanel::chooseModelURL() {
|
||||||
ModelsBrowser modelBrowser(ATTACHMENT_MODEL, this);
|
ModelsBrowser modelBrowser(ATTACHMENT_MODEL, this);
|
||||||
connect(&modelBrowser, SIGNAL(selected(QString)), SLOT(setModelURL(const QString&)));
|
connect(&modelBrowser, SIGNAL(selected(QString)), SLOT(setModelURL(const QString&)));
|
||||||
|
@ -89,4 +150,5 @@ void AttachmentPanel::chooseModelURL() {
|
||||||
|
|
||||||
void AttachmentPanel::setModelURL(const QString& url) {
|
void AttachmentPanel::setModelURL(const QString& url) {
|
||||||
_modelURL->setText(url);
|
_modelURL->setText(url);
|
||||||
|
emit _modelURL->returnPressed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
class QDoubleSpinner;
|
class QDoubleSpinner;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
class QVBoxLayout;
|
||||||
|
|
||||||
/// Allows users to edit the avatar attachments.
|
/// Allows users to edit the avatar attachments.
|
||||||
class AttachmentsDialog : public QDialog {
|
class AttachmentsDialog : public QDialog {
|
||||||
|
@ -28,9 +29,17 @@ public:
|
||||||
|
|
||||||
AttachmentsDialog();
|
AttachmentsDialog();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void updateAttachmentData();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void addAttachment(const AttachmentData& data = AttachmentData());
|
void addAttachment(const AttachmentData& data = AttachmentData());
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QVBoxLayout* _attachments;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A panel controlling a single attachment.
|
/// A panel controlling a single attachment.
|
||||||
|
@ -39,7 +48,9 @@ class AttachmentPanel : public QWidget {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AttachmentPanel(const AttachmentData& data = AttachmentData());
|
AttachmentPanel(AttachmentsDialog* dialog, const AttachmentData& data = AttachmentData());
|
||||||
|
|
||||||
|
AttachmentData getAttachmentData() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
|
|
@ -662,8 +662,6 @@ void AvatarData::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||||
|
|
||||||
void AvatarData::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
|
void AvatarData::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
|
||||||
_attachmentData = attachmentData;
|
_attachmentData = attachmentData;
|
||||||
|
|
||||||
qDebug() << "Changing attachment data for avatar.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarData::setDisplayName(const QString& displayName) {
|
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 {
|
bool AttachmentData::operator==(const AttachmentData& other) const {
|
||||||
return modelURL == other.modelURL && jointName == other.jointName && translation == other.translation &&
|
return modelURL == other.modelURL && jointName == other.jointName && translation == other.translation &&
|
||||||
rotation == other.rotation && scale == other.scale;
|
rotation == other.rotation && scale == other.scale;
|
||||||
|
|
|
@ -324,6 +324,8 @@ public:
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
float scale;
|
float scale;
|
||||||
|
|
||||||
|
AttachmentData();
|
||||||
|
|
||||||
bool operator==(const AttachmentData& other) const;
|
bool operator==(const AttachmentData& other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue