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-10-25 00:19:38 +00:00
|
|
|
#include "util.h"
|
2018-05-10 09:16:22 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
ExportPreviewWidget::ExportPreviewWidget(Document *document, QWidget *parent) :
|
2018-09-21 07:10:18 +00:00
|
|
|
QDialog(parent),
|
2018-05-10 09:16:22 +00:00
|
|
|
m_document(document),
|
2018-11-15 22:56:24 +00:00
|
|
|
m_colorPreviewLabel(nullptr),
|
2018-05-10 09:16:22 +00:00
|
|
|
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
|
|
|
|
2018-11-15 22:56:24 +00:00
|
|
|
m_colorPreviewLabel = new QLabel;
|
|
|
|
m_colorPreviewLabel->setMinimumSize(128, 128);
|
|
|
|
m_colorPreviewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
m_normalPreviewLabel = new QLabel;
|
|
|
|
m_normalPreviewLabel->setMinimumSize(64, 64);
|
|
|
|
m_normalPreviewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
m_metalnessRoughnessAmbientOcclusionPreviewLabel = new QLabel;
|
|
|
|
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setMinimumSize(64, 64);
|
|
|
|
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
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
|
|
|
QComboBox *exportFormatSelectBox = new QComboBox;
|
2018-10-25 09:18:04 +00:00
|
|
|
exportFormatSelectBox->addItem(tr(".glb"));
|
|
|
|
exportFormatSelectBox->addItem(tr(".fbx"));
|
2018-09-14 09:45:05 +00:00
|
|
|
exportFormatSelectBox->setCurrentIndex(0);
|
|
|
|
|
2018-10-20 05:07:11 +00:00
|
|
|
m_saveButton = new QPushButton(tr("Save"));
|
|
|
|
connect(m_saveButton, &QPushButton::clicked, this, [=]() {
|
|
|
|
auto currentIndex = exportFormatSelectBox->currentIndex();
|
|
|
|
if (0 == currentIndex) {
|
2018-10-25 09:18:04 +00:00
|
|
|
emit saveAsGlb();
|
2018-10-20 05:07:11 +00:00
|
|
|
} else if (1 == currentIndex) {
|
|
|
|
emit saveAsFbx();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
m_saveButton->hide();
|
|
|
|
m_saveButton->setDefault(true);
|
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
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);
|
2018-11-15 22:56:24 +00:00
|
|
|
containerLayout->addWidget(m_colorPreviewLabel, 0, 0);
|
2018-11-16 05:55:52 +00:00
|
|
|
containerLayout->addWidget(m_normalPreviewLabel, 0, 1);
|
|
|
|
containerLayout->addWidget(m_metalnessRoughnessAmbientOcclusionPreviewLabel, 0, 2);
|
|
|
|
//containerLayout->setRowStretch(0, 1);
|
|
|
|
//containerLayout->setColumnStretch(0, 1);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
2018-11-17 09:10:08 +00:00
|
|
|
//m_textureRenderWidget = new ModelWidget;
|
|
|
|
//m_textureRenderWidget->setMinimumSize(128, 128);
|
2018-11-16 05:55:52 +00:00
|
|
|
//m_textureRenderWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
2018-11-17 09:10:08 +00:00
|
|
|
//QVBoxLayout *renderLayout = new QVBoxLayout;
|
|
|
|
//renderLayout->setSpacing(0);
|
|
|
|
//renderLayout->setContentsMargins(20, 0, 20, 0);
|
|
|
|
//renderLayout->addWidget(m_textureRenderWidget);
|
2018-05-10 09:16:22 +00:00
|
|
|
|
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);
|
2018-11-17 09:10:08 +00:00
|
|
|
//topLayout->addLayout(renderLayout);
|
2018-09-14 09:45:05 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-11-15 22:56:24 +00:00
|
|
|
m_spinnerWidget = new WaitingSpinnerWidget(m_colorPreviewLabel);
|
2018-05-10 09:16:22 +00:00
|
|
|
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::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(event);
|
2018-11-15 22:56:24 +00:00
|
|
|
resizePreviewImages();
|
2018-05-10 09:16:22 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 22:56:24 +00:00
|
|
|
void ExportPreviewWidget::resizePreviewImages()
|
2018-05-10 09:16:22 +00:00
|
|
|
{
|
2018-11-16 05:55:52 +00:00
|
|
|
if (m_colorImage.isNull()) {
|
|
|
|
m_colorPreviewLabel->hide();
|
|
|
|
} else {
|
2018-11-15 22:56:24 +00:00
|
|
|
QPixmap pixmap = QPixmap::fromImage(m_colorImage);
|
|
|
|
m_colorPreviewLabel->setPixmap(pixmap.scaled(m_colorPreviewLabel->width(), m_colorPreviewLabel->height(), Qt::KeepAspectRatio));
|
2018-11-16 05:55:52 +00:00
|
|
|
m_colorPreviewLabel->show();
|
2018-11-15 22:56:24 +00:00
|
|
|
}
|
2018-11-16 05:55:52 +00:00
|
|
|
|
|
|
|
if (m_normalImage.isNull()) {
|
|
|
|
m_normalPreviewLabel->hide();
|
|
|
|
} else {
|
2018-11-15 22:56:24 +00:00
|
|
|
QPixmap pixmap = QPixmap::fromImage(m_normalImage);
|
|
|
|
m_normalPreviewLabel->setPixmap(pixmap.scaled(m_normalPreviewLabel->width(), m_normalPreviewLabel->height(), Qt::KeepAspectRatio));
|
2018-11-16 05:55:52 +00:00
|
|
|
m_normalPreviewLabel->show();
|
2018-11-15 22:56:24 +00:00
|
|
|
}
|
2018-11-16 05:55:52 +00:00
|
|
|
|
|
|
|
if (m_metalnessRoughnessAmbientOcclusionImage.isNull()) {
|
|
|
|
m_metalnessRoughnessAmbientOcclusionPreviewLabel->hide();
|
|
|
|
} else {
|
2018-11-15 22:56:24 +00:00
|
|
|
QPixmap pixmap = QPixmap::fromImage(m_metalnessRoughnessAmbientOcclusionImage);
|
|
|
|
m_metalnessRoughnessAmbientOcclusionPreviewLabel->setPixmap(pixmap.scaled(m_metalnessRoughnessAmbientOcclusionPreviewLabel->width(), m_metalnessRoughnessAmbientOcclusionPreviewLabel->height(), Qt::KeepAspectRatio));
|
2018-11-16 05:55:52 +00:00
|
|
|
m_metalnessRoughnessAmbientOcclusionPreviewLabel->show();
|
2018-11-15 22:56:24 +00:00
|
|
|
}
|
2018-05-10 09:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-11-15 22:56:24 +00:00
|
|
|
m_colorImage = *m_document->textureGuideImage;
|
2018-11-16 05:55:52 +00:00
|
|
|
else
|
|
|
|
m_colorImage = QImage();
|
2018-11-15 22:56:24 +00:00
|
|
|
if (m_document->textureNormalImage)
|
|
|
|
m_normalImage = *m_document->textureNormalImage;
|
2018-11-16 05:55:52 +00:00
|
|
|
else
|
|
|
|
m_normalImage = QImage();
|
2018-11-15 22:56:24 +00:00
|
|
|
if (m_document->textureMetalnessRoughnessAmbientOcclusionImage)
|
|
|
|
m_metalnessRoughnessAmbientOcclusionImage = *m_document->textureMetalnessRoughnessAmbientOcclusionImage;
|
2018-11-16 05:55:52 +00:00
|
|
|
else
|
|
|
|
m_metalnessRoughnessAmbientOcclusionImage = QImage();
|
2018-11-17 09:10:08 +00:00
|
|
|
//m_textureRenderWidget->updateMesh(m_document->takeResultTextureMesh());
|
2018-11-15 22:56:24 +00:00
|
|
|
resizePreviewImages();
|
|
|
|
checkSpinner();
|
2018-05-10 09:16:22 +00:00
|
|
|
}
|
|
|
|
|