2018-05-10 09:16:22 +00:00
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
2018-09-14 09:45:05 +00:00
|
|
|
#include <QComboBox>
|
2018-05-10 09:16:22 +00:00
|
|
|
#include "exportpreviewwidget.h"
|
|
|
|
#include "aboutwidget.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "theme.h"
|
2018-09-21 07:10:18 +00:00
|
|
|
#include "dust3dutil.h"
|
2018-05-10 09:16:22 +00:00
|
|
|
|
|
|
|
ExportPreviewWidget::ExportPreviewWidget(SkeletonDocument *document, QWidget *parent) :
|
2018-09-21 07:10:18 +00:00
|
|
|
QDialog(parent),
|
2018-05-10 09:16:22 +00:00
|
|
|
m_document(document),
|
|
|
|
m_previewLabel(nullptr),
|
|
|
|
m_spinnerWidget(nullptr)
|
|
|
|
{
|
2018-09-14 09:45:05 +00:00
|
|
|
QHBoxLayout *toolButtonLayout = new QHBoxLayout;
|
2018-05-10 09:16:22 +00:00
|
|
|
toolButtonLayout->setSpacing(0);
|
2018-09-14 09:45:05 +00:00
|
|
|
//toolButtonLayout->setContentsMargins(5, 10, 4, 0);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
|
|
|
m_previewLabel = new QLabel;
|
|
|
|
m_previewLabel->setMinimumSize(128, 128);
|
|
|
|
m_previewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
//QPushButton *regenerateButton = new QPushButton(QChar(fa::recycle));
|
|
|
|
//initAwesomeButton(regenerateButton);
|
|
|
|
QPushButton *regenerateButton = new QPushButton(tr("Regenerate"));
|
2018-05-10 09:16:22 +00:00
|
|
|
connect(this, &ExportPreviewWidget::regenerate, this, &ExportPreviewWidget::checkSpinner);
|
|
|
|
connect(regenerateButton, &QPushButton::clicked, this, &ExportPreviewWidget::regenerate);
|
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
//m_saveButton = new QPushButton(QChar(fa::save));
|
|
|
|
//initAwesomeButton(m_saveButton);
|
|
|
|
m_saveButton = new QPushButton(tr("Save"));
|
2018-05-10 09:16:22 +00:00
|
|
|
connect(m_saveButton, &QPushButton::clicked, this, &ExportPreviewWidget::save);
|
|
|
|
m_saveButton->hide();
|
2018-09-21 07:10:18 +00:00
|
|
|
m_saveButton->setDefault(true);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
QComboBox *exportFormatSelectBox = new QComboBox;
|
|
|
|
exportFormatSelectBox->addItem(tr("glTF"));
|
|
|
|
exportFormatSelectBox->setCurrentIndex(0);
|
|
|
|
|
|
|
|
toolButtonLayout->addWidget(exportFormatSelectBox);
|
2018-05-10 09:16:22 +00:00
|
|
|
toolButtonLayout->addWidget(regenerateButton);
|
|
|
|
toolButtonLayout->addStretch();
|
2018-09-14 09:45:05 +00:00
|
|
|
toolButtonLayout->addWidget(m_saveButton);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
|
|
|
QGridLayout *containerLayout = new QGridLayout;
|
|
|
|
containerLayout->setSpacing(0);
|
|
|
|
containerLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
containerLayout->addWidget(m_previewLabel);
|
|
|
|
containerLayout->setRowStretch(0, 1);
|
|
|
|
containerLayout->setColumnStretch(0, 1);
|
|
|
|
|
|
|
|
m_textureRenderWidget = new ModelWidget;
|
2018-08-27 08:50:40 +00:00
|
|
|
m_textureRenderWidget->setMinimumSize(128, 128);
|
|
|
|
m_textureRenderWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
|
|
|
QVBoxLayout *renderLayout = new QVBoxLayout;
|
|
|
|
renderLayout->setSpacing(0);
|
|
|
|
renderLayout->setContentsMargins(20, 0, 20, 0);
|
|
|
|
renderLayout->addWidget(m_textureRenderWidget);
|
|
|
|
|
2018-09-21 07:10:18 +00:00
|
|
|
QWidget *hrLightWidget = Theme::createHorizontalLineWidget();
|
2018-09-14 09:45:05 +00:00
|
|
|
|
|
|
|
QHBoxLayout *topLayout = new QHBoxLayout;
|
|
|
|
topLayout->setSpacing(0);
|
|
|
|
topLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
topLayout->addLayout(containerLayout);
|
|
|
|
topLayout->addLayout(renderLayout);
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->addLayout(topLayout);
|
|
|
|
mainLayout->addWidget(hrLightWidget);
|
2018-05-10 09:16:22 +00:00
|
|
|
mainLayout->addLayout(toolButtonLayout);
|
|
|
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
setMinimumSize(256, 256);
|
|
|
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
|
|
|
|
|
m_spinnerWidget = new WaitingSpinnerWidget(m_previewLabel);
|
|
|
|
m_spinnerWidget->setColor(Theme::white);
|
|
|
|
m_spinnerWidget->setInnerRadius(Theme::miniIconFontSize / 4);
|
|
|
|
m_spinnerWidget->setNumberOfLines(12);
|
|
|
|
m_spinnerWidget->hide();
|
|
|
|
|
2018-09-21 07:10:18 +00:00
|
|
|
setWindowTitle(unifiedWindowTitle(tr("Export")));
|
2018-06-15 05:34:41 +00:00
|
|
|
|
|
|
|
emit updateTexturePreview();
|
2018-05-10 09:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::updateTexturePreviewImage(const QImage &image)
|
|
|
|
{
|
|
|
|
m_previewImage = image;
|
|
|
|
resizePreviewImage();
|
|
|
|
checkSpinner();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
resizePreviewImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::resizePreviewImage()
|
|
|
|
{
|
|
|
|
QPixmap pixmap = QPixmap::fromImage(m_previewImage);
|
|
|
|
m_previewLabel->setPixmap(pixmap.scaled(m_previewLabel->width(), m_previewLabel->height(), Qt::KeepAspectRatio));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::initAwesomeButton(QPushButton *button)
|
|
|
|
{
|
|
|
|
button->setFont(Theme::awesome()->font(Theme::toolIconFontSize));
|
|
|
|
button->setFixedSize(Theme::toolIconSize, Theme::toolIconSize);
|
|
|
|
button->setStyleSheet("QPushButton {color: #f7d9c8}");
|
|
|
|
button->setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QWidget::showEvent(event);
|
|
|
|
checkSpinner();
|
2018-09-22 10:31:02 +00:00
|
|
|
if (m_document->isPostProcessResultObsolete()) {
|
|
|
|
m_document->postProcess();
|
|
|
|
}
|
2018-05-10 09:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::checkSpinner()
|
|
|
|
{
|
|
|
|
if (m_document->isExportReady()) {
|
|
|
|
m_spinnerWidget->stop();
|
|
|
|
m_spinnerWidget->hide();
|
|
|
|
m_saveButton->show();
|
|
|
|
} else {
|
|
|
|
m_spinnerWidget->start();
|
|
|
|
m_spinnerWidget->show();
|
|
|
|
m_saveButton->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPreviewWidget::updateTexturePreview()
|
|
|
|
{
|
|
|
|
if (m_document->textureGuideImage)
|
|
|
|
updateTexturePreviewImage(*m_document->textureGuideImage);
|
|
|
|
m_textureRenderWidget->updateMesh(m_document->takeResultTextureMesh());
|
|
|
|
}
|
|
|
|
|