336 lines
9.1 KiB
C++
336 lines
9.1 KiB
C++
#include "..\Header\MainWindow.h"
|
|
#include "..\Header\OglViewerWidget.h"
|
|
#include <QSurfaceFormat>
|
|
#include <QMessageBox>
|
|
#include <QFileDialog>
|
|
#include <QPalette>
|
|
#include <QAction>
|
|
#include <QSignalMapper>
|
|
#include <QFile>
|
|
#include <QSizePolicy>
|
|
#include <QFont>
|
|
#include <QResizeEvent>
|
|
#include <QToolButton>
|
|
#include "..\Header\FileInterface.h"
|
|
|
|
#define WINDOW_NAME "Mesh Viewer"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindowClass)
|
|
, m_curSeverity(0)
|
|
, m_output(new QLabel(this))
|
|
, m_infoWindow(new FileInfoWindow(this))
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
setWindowTitle(WINDOW_NAME);
|
|
setWindowIcon(QIcon(":/images/icon.ico"));
|
|
|
|
QSurfaceFormat format;
|
|
format.setDepthBufferSize(24);
|
|
QSurfaceFormat::setDefaultFormat(format);
|
|
|
|
setupWidgets();
|
|
|
|
printMessage("MeshViewer by Anakin", 0);
|
|
|
|
m_fileInfo += "Filename: -\nMaterials: -\nVertices: -\nTriangle: -<detail>No file is open";
|
|
|
|
QFile styleSheet(":/files/StyleSheet.txt");
|
|
styleSheet.open(QIODevice::ReadOnly);
|
|
this->setStyleSheet(styleSheet.readAll());
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
delete m_output;
|
|
delete m_infoWindow;
|
|
}
|
|
|
|
void MainWindow::openFile()
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
|
|
if(!fileName.isEmpty())
|
|
emit loadFile(fileName);
|
|
}
|
|
|
|
void MainWindow::setupWidgets()
|
|
{
|
|
OglViewerWidget* viewer = new OglViewerWidget(this);
|
|
setCentralWidget(viewer);
|
|
connect(viewer, &OglViewerWidget::sendMessage, this, &MainWindow::printMessage);
|
|
|
|
QToolButton *openFile = new QToolButton(this);
|
|
openFile->setObjectName("openFile");
|
|
openFile->setToolTip("open file");
|
|
connect(openFile, &QToolButton::pressed, this, &MainWindow::openFile);
|
|
ui->mainToolBar->addWidget(openFile);
|
|
|
|
QToolButton *screenshot = new QToolButton(this);
|
|
screenshot->setObjectName("screenshot");
|
|
screenshot->setToolTip("take screenshot");
|
|
connect(screenshot, &QToolButton::pressed, this, &MainWindow::takeScreenShot);
|
|
ui->mainToolBar->addWidget(screenshot);
|
|
|
|
ui->mainToolBar->addSeparator();
|
|
|
|
QSignalMapper* signalMapper = new QSignalMapper(this);
|
|
|
|
QToolButton *x = new QToolButton(this);
|
|
x->setObjectName("x");
|
|
x->setToolTip("x-direction");
|
|
x->setCheckable(true);
|
|
x->setChecked(true);
|
|
ui->mainToolBar->addWidget(x);
|
|
|
|
QToolButton *y = new QToolButton(this);
|
|
y->setObjectName("y");
|
|
y->setToolTip("y-direction");
|
|
y->setCheckable(true);
|
|
y->setChecked(true);
|
|
ui->mainToolBar->addWidget(y);
|
|
|
|
QToolButton *z = new QToolButton(this);
|
|
z->setObjectName("z");
|
|
z->setToolTip("z-direction");
|
|
z->setCheckable(true);
|
|
z->setChecked(true);
|
|
ui->mainToolBar->addWidget(z);
|
|
|
|
connect(x, SIGNAL(pressed()), signalMapper, SLOT(map()));
|
|
connect(y, SIGNAL(pressed()), signalMapper, SLOT(map()));
|
|
connect(z, SIGNAL(pressed()), signalMapper, SLOT(map()));
|
|
|
|
signalMapper->setMapping(x, 1);
|
|
signalMapper->setMapping(y, 2);
|
|
signalMapper->setMapping(z, 3);
|
|
|
|
connect(signalMapper, SIGNAL(mapped(int)), viewer, SLOT(changeDirection(int)));
|
|
|
|
ui->mainToolBar->addSeparator();
|
|
|
|
QToolButton *wireframe = new QToolButton(this);
|
|
wireframe->setObjectName("wireframe");
|
|
wireframe->setToolTip("wireframe");
|
|
wireframe->setCheckable(true);
|
|
wireframe->setChecked(false);
|
|
connect(wireframe, &QToolButton::pressed, viewer, &OglViewerWidget::toggleWireframe);
|
|
ui->mainToolBar->addWidget(wireframe);
|
|
|
|
QToolButton *light = new QToolButton(this);
|
|
light->setObjectName("light");
|
|
light->setToolTip("toggle light");
|
|
light->setCheckable(true);
|
|
light->setChecked(false);
|
|
connect(light, &QToolButton::pressed, viewer, &OglViewerWidget::toggleLight);
|
|
ui->mainToolBar->addWidget(light);
|
|
|
|
ui->mainToolBar->addSeparator();
|
|
|
|
QToolButton *fileInfo = new QToolButton(this);
|
|
fileInfo->setObjectName("fileInfo");
|
|
fileInfo->setToolTip("file info");
|
|
connect(fileInfo, &QToolButton::pressed, this, &MainWindow::aboutFile);
|
|
ui->mainToolBar->addWidget(fileInfo);
|
|
|
|
QToolButton *help = new QToolButton(this);
|
|
help->setObjectName("help");
|
|
help->setToolTip("help");
|
|
connect(help, &QToolButton::pressed, this, &MainWindow::aboutTool);
|
|
ui->mainToolBar->addWidget(help);
|
|
|
|
m_output->setObjectName("output");
|
|
m_output->setStyleSheet("QLabel#output{color : white; min-width: 400px; min-height: 50px;}");
|
|
m_output->setAlignment(Qt::AlignTop);
|
|
m_output->setText("Name: -\nMaterials: -\nVertice: -\nTriangle: -");
|
|
m_output->raise();
|
|
|
|
}
|
|
|
|
void MainWindow::aboutFile()
|
|
{
|
|
/*QMessageBox* dialog = new QMessageBox(QMessageBox::NoIcon,
|
|
WINDOW_NAME,
|
|
QString(m_fileInfo.left(m_fileInfo.indexOf("<detail>"))),
|
|
QMessageBox::StandardButton::Close,
|
|
this,
|
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
|
|
|
dialog->setStyleSheet("QLabel{min-width: 200px;}");
|
|
dialog->setDetailedText(QString(m_fileInfo.right(m_fileInfo.size() - m_fileInfo.indexOf("<detail>") - 8)));
|
|
dialog->exec();
|
|
delete dialog;*/
|
|
m_infoWindow->show();
|
|
}
|
|
|
|
void MainWindow::aboutTool()
|
|
{
|
|
QFile file(":/files/about.txt");
|
|
file.open(QIODevice::ReadOnly);
|
|
QMessageBox* dialog = new QMessageBox(
|
|
QMessageBox::Question,
|
|
WINDOW_NAME,
|
|
QString(file.readAll()),
|
|
QMessageBox::StandardButton::Close,
|
|
this,
|
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
|
|
|
file.close();
|
|
|
|
dialog->exec();
|
|
|
|
delete dialog;
|
|
}
|
|
|
|
void MainWindow::takeScreenShot()
|
|
{
|
|
QString destination = QFileDialog::getSaveFileName(this, "Save as...", "", "PNG (*.png);; BMP (*.bmp);;TIFF (*.tiff, *.tif);;JPEG (*.jpg *jpeg)");
|
|
|
|
OglViewerWidget* viewer = dynamic_cast<OglViewerWidget*>(centralWidget());
|
|
if (!destination.isEmpty() && viewer != NULL)
|
|
viewer->grab().save(destination);
|
|
}
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent * e)
|
|
{
|
|
m_output->move(40, e->size().height() - 80);
|
|
}
|
|
|
|
void MainWindow::setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle)
|
|
{
|
|
m_fileInfo = QByteArray("Filename: ");
|
|
m_fileInfo += name;
|
|
m_fileInfo += "\nMaterials: ";
|
|
m_fileInfo += QByteArray::number(materials->size());
|
|
m_fileInfo += "\nVertices: ";
|
|
m_fileInfo += QByteArray::number(vertices);
|
|
m_fileInfo += "\nTriangle: ";
|
|
m_fileInfo += QByteArray::number(triangle);
|
|
m_fileInfo += "<detail>";
|
|
|
|
for (auto& it : *materials)
|
|
{
|
|
m_fileInfo += it.name;
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "TX0D:\t\t";
|
|
if (it.tx0d.isEmpty())
|
|
m_fileInfo += "-";
|
|
else
|
|
m_fileInfo += it.tx0d;
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "TX1D:\t\t";
|
|
if (it.tx1d.isEmpty())
|
|
m_fileInfo += "-";
|
|
else
|
|
m_fileInfo += it.tx1d;
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "TX2D:\t\t";
|
|
if (it.tx2d.isEmpty())
|
|
m_fileInfo += "-";
|
|
else
|
|
m_fileInfo += it.tx2d;
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "TX3D:\t\t";
|
|
if (it.tx3d.isEmpty())
|
|
m_fileInfo += "-";
|
|
else
|
|
m_fileInfo += it.tx3d;
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "Flags:\t\t";
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
if (it.flags[i])
|
|
m_fileInfo += "1";
|
|
else
|
|
m_fileInfo += "0";
|
|
}
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "Rendertype:\t";
|
|
m_fileInfo += QByteArray::number(it.rendertype);
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "Gloss:\t";
|
|
m_fileInfo += QByteArray::number(it.shininess);
|
|
m_fileInfo += "\tData0:\t";
|
|
m_fileInfo += QByteArray::number(it.dataValues[0]);
|
|
m_fileInfo += "\tData1:\t";
|
|
m_fileInfo += QByteArray::number(it.dataValues[1]);
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "Diffusecolor:\tR: ";
|
|
m_fileInfo += QByteArray::number(it.diffuseColor.x());
|
|
m_fileInfo += "\tG: ";
|
|
m_fileInfo += QByteArray::number(it.diffuseColor.y());
|
|
m_fileInfo += "\tB: ";
|
|
m_fileInfo += QByteArray::number(it.diffuseColor.z());
|
|
m_fileInfo += "\tA: ";
|
|
m_fileInfo += QByteArray::number(it.diffuseColor.w());
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "Ambientcolor:\tR: ";
|
|
m_fileInfo += QByteArray::number(it.ambientColor.x());
|
|
m_fileInfo += "\tG: ";
|
|
m_fileInfo += QByteArray::number(it.ambientColor.y());
|
|
m_fileInfo += "\tB: ";
|
|
m_fileInfo += QByteArray::number(it.ambientColor.z());
|
|
m_fileInfo += "\tA: ";
|
|
m_fileInfo += QByteArray::number(it.ambientColor.w());
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "Specularcolor:\tR: ";
|
|
m_fileInfo += QByteArray::number(it.specularColor.x());
|
|
m_fileInfo += "\tG: ";
|
|
m_fileInfo += QByteArray::number(it.specularColor.y());
|
|
m_fileInfo += " \tB: ";
|
|
m_fileInfo += QByteArray::number(it.specularColor.z());
|
|
m_fileInfo += " \tA: ";
|
|
m_fileInfo += QByteArray::number(it.specularColor.w());
|
|
m_fileInfo += "\n";
|
|
|
|
m_fileInfo += "-----------------------------------------------------------------\n";
|
|
}
|
|
|
|
m_output->setText(m_fileInfo.left(m_fileInfo.indexOf("<detail>")));
|
|
|
|
m_infoWindow->setBasicText(QString(m_fileInfo.left(m_fileInfo.indexOf("<detail>"))));
|
|
m_infoWindow->setDetailText(QString(m_fileInfo.right(m_fileInfo.size() - m_fileInfo.indexOf("<detail>") - 8)));
|
|
|
|
}
|
|
|
|
void MainWindow::printMessage(QString message, int severity)
|
|
{
|
|
if (!ui->statusBar->currentMessage().isEmpty() && severity < m_curSeverity)
|
|
return;
|
|
|
|
m_curSeverity = severity;
|
|
int time(0);
|
|
QPalette palette;
|
|
|
|
switch (severity)
|
|
{
|
|
case 1:
|
|
time = 3000;
|
|
palette.setColor(QPalette::WindowText, Qt::darkYellow);
|
|
break;
|
|
case 2:
|
|
time = 3000;
|
|
palette.setColor(QPalette::WindowText, Qt::red);
|
|
break;
|
|
case 0:
|
|
default:
|
|
time = 2000;
|
|
palette.setColor(QPalette::WindowText, Qt::black);
|
|
break;
|
|
}
|
|
|
|
ui->statusBar->setPalette(palette);
|
|
ui->statusBar->showMessage(message, time);
|
|
} |