-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
133 lines (117 loc) · 4.59 KB
/
widget.cpp
File metadata and controls
133 lines (117 loc) · 4.59 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//font setting
QFont font("Arial");
font.setPointSize(10);
font.setBold(true);
//GUI setting
//call widget variables
connectButton = new QPushButton("Set");
dangerInput = new QLineEdit();
cautionInput = new QLineEdit();
for(int i = 0; i<2; i++) slopeInput[i] = new QLineEdit();
portBox = new QComboBox();
dangerLabel = new QLabel();
cautionLabel = new QLabel();
for(int i = 0; i<2; i++) slopeLabel[i] = new QLabel();
portLabel = new QLabel("Port Name");
QLabel* vLabel = new QLabel("(V)");
QLabel* vLabel2 = new QLabel("(V)");
QHBoxLayout* slopeLayout[2];
//call layout variables
connectWidgetMainLayout = new QVBoxLayout();
dangerLayout = new QHBoxLayout();
cautionLayout = new QHBoxLayout();
portLayout = new QHBoxLayout();
for(int i = 0; i<2; i++) slopeLayout[i] = new QHBoxLayout();
//set widget propertie
dangerLabel->setText("<font color=\"black\">Threshold of<\font> <font color = \"red\"> Danger <\font>");
cautionLabel->setText("<font color=\"black\">Threshold of<\font> <font color = \"#FF7F00\"> Caution <\font>");
slopeLabel[0]->setText("<font color=\"black\">Slope <\font> <font color = \"red\"> (Danger) <\font>");
slopeLabel[1]->setText("<font color=\"black\">Slope <\font> <font color = \"#FF7F00\"> (Caution) <\font>");
portBox->addItems(QStringList() << "COM1" << "COM2" << "COM3" << "COM4" << "COM5" << "COM6" << "COM7" << "COM8" << "COM9");
dangerLabel->setFont(font);
cautionLabel->setFont(font);
for(int i = 0; i<2; i++) slopeLabel[i]->setFont(font);
font.setBold(false);
vLabel->setFont(font);
vLabel2->setFont(font);
portBox->setFont(font);
font.setBold(true);
portLabel->setFont(font);
font.setBold(false);
connectButton->setFont(font);
dangerInput->setMaximumWidth(40);
cautionInput->setMaximumWidth(40);
for(int i = 0; i<2; i++) slopeInput[i]->setMaximumWidth(40);
portBox->setMaximumWidth(65);
dangerInput->setAlignment(Qt::AlignCenter);
cautionInput->setAlignment(Qt::AlignCenter);
for(int i =0; i<2; i++)slopeInput[i]->setAlignment(Qt::AlignCenter);
//layout push
dangerLayout->addWidget(dangerLabel);
dangerLayout->addSpacing(20);
dangerLayout->addWidget(dangerInput);
dangerLayout->addWidget(vLabel);
cautionLayout->addWidget(cautionLabel);
cautionLayout->addSpacing(17);
cautionLayout->addWidget(cautionInput);
cautionLayout->addWidget(vLabel2);
for(int i = 0; i<2; i++){
slopeLayout[i]->addWidget(slopeLabel[i]);
slopeLayout[i]->addSpacing(23);
slopeLayout[i]->addWidget(slopeInput[i]);
slopeLayout[i]->addSpacing(27);
}
portLayout->addWidget(portLabel);
portLayout->addWidget(portBox);
connectWidgetMainLayout->setSpacing(10);
connectWidgetMainLayout->addLayout(dangerLayout);
connectWidgetMainLayout->addLayout(cautionLayout);
for(int i = 0; i<2; i++) connectWidgetMainLayout->addLayout(slopeLayout[i]);
connectWidgetMainLayout->addLayout(portLayout);
connectWidgetMainLayout->addWidget(connectButton);
this->setLayout(connectWidgetMainLayout);
this->setWindowTitle("MCM's Set up");
//connections
connect(connectButton, SIGNAL(clicked()), this, SLOT(ConnectSerial()));
}
Widget::~Widget()
{
}
void Widget::ConnectSerial(){
//serial setting
port = new QSerialPort();
port->setPortName(portBox->currentText());
port->setBaudRate(QSerialPort::Baud19200);
port->setDataBits(QSerialPort::Data8);
port->setParity(QSerialPort::NoParity);
port->setStopBits(QSerialPort::OneStop);
port->setFlowControl(QSerialPort::NoFlowControl);
//open
if(!port->open(QIODevice::ReadOnly)){
QMessageBox errorBox;
errorBox.setWindowTitle("Error!");
errorBox.setInformativeText("Serial Port error");
errorBox.setStandardButtons(QMessageBox::Close);
errorBox.exec();
}
else{
qreal dangerValue = dangerInput->text().toFloat();
qreal cautionValue = cautionInput->text().toFloat();
qreal dangerSlope = slopeInput[0]->text().toFloat();
qreal cautionSlope = slopeInput[1]->text().toFloat();
if(dangerValue < cautionValue){
QMessageBox errorBox;
errorBox.critical(0, "Error!", "Serial Port Error!");
errorBox.show();
return;
}
tabDialog = new TabDialog(dangerValue, cautionValue, dangerSlope, cautionSlope, port);
this->hide();
tabDialog->show();
tabDialog->exec();
}
}