SWBF2-Classic-Msh-Viewer/QtMeshViewer/Source/MainWindow.cpp

105 lines
2.4 KiB
C++

#include "..\Header\MainWindow.h"
#include "..\Header\OglViewerWidget.h"
#include <QSurfaceFormat>
#include <QMessageBox>
#include <QFileDialog>
#include <QFile>
#include <QPalette>
#include "..\Header\FileInterface.h"
#define WINDOW_NAME "Mesh Viewer"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindowClass)
, m_curSeverity(0)
{
ui->setupUi(this);
setWindowTitle(WINDOW_NAME);
setWindowIcon(QIcon(":/images/icon.ico"));
ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile);
ui->mainToolBar->addAction("File Info", this, &MainWindow::aboutFile);
ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool);
QSurfaceFormat format;
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
setCentralWidget(new OglViewerWidget(this));
ui->statusBar->showMessage("MeshViewer by Anakin", 0);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openFile()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
emit loadFile(fileName.toStdString().c_str());
}
void MainWindow::aboutFile()
{
QMessageBox* dialog = new QMessageBox(QMessageBox::Information,
WINDOW_NAME,
"When i find some time, i'll add some information about\nthe file in the detailed text",
QMessageBox::StandardButton::Close,
this,
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
dialog->setDetailedText("This is the cool detailed text\n");
dialog->exec();
}
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
);
//dialog->setDetailedText(QString(file.readAll()));
file.close();
dialog->exec();
}
void MainWindow::showMessage(QString message, int severity)
{
if (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);
}