MainWindow.cpp 2.36 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
#include "..\Header\FileInterface.h"
Anakin's avatar
Anakin committed
9
10

#define WINDOW_NAME "Mesh Viewer"
11
12
13
14

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

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

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

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

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

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

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

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

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

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

Anakin's avatar
Anakin committed
74
	dialog->exec();
75
76
}

Anakin's avatar
Anakin committed
77
void MainWindow::printMessage(QString message, int severity)
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
104
{
	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);
105
}