dust3d/application/sources/bone_property_widget.cc

83 lines
2.5 KiB
C++
Raw Normal View History

2022-11-11 12:06:06 +00:00
#include "bone_property_widget.h"
#include "float_number_widget.h"
#include "image_preview_widget.h"
#include "theme.h"
2022-11-16 10:58:13 +00:00
#include <QComboBox>
2022-11-11 12:06:06 +00:00
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLineEdit>
2022-11-11 12:06:06 +00:00
#include <QPushButton>
#include <QVBoxLayout>
#include <unordered_set>
BonePropertyWidget::BonePropertyWidget(Document* document,
const std::vector<dust3d::Uuid>& boneIds,
QWidget* parent)
: QWidget(parent)
, m_document(document)
, m_boneIds(boneIds)
{
prepareBoneIds();
QVBoxLayout* mainLayout = new QVBoxLayout;
if (nullptr != m_bone) {
m_nameEdit = new QLineEdit;
Theme::initLineEdit(m_nameEdit);
m_nameEdit->setFixedWidth(Theme::partPreviewImageSize * 2.7);
m_nameEdit->setText(m_bone->name);
connect(m_nameEdit, &QLineEdit::textChanged, this, &BonePropertyWidget::nameEditChanged);
QHBoxLayout* renameLayout = new QHBoxLayout;
renameLayout->addWidget(new QLabel(tr("Name")));
renameLayout->addWidget(m_nameEdit);
renameLayout->addStretch();
2022-11-16 10:58:13 +00:00
m_jointsWidget = new IntNumberWidget;
m_jointsWidget->setRange(2, 10);
QPushButton* nodePicker = new QPushButton(QChar(fa::eyedropper));
nodePicker->setToolTip(tr("Click node one by one on canvas as joints in order"));
Theme::initIconButton(nodePicker);
connect(nodePicker, &QPushButton::clicked, this, &BonePropertyWidget::pickBoneJoints);
QHBoxLayout* jointsLayout = new QHBoxLayout;
jointsLayout->addWidget(new QLabel(tr("Joints")));
jointsLayout->addWidget(m_jointsWidget);
jointsLayout->addStretch();
jointsLayout->addWidget(nodePicker);
mainLayout->addLayout(renameLayout);
2022-11-16 10:58:13 +00:00
mainLayout->addLayout(jointsLayout);
}
2022-11-11 12:06:06 +00:00
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
connect(this, &BonePropertyWidget::renameBone, m_document, &Document::renameBone);
2022-11-11 12:06:06 +00:00
connect(this, &BonePropertyWidget::groupOperationAdded, m_document, &Document::saveSnapshot);
setLayout(mainLayout);
setFixedSize(minimumSizeHint());
}
void BonePropertyWidget::prepareBoneIds()
{
if (1 == m_boneIds.size()) {
m_bone = m_document->findBone(m_boneIds.front());
if (nullptr != m_bone)
m_boneId = m_boneIds.front();
}
}
void BonePropertyWidget::nameEditChanged()
{
const Document::Bone* bone = m_document->findBone(m_boneId);
if (nullptr == bone)
return;
emit renameBone(m_boneId, m_nameEdit->text());
emit groupOperationAdded();
}