MainWindow.cpp 2.32 KB
Newer Older
1 2 3
#include "..\Header\MainWindow.h"
#include "..\Header\OglViewerWidget.h"
#include <QSurfaceFormat>
Anakin's avatar
Anakin committed
4 5
#include <QMessageBox>
#include <QFileDialog>
6 7
#include <QFile>
#include <QPalette>
Anakin's avatar
Anakin committed
8 9

#define WINDOW_NAME "Mesh Viewer"
10 11 12 13

MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
	, ui(new Ui::MainWindowClass)
14
	, m_curSeverity(0)
15 16 17
{
	ui->setupUi(this);

Anakin's avatar
Anakin committed
18 19 20 21
	setWindowTitle(WINDOW_NAME);
	setWindowIcon(QIcon(":/images/icon.ico"));

	ui->mainToolBar->addAction("Open File", this, &MainWindow::openFile);
22
	ui->mainToolBar->addAction("File Info", this, &MainWindow::aboutFile);
Anakin's avatar
Anakin committed
23 24
	ui->mainToolBar->addAction("Help", this, &MainWindow::aboutTool);

25 26 27 28
	QSurfaceFormat format;
	format.setDepthBufferSize(24);
	QSurfaceFormat::setDefaultFormat(format);

Anakin's avatar
Anakin committed
29
	setCentralWidget(new OglViewerWidget(this));
30 31

	ui->statusBar->showMessage("MeshViewer by Anakin", 0);
32 33 34 35 36
}

MainWindow::~MainWindow()
{
	delete ui;
Anakin's avatar
Anakin committed
37 38 39 40
}

void MainWindow::openFile()
{
Anakin's avatar
Anakin committed
41
	QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
Anakin's avatar
Anakin committed
42
	emit loadFile(fileName.toStdString().c_str());
Anakin's avatar
Anakin committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
}

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()
{
59 60 61 62
	QFile file(":/files/about.txt");
	file.open(QIODevice::ReadOnly);
	QMessageBox* dialog = new QMessageBox(
		QMessageBox::Question,
Anakin's avatar
Anakin committed
63
		WINDOW_NAME,
64
		QString(file.readAll()),
Anakin's avatar
Anakin committed
65 66
		QMessageBox::StandardButton::Close,
		this,
67 68 69 70 71 72
		Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint
		);

	//dialog->setDetailedText(QString(file.readAll()));
	file.close();

Anakin's avatar
Anakin committed
73
	dialog->exec();
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
}

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);
104
}