-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
74 lines (59 loc) · 1.6 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLayout>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
DbWindow *MainWindow::createDbWindow()
{
DbWindow *child = new DbWindow;
QMdiSubWindow *subWindow = ui->m_maMain->addSubWindow(child);
subWindow->setWindowState(Qt::WindowMaximized);
return child;
}
QMdiSubWindow *MainWindow::findDbWindow(const QString &fileName)
{
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
foreach (QMdiSubWindow *window, ui->m_maMain->subWindowList()) {
DbWindow *child = qobject_cast<DbWindow *>(window->widget());
if (child->currentFile() == canonicalFilePath)
return window;
}
return 0;
}
void MainWindow::openDbFile()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open"), QString(), tr("DBC Database (*.dbc);;All Files (*.*)"));
if (fileName.isEmpty())
return;
QMdiSubWindow *existing = findDbWindow(fileName);
if (existing)
{
ui->m_maMain->setActiveSubWindow(existing);
return;
}
DbWindow *child = createDbWindow();
connect(child, &DbWindow::statusEvent, this, &setStatusBarText);
if (child->loadFile(fileName)) {
statusBar()->showMessage(tr("File Loaded"), 2000);
child->show();
} else {
child->close();
}
}
void MainWindow::on_m_actOpen_triggered()
{
openDbFile();
}
void MainWindow::setStatusBarText(const QString& msg)
{
statusBar()->showMessage(msg);
}