2018-03-11 03:18:24 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QToolBar>
|
2018-03-11 16:02:15 +00:00
|
|
|
#include <QThread>
|
2018-03-13 06:39:36 +00:00
|
|
|
#include <QFileDialog>
|
2018-03-14 02:55:59 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2018-03-14 15:22:00 +00:00
|
|
|
#include <QStackedWidget>
|
2018-03-15 15:40:30 +00:00
|
|
|
#include <QXmlStreamReader>
|
|
|
|
#include <QBuffer>
|
2018-03-19 07:58:51 +00:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QComboBox>
|
2018-03-11 16:02:15 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include "mainwindow.h"
|
2018-03-14 06:43:16 +00:00
|
|
|
#include "skeletonwidget.h"
|
|
|
|
#include "theme.h"
|
2018-03-15 15:40:30 +00:00
|
|
|
#include "ds3file.h"
|
2018-03-10 06:57:14 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
MainWindow::MainWindow()
|
2018-03-10 06:57:14 +00:00
|
|
|
{
|
2018-03-15 15:40:30 +00:00
|
|
|
m_modelPageButton = new QPushButton("Model");
|
|
|
|
m_sharePageButton = new QPushButton("Share");
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
QWidget *hrWidget = new QWidget;
|
|
|
|
hrWidget->setFixedHeight(2);
|
|
|
|
hrWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
hrWidget->setStyleSheet(QString("background-color: #fc6621;"));
|
|
|
|
hrWidget->setContentsMargins(0, 0, 0, 0);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
QButtonGroup *pageButtonGroup = new QButtonGroup;
|
2018-03-15 15:40:30 +00:00
|
|
|
pageButtonGroup->addButton(m_modelPageButton);
|
|
|
|
pageButtonGroup->addButton(m_sharePageButton);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
m_modelPageButton->setCheckable(true);
|
|
|
|
m_sharePageButton->setCheckable(true);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
pageButtonGroup->setExclusive(true);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
m_modelPageButton->setChecked(true);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
QHBoxLayout *topButtonsLayout = new QHBoxLayout;
|
|
|
|
topButtonsLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
topButtonsLayout->setSpacing(0);
|
|
|
|
topButtonsLayout->addStretch();
|
2018-03-15 15:40:30 +00:00
|
|
|
topButtonsLayout->addWidget(m_modelPageButton);
|
|
|
|
topButtonsLayout->addWidget(m_sharePageButton);
|
2018-03-14 06:43:16 +00:00
|
|
|
topButtonsLayout->addStretch();
|
2018-03-11 03:18:24 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
QVBoxLayout *topLayout = new QVBoxLayout;
|
|
|
|
topLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
topLayout->setSpacing(0);
|
|
|
|
topLayout->addLayout(topButtonsLayout);
|
|
|
|
topLayout->addWidget(hrWidget);
|
2018-03-11 16:02:15 +00:00
|
|
|
|
2018-03-19 07:58:51 +00:00
|
|
|
m_edgePropertyWidget = new QWidget;
|
|
|
|
QFormLayout *formLayout = new QFormLayout;
|
|
|
|
QComboBox *edgeTypeBox = new QComboBox;
|
|
|
|
edgeTypeBox->addItem("Spine", "Spine");
|
|
|
|
edgeTypeBox->addItem("Attach", "Attach");
|
|
|
|
formLayout->addRow(tr("Edge Type:"), edgeTypeBox);
|
|
|
|
m_edgePropertyWidget->setLayout(formLayout);
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QVBoxLayout *modelRightLayout = new QVBoxLayout;
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-20 03:31:05 +00:00
|
|
|
modelRightLayout->addSpacing(10);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
|
|
|
QPushButton *changeTurnaroundButton = new QPushButton(" Change Turnaround ");
|
2018-03-15 15:40:30 +00:00
|
|
|
modelRightLayout->addWidget(changeTurnaroundButton);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QPushButton *exportPartsModelButton = new QPushButton(" Export ");
|
|
|
|
modelRightLayout->addWidget(exportPartsModelButton);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QPushButton *newModelButton = new QPushButton(" New ");
|
|
|
|
modelRightLayout->addWidget(newModelButton);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QPushButton *loadModelButton = new QPushButton(" Load ");
|
|
|
|
modelRightLayout->addWidget(loadModelButton);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QPushButton *saveModelButton = new QPushButton(" Save ");
|
|
|
|
modelRightLayout->addWidget(saveModelButton);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QPushButton *saveModelAsButton = new QPushButton(" Save as ");
|
|
|
|
modelRightLayout->addWidget(saveModelAsButton);
|
|
|
|
saveModelAsButton->hide();
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-19 07:58:51 +00:00
|
|
|
modelRightLayout->addSpacing(20);
|
|
|
|
|
|
|
|
modelRightLayout->addWidget(m_edgePropertyWidget);
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
modelRightLayout->addStretch();
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
SkeletonWidget *skeletonWidget = new SkeletonWidget(this);
|
2018-03-14 15:22:00 +00:00
|
|
|
m_skeletonWidget = skeletonWidget;
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QHBoxLayout *modelPageLayout = new QHBoxLayout;
|
|
|
|
modelPageLayout->addWidget(skeletonWidget);
|
|
|
|
modelPageLayout->addLayout(modelRightLayout);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QWidget *modelPageWidget = new QWidget;
|
|
|
|
modelPageWidget->setLayout(modelPageLayout);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
QWidget *sharePageWidget = new QWidget;
|
2018-03-14 15:22:00 +00:00
|
|
|
|
|
|
|
QStackedWidget *stackedWidget = new QStackedWidget;
|
2018-03-15 15:40:30 +00:00
|
|
|
stackedWidget->addWidget(modelPageWidget);
|
|
|
|
stackedWidget->addWidget(sharePageWidget);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
|
|
|
m_stackedWidget = stackedWidget;
|
2018-03-11 03:18:24 +00:00
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->addLayout(topLayout);
|
2018-03-14 15:22:00 +00:00
|
|
|
mainLayout->addWidget(stackedWidget);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
|
|
|
QWidget *centralWidget = new QWidget;
|
|
|
|
centralWidget->setLayout(mainLayout);
|
|
|
|
|
|
|
|
setCentralWidget(centralWidget);
|
|
|
|
setWindowTitle(tr("Dust 3D"));
|
2018-03-11 16:02:15 +00:00
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
bool connectResult = false;
|
2018-03-11 16:02:15 +00:00
|
|
|
|
2018-03-14 15:22:00 +00:00
|
|
|
connectResult = connect(changeTurnaroundButton, SIGNAL(clicked()), skeletonWidget, SLOT(changeTurnaround()));
|
|
|
|
assert(connectResult);
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
connectResult = connect(m_modelPageButton, SIGNAL(clicked()), this, SLOT(updatePageButtons()));
|
2018-03-11 16:02:15 +00:00
|
|
|
assert(connectResult);
|
2018-03-14 15:22:00 +00:00
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
connectResult = connect(m_sharePageButton, SIGNAL(clicked()), this, SLOT(updatePageButtons()));
|
2018-03-14 15:22:00 +00:00
|
|
|
assert(connectResult);
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
connectResult = connect(saveModelButton, SIGNAL(clicked()), this, SLOT(saveModel()));
|
2018-03-14 15:22:00 +00:00
|
|
|
assert(connectResult);
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
connectResult = connect(loadModelButton, SIGNAL(clicked()), this, SLOT(loadModel()));
|
2018-03-14 15:22:00 +00:00
|
|
|
assert(connectResult);
|
|
|
|
|
|
|
|
updatePageButtons();
|
|
|
|
}
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
void MainWindow::loadModel()
|
2018-03-14 15:22:00 +00:00
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getOpenFileName(this,
|
2018-03-15 15:40:30 +00:00
|
|
|
tr("Load Model"), ".",
|
|
|
|
tr("Dust 3D Project (*.ds3)"));
|
2018-03-14 15:22:00 +00:00
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
2018-03-15 15:40:30 +00:00
|
|
|
Ds3FileReader ds3Reader(filename);
|
|
|
|
for (int i = 0; i < ds3Reader.items().size(); ++i) {
|
|
|
|
Ds3ReaderItem item = ds3Reader.items().at(i);
|
|
|
|
if (item.type == "model") {
|
|
|
|
QByteArray data;
|
|
|
|
ds3Reader.loadItem(item.name, &data);
|
|
|
|
QXmlStreamReader xmlReader(data);
|
|
|
|
m_skeletonWidget->graphicsView()->loadFromXmlStream(xmlReader);
|
|
|
|
} else if (item.type == "asset") {
|
|
|
|
if (item.name == "canvas.png") {
|
|
|
|
QByteArray data;
|
|
|
|
ds3Reader.loadItem(item.name, &data);
|
|
|
|
QImage image = QImage::fromData(data, "PNG");
|
|
|
|
m_skeletonWidget->graphicsView()->updateBackgroundImage(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 08:46:53 +00:00
|
|
|
m_skeletonWidget->graphicsView()->turnOffAddNodeMode();
|
2018-03-14 15:22:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 15:40:30 +00:00
|
|
|
void MainWindow::saveModel()
|
2018-03-14 15:22:00 +00:00
|
|
|
{
|
2018-03-15 15:40:30 +00:00
|
|
|
if (m_saveModelAs.isEmpty()) {
|
|
|
|
m_saveModelAs = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Save Model"), ".",
|
|
|
|
tr("Dust 3D Project (*.ds3)"));
|
|
|
|
if (m_saveModelAs.isEmpty()) {
|
2018-03-14 15:22:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 15:40:30 +00:00
|
|
|
|
|
|
|
Ds3FileWriter ds3Writer;
|
|
|
|
|
|
|
|
QByteArray modelXml;
|
|
|
|
QXmlStreamWriter stream(&modelXml);
|
|
|
|
m_skeletonWidget->graphicsView()->saveToXmlStream(&stream);
|
|
|
|
if (modelXml.size() > 0)
|
|
|
|
ds3Writer.add("model1.xml", "model", &modelXml);
|
|
|
|
|
|
|
|
QByteArray imageByteArray;
|
|
|
|
QBuffer pngBuffer(&imageByteArray);
|
|
|
|
pngBuffer.open(QIODevice::WriteOnly);
|
|
|
|
m_skeletonWidget->graphicsView()->backgroundImage().save(&pngBuffer, "PNG");
|
|
|
|
if (imageByteArray.size() > 0)
|
|
|
|
ds3Writer.add("canvas.png", "asset", &imageByteArray);
|
|
|
|
|
|
|
|
ds3Writer.save(m_saveModelAs);
|
2018-03-10 06:57:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 06:43:16 +00:00
|
|
|
void MainWindow::updatePageButtons()
|
2018-03-11 16:02:15 +00:00
|
|
|
{
|
2018-03-15 15:40:30 +00:00
|
|
|
if (m_modelPageButton->isChecked()) {
|
2018-03-14 15:22:00 +00:00
|
|
|
m_stackedWidget->setCurrentIndex(0);
|
|
|
|
}
|
2018-03-15 15:40:30 +00:00
|
|
|
if (m_sharePageButton->isChecked()) {
|
2018-03-14 15:22:00 +00:00
|
|
|
m_stackedWidget->setCurrentIndex(1);
|
|
|
|
}
|
2018-03-15 15:40:30 +00:00
|
|
|
m_modelPageButton->setStyleSheet(m_modelPageButton->isChecked() ? Theme::tabButtonSelectedStylesheet : Theme::tabButtonStylesheet);
|
|
|
|
m_sharePageButton->setStyleSheet(m_sharePageButton->isChecked() ? Theme::tabButtonSelectedStylesheet : Theme::tabButtonStylesheet);
|
2018-03-11 16:02:15 +00:00
|
|
|
}
|
|
|
|
|