2021-11-18 14:58:01 +00:00
|
|
|
#include "material_manage_widget.h"
|
2020-12-19 02:29:24 +00:00
|
|
|
#include "document.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include "info_label.h"
|
|
|
|
#include "material_edit_widget.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
2018-10-09 02:19:12 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
MaterialManageWidget::MaterialManageWidget(const Document* document, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, m_document(document)
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
2022-10-18 09:35:04 +00:00
|
|
|
QPushButton* addMaterialButton = new QPushButton(Theme::awesome()->icon(fa::plus), tr("Add Material..."));
|
2018-10-09 02:19:12 +00:00
|
|
|
|
|
|
|
connect(addMaterialButton, &QPushButton::clicked, this, &MaterialManageWidget::showAddMaterialDialog);
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
QHBoxLayout* toolsLayout = new QHBoxLayout;
|
2018-10-09 02:19:12 +00:00
|
|
|
toolsLayout->addWidget(addMaterialButton);
|
|
|
|
|
|
|
|
m_materialListWidget = new MaterialListWidget(document);
|
|
|
|
connect(m_materialListWidget, &MaterialListWidget::modifyMaterial, this, &MaterialManageWidget::showMaterialDialog);
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
2018-10-09 02:19:12 +00:00
|
|
|
mainLayout->addLayout(toolsLayout);
|
|
|
|
mainLayout->addWidget(m_materialListWidget);
|
|
|
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
MaterialListWidget* MaterialManageWidget::materialListWidget()
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
return m_materialListWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize MaterialManageWidget::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(Theme::sidebarPreferredWidth, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialManageWidget::showAddMaterialDialog()
|
|
|
|
{
|
2021-11-18 14:58:01 +00:00
|
|
|
showMaterialDialog(dust3d::Uuid());
|
2018-10-09 02:19:12 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
void MaterialManageWidget::showMaterialDialog(dust3d::Uuid materialId)
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
2022-10-18 09:35:04 +00:00
|
|
|
MaterialEditWidget* materialEditWidget = new MaterialEditWidget(m_document);
|
2018-10-09 02:19:12 +00:00
|
|
|
materialEditWidget->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
if (!materialId.isNull()) {
|
2022-10-18 09:35:04 +00:00
|
|
|
const Material* material = m_document->findMaterial(materialId);
|
2018-10-09 02:19:12 +00:00
|
|
|
if (nullptr != material) {
|
|
|
|
materialEditWidget->setEditMaterialId(materialId);
|
|
|
|
materialEditWidget->setEditMaterialName(material->name);
|
|
|
|
materialEditWidget->setEditMaterialLayers(material->layers);
|
|
|
|
materialEditWidget->clearUnsaveState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
materialEditWidget->show();
|
|
|
|
connect(materialEditWidget, &QDialog::destroyed, [=]() {
|
2022-10-18 09:35:04 +00:00
|
|
|
emit unregisterDialog((QWidget*)materialEditWidget);
|
2018-10-09 02:19:12 +00:00
|
|
|
});
|
2022-10-18 09:35:04 +00:00
|
|
|
emit registerDialog((QWidget*)materialEditWidget);
|
2018-10-09 02:19:12 +00:00
|
|
|
}
|