2016-12-24 15:03:37 +00:00
|
|
|
#include "..\Header\MainWindow.h"
|
|
|
|
#include "..\Header\OglViewerWidget.h"
|
|
|
|
#include <QSurfaceFormat>
|
2016-12-31 15:18:35 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFileDialog>
|
2017-01-04 13:35:27 +00:00
|
|
|
#include <QPalette>
|
2017-01-05 15:04:51 +00:00
|
|
|
#include <QAction>
|
|
|
|
#include <QSignalMapper>
|
2017-01-07 14:59:16 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QSizePolicy>
|
2017-01-05 10:31:36 +00:00
|
|
|
#include "..\Header\FileInterface.h"
|
2016-12-31 15:18:35 +00:00
|
|
|
|
|
|
|
#define WINDOW_NAME "Mesh Viewer"
|
2016-12-24 15:03:37 +00:00
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindowClass)
|
2017-01-04 13:35:27 +00:00
|
|
|
, m_curSeverity(0)
|
2016-12-24 15:03:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2016-12-31 15:18:35 +00:00
|
|
|
setWindowTitle(WINDOW_NAME);
|
|
|
|
setWindowIcon(QIcon(":/images/icon.ico"));
|
|
|
|
|
2016-12-24 15:03:37 +00:00
|
|
|
QSurfaceFormat format;
|
|
|
|
format.setDepthBufferSize(24);
|
|
|
|
QSurfaceFormat::setDefaultFormat(format);
|
|
|
|
|
2017-01-05 15:04:51 +00:00
|
|
|
setupWidgets();
|
2017-01-04 13:35:27 +00:00
|
|
|
|
|
|
|
ui->statusBar->showMessage("MeshViewer by Anakin", 0);
|
2017-01-07 14:59:16 +00:00
|
|
|
|
|
|
|
m_fileInfo += "Filename: -\nMaterials: -\nVertices: -\nTriangle: -\n<detail>No file is open";
|
2016-12-24 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
2016-12-31 15:18:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::openFile()
|
|
|
|
{
|
2017-01-03 13:35:09 +00:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
|
2017-01-07 14:59:16 +00:00
|
|
|
if(!fileName.isEmpty())
|
|
|
|
emit loadFile(fileName);
|
2016-12-31 15:18:35 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 15:04:51 +00:00
|
|
|
void MainWindow::setupWidgets()
|
|
|
|
{
|
|
|
|
OglViewerWidget* viewer = new OglViewerWidget(this);
|
|
|
|
setCentralWidget(viewer);
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
QAction *openFile = new QAction(QIcon(":/images/toolbar/open.png"), "Open file", this);
|
2017-01-05 15:04:51 +00:00
|
|
|
connect(openFile, &QAction::triggered, this, &MainWindow::openFile);
|
|
|
|
ui->mainToolBar->addAction(openFile);
|
|
|
|
|
2017-01-11 15:28:51 +00:00
|
|
|
QAction *screenShot = new QAction(QIcon(":/images/toolbar/screenshot.png"), "Screenshot", this);
|
|
|
|
connect(screenShot, &QAction::triggered, this, &MainWindow::takeScreenShot);
|
|
|
|
ui->mainToolBar->addAction(screenShot);
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
ui->mainToolBar->addSeparator();
|
|
|
|
|
2017-01-05 15:04:51 +00:00
|
|
|
QSignalMapper* signalMapper = new QSignalMapper(this);
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
QAction *x = new QAction(QIcon(":/images/toolbar/X.png"), "X", this);
|
2017-01-05 15:04:51 +00:00
|
|
|
x->setCheckable(true);
|
|
|
|
x->setChecked(true);
|
|
|
|
ui->mainToolBar->addAction(x);
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
QAction *y = new QAction(QIcon(":/images/toolbar/Y.png"), "Y", this);
|
2017-01-05 15:04:51 +00:00
|
|
|
y->setCheckable(true);
|
|
|
|
y->setChecked(true);
|
|
|
|
ui->mainToolBar->addAction(y);
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
QAction *z = new QAction(QIcon(":/images/toolbar/Z.png"), "Z", this);
|
2017-01-05 15:04:51 +00:00
|
|
|
z->setCheckable(true);
|
|
|
|
z->setChecked(true);
|
|
|
|
ui->mainToolBar->addAction(z);
|
|
|
|
|
|
|
|
connect(x, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
|
|
|
connect(y, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
|
|
|
connect(z, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
|
|
|
|
|
|
|
signalMapper->setMapping(x, 1);
|
|
|
|
signalMapper->setMapping(y, 2);
|
|
|
|
signalMapper->setMapping(z, 3);
|
|
|
|
|
|
|
|
connect(signalMapper, SIGNAL(mapped(int)), viewer, SLOT(changeDirection(int)));
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
ui->mainToolBar->addSeparator();
|
2017-01-05 15:04:51 +00:00
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
QAction *fileInfo = new QAction(QIcon(":/images/toolbar/info.png"), "File info", this);
|
2017-01-05 15:04:51 +00:00
|
|
|
connect(fileInfo, &QAction::triggered, this, &MainWindow::aboutFile);
|
|
|
|
ui->mainToolBar->addAction(fileInfo);
|
|
|
|
|
2017-01-09 15:34:54 +00:00
|
|
|
QAction *help = new QAction(QIcon(":/images/toolbar/about.png"), "Help", this);
|
2017-01-05 15:04:51 +00:00
|
|
|
connect(help, &QAction::triggered, this, &MainWindow::aboutTool);
|
|
|
|
ui->mainToolBar->addAction(help);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:18:35 +00:00
|
|
|
void MainWindow::aboutFile()
|
|
|
|
{
|
2017-01-07 14:59:16 +00:00
|
|
|
QMessageBox* dialog = new QMessageBox(QMessageBox::NoIcon,
|
2016-12-31 15:18:35 +00:00
|
|
|
WINDOW_NAME,
|
2017-01-07 14:59:16 +00:00
|
|
|
QString(m_fileInfo.left(m_fileInfo.indexOf("<detail>"))),
|
2016-12-31 15:18:35 +00:00
|
|
|
QMessageBox::StandardButton::Close,
|
|
|
|
this,
|
|
|
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
2017-01-07 14:59:16 +00:00
|
|
|
|
|
|
|
dialog->setStyleSheet("QLabel{min-width: 200px;}");
|
|
|
|
dialog->setDetailedText(QString(m_fileInfo.right(m_fileInfo.size() - m_fileInfo.indexOf("<detail>") - 8)));
|
2016-12-31 15:18:35 +00:00
|
|
|
dialog->exec();
|
2017-01-07 14:59:16 +00:00
|
|
|
delete dialog;
|
2016-12-31 15:18:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::aboutTool()
|
|
|
|
{
|
2017-01-04 13:35:27 +00:00
|
|
|
QFile file(":/files/about.txt");
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
QMessageBox* dialog = new QMessageBox(
|
|
|
|
QMessageBox::Question,
|
2016-12-31 15:18:35 +00:00
|
|
|
WINDOW_NAME,
|
2017-01-04 13:35:27 +00:00
|
|
|
QString(file.readAll()),
|
2016-12-31 15:18:35 +00:00
|
|
|
QMessageBox::StandardButton::Close,
|
|
|
|
this,
|
2017-01-07 14:59:16 +00:00
|
|
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
2017-01-04 13:35:27 +00:00
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
2016-12-31 15:18:35 +00:00
|
|
|
dialog->exec();
|
2017-01-07 14:59:16 +00:00
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2017-01-11 15:28:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-01-15 11:26:15 +00:00
|
|
|
void MainWindow::setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle)
|
2017-01-07 14:59:16 +00:00
|
|
|
{
|
|
|
|
m_fileInfo = QByteArray("Filename: ");
|
|
|
|
m_fileInfo += name;
|
|
|
|
m_fileInfo += "\nMaterials: ";
|
2017-01-15 11:26:15 +00:00
|
|
|
m_fileInfo += QByteArray::number(materials->size());
|
2017-01-07 14:59:16 +00:00
|
|
|
m_fileInfo += "\nVertices: ";
|
|
|
|
m_fileInfo += QByteArray::number(vertices);
|
|
|
|
m_fileInfo += "\nTriangle: ";
|
|
|
|
m_fileInfo += QByteArray::number(triangle);
|
|
|
|
m_fileInfo += "<detail>";
|
|
|
|
|
|
|
|
int count(0);
|
2017-01-15 11:26:15 +00:00
|
|
|
//TODO: mark not opened textures
|
|
|
|
for (auto& it : *materials)
|
2017-01-07 14:59:16 +00:00
|
|
|
{
|
|
|
|
m_fileInfo += "Material ";
|
|
|
|
m_fileInfo += QByteArray::number(count++);
|
|
|
|
m_fileInfo += " - ";
|
2017-01-15 11:26:15 +00:00
|
|
|
m_fileInfo += it.name;
|
2017-01-07 14:59:16 +00:00
|
|
|
m_fileInfo += "\n";
|
|
|
|
}
|
2017-01-04 13:35:27 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 13:46:01 +00:00
|
|
|
void MainWindow::printMessage(QString message, int severity)
|
2017-01-04 13:35:27 +00:00
|
|
|
{
|
2017-01-05 15:18:01 +00:00
|
|
|
if (!ui->statusBar->currentMessage().isEmpty() && severity < m_curSeverity)
|
2017-01-04 13:35:27 +00:00
|
|
|
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);
|
2016-12-24 15:03:37 +00:00
|
|
|
}
|