dust3d/src/cutfacewidget.cpp

61 lines
1.6 KiB
C++

#include "cutfacewidget.h"
CutFaceWidget::CutFaceWidget(const Document *document, QUuid partId) :
m_partId(partId),
m_document(document)
{
setObjectName("CutFaceFrame");
m_previewWidget = new ModelWidget(this);
m_previewWidget->setAttribute(Qt::WA_TransparentForMouseEvents);
m_previewWidget->setFixedSize(Theme::cutFacePreviewImageSize, Theme::cutFacePreviewImageSize);
m_previewWidget->enableMove(false);
m_previewWidget->enableZoom(false);
setFixedSize(Theme::cutFacePreviewImageSize, CutFaceWidget::preferredHeight());
connect(document, &Document::partPreviewChanged, this, &CutFaceWidget::updatePreview);
}
void CutFaceWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
m_previewWidget->move((width() - Theme::cutFacePreviewImageSize) / 2, 0);
}
int CutFaceWidget::preferredHeight()
{
return Theme::cutFacePreviewImageSize;
}
void CutFaceWidget::reload()
{
updatePreview(m_partId);
}
void CutFaceWidget::updatePreview(QUuid partId)
{
if (partId != m_partId)
return;
const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) {
qDebug() << "Part not found:" << m_partId;
return;
}
MeshLoader *previewMesh = part->takePreviewMesh();
m_previewWidget->updateMesh(previewMesh);
}
void CutFaceWidget::updateCheckedState(bool checked)
{
if (checked)
setStyleSheet("#CutFaceFrame {border: 1px solid " + Theme::red.name() + ";}");
else
setStyleSheet("#CutFaceFrame {border: 1px solid transparent;}");
}
ModelWidget *CutFaceWidget::previewWidget()
{
return m_previewWidget;
}