2018-10-09 02:19:12 +00:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include "materialmanagewidget.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "materialeditwidget.h"
|
|
|
|
#include "infolabel.h"
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
MaterialManageWidget::MaterialManageWidget(const Document *document, QWidget *parent) :
|
2018-10-09 02:19:12 +00:00
|
|
|
QWidget(parent),
|
|
|
|
m_document(document)
|
|
|
|
{
|
|
|
|
QPushButton *addMaterialButton = new QPushButton(Theme::awesome()->icon(fa::plus), tr("Add Material..."));
|
|
|
|
|
|
|
|
connect(addMaterialButton, &QPushButton::clicked, this, &MaterialManageWidget::showAddMaterialDialog);
|
|
|
|
|
|
|
|
QHBoxLayout *toolsLayout = new QHBoxLayout;
|
|
|
|
toolsLayout->addWidget(addMaterialButton);
|
|
|
|
|
|
|
|
m_materialListWidget = new MaterialListWidget(document);
|
|
|
|
connect(m_materialListWidget, &MaterialListWidget::modifyMaterial, this, &MaterialManageWidget::showMaterialDialog);
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->addLayout(toolsLayout);
|
|
|
|
mainLayout->addWidget(m_materialListWidget);
|
|
|
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
MaterialListWidget *MaterialManageWidget::materialListWidget()
|
|
|
|
{
|
|
|
|
return m_materialListWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize MaterialManageWidget::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(Theme::sidebarPreferredWidth, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialManageWidget::showAddMaterialDialog()
|
|
|
|
{
|
|
|
|
showMaterialDialog(QUuid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaterialManageWidget::showMaterialDialog(QUuid materialId)
|
|
|
|
{
|
|
|
|
MaterialEditWidget *materialEditWidget = new MaterialEditWidget(m_document);
|
|
|
|
materialEditWidget->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
if (!materialId.isNull()) {
|
2018-10-25 00:19:38 +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, [=]() {
|
|
|
|
emit unregisterDialog((QWidget *)materialEditWidget);
|
|
|
|
});
|
|
|
|
emit registerDialog((QWidget *)materialEditWidget);
|
|
|
|
}
|