-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
106 lines (78 loc) · 2 KB
/
mainwindow.cpp
File metadata and controls
106 lines (78 loc) · 2 KB
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
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
104
105
106
#include "mainwindow.hpp"
#include "flowmasterwidget.hpp"
#include "serialportdialog.hpp"
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QStatusBar>
#include <QEvent>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setupMenubar();
setupStatusbar();
m_flowmaster = new FlowmasterWidget(this);
setCentralWidget(m_flowmaster);
connect(m_flowmaster,SIGNAL(statusMessage(QString)),
this,SLOT(setStatusMessage(QString)));
}
MainWindow::~MainWindow()
{
}
void MainWindow::setupMenubar()
{
QMenuBar *bar = new QMenuBar(this);
QMenu *file_menu = new QMenu("File");
bar->addMenu(file_menu);
QAction *action = file_menu->addAction("Serial Port");
connect(action,SIGNAL(triggered()),
this, SLOT(setupSerialPort()));
file_menu->addSeparator ();
m_connect = file_menu->addAction("Connect");
connect(m_connect, SIGNAL(triggered()),
this, SLOT(connectSerial()));
m_disconnect = file_menu->addAction("Disconnect");
connect(m_disconnect, SIGNAL(triggered()),
this,SLOT(disconnectSerial()));
file_menu->addSeparator();
action = file_menu->addAction("Exit");
setMenuBar(bar);
}
void MainWindow::setupStatusbar()
{
QStatusBar *statusBar = new QStatusBar;
setStatusBar(statusBar);
}
void MainWindow::setStatusMessage(const QString &message)
{
this->statusBar()->showMessage(message);
}
void MainWindow::setupSerialPort()
{
SerialPortDialog dlg;
int rc = dlg.exec();
if(rc == QDialog::Accepted){
/* need to trigger a reconnection here*/
}
}
void MainWindow::connectSerial()
{
m_flowmaster->startMonitor();
m_connect->setEnabled(false);
m_disconnect->setEnabled(true);
}
void MainWindow::disconnectSerial()
{
m_flowmaster->stopMonitor();
m_connect->setEnabled(true);
m_disconnect->setEnabled(false);
}
void MainWindow::changeEvent(QEvent *event)
{
if(event->type() == QEvent::WindowStateChange){
if(isMinimized()){
hide();
event->ignore();
}
}
}