Add bone attachment edit interface
parent
8007f17f08
commit
6b4192161e
|
@ -22,6 +22,38 @@ BonePropertyWidget::BonePropertyWidget(Document* document,
|
||||||
QVBoxLayout* mainLayout = new QVBoxLayout;
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||||
|
|
||||||
if (nullptr != m_bone) {
|
if (nullptr != m_bone) {
|
||||||
|
m_parentBoneComboBox = new QComboBox;
|
||||||
|
m_parentBoneComboBox->addItem(tr("None"));
|
||||||
|
|
||||||
|
m_parentJointComboBox = new QComboBox;
|
||||||
|
m_parentJointComboBox->addItem(tr("1"));
|
||||||
|
m_parentJointComboBox->setVisible(false);
|
||||||
|
|
||||||
|
QHBoxLayout* parentBoneAndJointLayout = new QHBoxLayout;
|
||||||
|
parentBoneAndJointLayout->addWidget(m_parentBoneComboBox);
|
||||||
|
parentBoneAndJointLayout->addWidget(m_parentJointComboBox);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m_document->boneIdList.size(); ++i) {
|
||||||
|
const auto& boneId = m_document->boneIdList[i];
|
||||||
|
if (boneId == m_boneId)
|
||||||
|
continue;
|
||||||
|
const Document::Bone* bone = m_document->findBone(boneId);
|
||||||
|
if (nullptr == bone)
|
||||||
|
continue;
|
||||||
|
m_parentBoneComboBox->addItem(QIcon(bone->previewPixmap), bone->name, QVariant(QString::fromStdString(boneId.toString())));
|
||||||
|
if (m_bone->attachBoneId == boneId)
|
||||||
|
m_parentBoneComboBox->setCurrentIndex(m_parentBoneComboBox->count() - 1);
|
||||||
|
}
|
||||||
|
updateBoneJointComboBox();
|
||||||
|
|
||||||
|
connect(m_parentBoneComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &BonePropertyWidget::updateBoneJointComboBox);
|
||||||
|
connect(m_parentJointComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &BonePropertyWidget::synchronizeBoneAttachmentFromControls);
|
||||||
|
|
||||||
|
QHBoxLayout* parentLayout = new QHBoxLayout;
|
||||||
|
parentLayout->addWidget(new QLabel(tr("Parent")));
|
||||||
|
parentLayout->addLayout(parentBoneAndJointLayout);
|
||||||
|
parentLayout->addStretch();
|
||||||
|
|
||||||
m_nameEdit = new QLineEdit;
|
m_nameEdit = new QLineEdit;
|
||||||
Theme::initLineEdit(m_nameEdit);
|
Theme::initLineEdit(m_nameEdit);
|
||||||
m_nameEdit->setFixedWidth(Theme::partPreviewImageSize * 2.7);
|
m_nameEdit->setFixedWidth(Theme::partPreviewImageSize * 2.7);
|
||||||
|
@ -51,6 +83,7 @@ BonePropertyWidget::BonePropertyWidget(Document* document,
|
||||||
jointsLayout->addStretch();
|
jointsLayout->addStretch();
|
||||||
jointsLayout->addWidget(nodePicker);
|
jointsLayout->addWidget(nodePicker);
|
||||||
|
|
||||||
|
mainLayout->addLayout(parentLayout);
|
||||||
mainLayout->addLayout(renameLayout);
|
mainLayout->addLayout(renameLayout);
|
||||||
mainLayout->addLayout(jointsLayout);
|
mainLayout->addLayout(jointsLayout);
|
||||||
}
|
}
|
||||||
|
@ -58,6 +91,7 @@ BonePropertyWidget::BonePropertyWidget(Document* document,
|
||||||
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
|
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
|
||||||
|
|
||||||
connect(this, &BonePropertyWidget::renameBone, m_document, &Document::renameBone);
|
connect(this, &BonePropertyWidget::renameBone, m_document, &Document::renameBone);
|
||||||
|
connect(this, &BonePropertyWidget::setBoneAttachment, m_document, &Document::setBoneAttachment);
|
||||||
connect(this, &BonePropertyWidget::groupOperationAdded, m_document, &Document::saveSnapshot);
|
connect(this, &BonePropertyWidget::groupOperationAdded, m_document, &Document::saveSnapshot);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
@ -65,6 +99,35 @@ BonePropertyWidget::BonePropertyWidget(Document* document,
|
||||||
setFixedSize(minimumSizeHint());
|
setFixedSize(minimumSizeHint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dust3d::Uuid BonePropertyWidget::editingParentBoneId()
|
||||||
|
{
|
||||||
|
return dust3d::Uuid(m_parentBoneComboBox->currentData().toString().toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
int BonePropertyWidget::editingParentJointIndex()
|
||||||
|
{
|
||||||
|
return dust3d::String::toInt(m_parentJointComboBox->currentText().toStdString()) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BonePropertyWidget::synchronizeBoneAttachmentFromControls()
|
||||||
|
{
|
||||||
|
if (nullptr == m_bone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto parentBoneId = editingParentBoneId();
|
||||||
|
int parentJointIndex = editingParentJointIndex();
|
||||||
|
|
||||||
|
if (-1 == parentJointIndex) {
|
||||||
|
// The joint control is initializing, ignore
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_bone->attachBoneId == parentBoneId && parentJointIndex == m_bone->attachBoneJointIndex)
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit setBoneAttachment(m_boneId, parentBoneId, parentJointIndex);
|
||||||
|
}
|
||||||
|
|
||||||
void BonePropertyWidget::prepareBoneIds()
|
void BonePropertyWidget::prepareBoneIds()
|
||||||
{
|
{
|
||||||
if (1 == m_boneIds.size()) {
|
if (1 == m_boneIds.size()) {
|
||||||
|
@ -82,3 +145,29 @@ void BonePropertyWidget::nameEditChanged()
|
||||||
emit renameBone(m_boneId, m_nameEdit->text());
|
emit renameBone(m_boneId, m_nameEdit->text());
|
||||||
emit groupOperationAdded();
|
emit groupOperationAdded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BonePropertyWidget::updateBoneJointComboBox()
|
||||||
|
{
|
||||||
|
if (nullptr == m_bone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto parentBoneId = editingParentBoneId();
|
||||||
|
const Document::Bone* parentBone = m_document->findBone(parentBoneId);
|
||||||
|
if (nullptr == parentBone || parentBone->joints.size() < 2) {
|
||||||
|
if (1 == m_parentJointComboBox->count())
|
||||||
|
return;
|
||||||
|
m_parentJointComboBox->clear();
|
||||||
|
m_parentJointComboBox->addItem(tr("1"));
|
||||||
|
m_parentJointComboBox->setVisible(false);
|
||||||
|
synchronizeBoneAttachmentFromControls();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_parentJointComboBox->clear();
|
||||||
|
for (size_t i = 0; i < parentBone->joints.size(); ++i) {
|
||||||
|
m_parentJointComboBox->addItem(QString::number(i + 1));
|
||||||
|
if (i == m_bone->attachBoneJointIndex)
|
||||||
|
m_parentJointComboBox->setCurrentIndex(m_parentJointComboBox->count() - 1);
|
||||||
|
}
|
||||||
|
m_parentJointComboBox->setVisible(true);
|
||||||
|
synchronizeBoneAttachmentFromControls();
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <dust3d/base/uuid.h>
|
#include <dust3d/base/uuid.h>
|
||||||
|
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
class BonePropertyWidget : public QWidget {
|
class BonePropertyWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -14,6 +15,7 @@ signals:
|
||||||
void renameBone(const dust3d::Uuid& boneId, const QString& name);
|
void renameBone(const dust3d::Uuid& boneId, const QString& name);
|
||||||
void groupOperationAdded();
|
void groupOperationAdded();
|
||||||
void pickBoneJoints(const dust3d::Uuid& boneId, size_t joints);
|
void pickBoneJoints(const dust3d::Uuid& boneId, size_t joints);
|
||||||
|
void setBoneAttachment(const dust3d::Uuid& boneId, const dust3d::Uuid& toBoneId, int toBoneJointIndex);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BonePropertyWidget(Document* document,
|
BonePropertyWidget(Document* document,
|
||||||
|
@ -21,6 +23,8 @@ public:
|
||||||
QWidget* parent = nullptr);
|
QWidget* parent = nullptr);
|
||||||
private slots:
|
private slots:
|
||||||
void nameEditChanged();
|
void nameEditChanged();
|
||||||
|
void updateBoneJointComboBox();
|
||||||
|
void synchronizeBoneAttachmentFromControls();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Document* m_document = nullptr;
|
Document* m_document = nullptr;
|
||||||
|
@ -28,8 +32,12 @@ private:
|
||||||
dust3d::Uuid m_boneId;
|
dust3d::Uuid m_boneId;
|
||||||
const Document::Bone* m_bone = nullptr;
|
const Document::Bone* m_bone = nullptr;
|
||||||
QLineEdit* m_nameEdit = nullptr;
|
QLineEdit* m_nameEdit = nullptr;
|
||||||
|
QComboBox* m_parentBoneComboBox = nullptr;
|
||||||
|
QComboBox* m_parentJointComboBox = nullptr;
|
||||||
IntNumberWidget* m_jointsWidget = nullptr;
|
IntNumberWidget* m_jointsWidget = nullptr;
|
||||||
void prepareBoneIds();
|
void prepareBoneIds();
|
||||||
|
dust3d::Uuid editingParentBoneId();
|
||||||
|
int editingParentJointIndex();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue