MainWindow.cpp 3.51 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
#include <QAction>
#include <QSignalMapper>
Anakin's avatar
Anakin committed
10
#include "..\Header\FileInterface.h"
Anakin's avatar
Anakin committed
11
12

#define WINDOW_NAME "Mesh Viewer"
13
14
15
16

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

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

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

Anakin's avatar
Anakin committed
28
	setupWidgets();
29
30

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

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

void MainWindow::openFile()
{
Anakin's avatar
Anakin committed
40
	QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Mesh (*.msh)");
Anakin's avatar
Anakin committed
41
	emit loadFile(fileName.toStdString().c_str());
Anakin's avatar
Anakin committed
42
43
}

Anakin's avatar
Anakin committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
void MainWindow::setupWidgets()
{
	OglViewerWidget* viewer = new OglViewerWidget(this);
	setCentralWidget(viewer);

	QAction *openFile = new QAction("Open file", this);
	connect(openFile, &QAction::triggered, this, &MainWindow::openFile);
	ui->mainToolBar->addAction(openFile);

	QSignalMapper* signalMapper = new QSignalMapper(this);

	QAction *x = new QAction("X", this);
	x->setCheckable(true);
	x->setChecked(true);
	ui->mainToolBar->addAction(x);

	QAction *y = new QAction("Y", this);
	y->setCheckable(true);
	y->setChecked(true);
	ui->mainToolBar->addAction(y);

	QAction *z = new QAction("Z", this);
	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)));


	QAction *fileInfo = new QAction("File info", this);
	connect(fileInfo, &QAction::triggered, this, &MainWindow::aboutFile);
	ui->mainToolBar->addAction(fileInfo);

	QAction *help = new QAction("Help", this);
	connect(help, &QAction::triggered, this, &MainWindow::aboutTool);
	ui->mainToolBar->addAction(help);

	
}

Anakin's avatar
Anakin committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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()
{
106
107
108
109
	QFile file(":/files/about.txt");
	file.open(QIODevice::ReadOnly);
	QMessageBox* dialog = new QMessageBox(
		QMessageBox::Question,
Anakin's avatar
Anakin committed
110
		WINDOW_NAME,
111
		QString(file.readAll()),
Anakin's avatar
Anakin committed
112
113
		QMessageBox::StandardButton::Close,
		this,
114
115
116
117
118
119
		Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint
		);

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

Anakin's avatar
Anakin committed
120
	dialog->exec();
121
122
}

Anakin's avatar
Anakin committed
123
void MainWindow::printMessage(QString message, int severity)
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
	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);
151
}