-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystemoption.cpp
More file actions
122 lines (112 loc) · 5.01 KB
/
systemoption.cpp
File metadata and controls
122 lines (112 loc) · 5.01 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
#include "systemoption.h"
#include <QDebug>
#include <QIntValidator>
#include <QString>
#include <QTimer>
#include <QVariant>
SystemOption::SystemOption(QWidget *parent) :
QWidget(parent),
comLabel(new QLabel(this)),
comComboBox(new QComboBox(this)),
baudRateLabel(new QLabel(this)),
baudRateComboBox(new QComboBox(this)),
comButton(new QPushButton(this)),
comStatusLabel(new QLabel(this)),
comStatus(new QLabel(this)),
ipLabel(new QLabel(this)),
portLabel(new QLabel(this)),
getIp(new QLineEdit(this)),
getPort(new QLineEdit(this)),
listen(new QPushButton(this)),
linkStatusLabel(new QLabel(this)),
linkStatus(new QComboBox(this)),
serverStatusLabel(new QLabel(this)),
serverStatus(new QLabel(this)),
systemOptionLayout(new QGridLayout(this))
{
setWindowTitle("System Option");
resize(300, 240);
comLabel->setText("COM");
comComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
baudRateLabel->setText("Baud Rate");
baudRateComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
comButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
comButton->setText("Open COM");
comStatusLabel->setText("COM Status");
comStatus->setText("Unconnected");
ipLabel->setText("IP Address");
portLabel->setText("Port");
getIp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
getIp->setFocusPolicy(Qt::NoFocus);
getPort->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
QIntValidator *getPortValidator = new QIntValidator(0, 65535, getPort);
getPort->setValidator(getPortValidator);
listen->setText("Listen");
listen->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
linkStatusLabel->setText("Link to");
serverStatusLabel->setText("Sever Status");
serverStatus->setText("Unconnected");
systemOptionLayout->addWidget(comLabel, 0, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(baudRateLabel, 0, 1, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(comComboBox, 1, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(baudRateComboBox, 1, 1, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(comButton, 1, 2, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(comStatusLabel, 2, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(comStatus, 2, 1, 1, 2, Qt::AlignVCenter);
systemOptionLayout->addWidget(ipLabel, 3, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(portLabel, 3, 1, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(getIp, 4, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(getPort, 4, 1, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(listen, 4, 2, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(linkStatusLabel, 5, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(linkStatus, 5, 1, 1, 2, Qt::AlignVCenter);
systemOptionLayout->addWidget(serverStatusLabel, 6, 0, 1, 1, Qt::AlignVCenter);
systemOptionLayout->addWidget(serverStatus, 6, 1, 1, 2, Qt::AlignVCenter);
//systemOptionLayout->setVerticalSpacing(0);
//systemOptionLayout->setHorizontalSpacing(0);
for(int i = 0; i < systemOptionLayout->columnCount(); i++)
systemOptionLayout->setColumnStretch(i, 1);
for(int i = 0; i < systemOptionLayout->rowCount(); i++)
systemOptionLayout->setRowStretch(i, 1);
setLayout(systemOptionLayout);
QObject::connect(comButton, &QPushButton::clicked, [](){qDebug() << "clLL";});
QObject::connect(listen, &QPushButton::clicked, this, &SystemOption::newlisten);
QObject::connect(linkStatus, static_cast<void(QComboBox::*)(int index)>(&QComboBox::currentIndexChanged), [=](int a){qDebug() << a << "current";});
//test code, it will be deleted in released version
QObject::connect(linkStatus, static_cast<void(QComboBox::*)(int index)>(&QComboBox::currentIndexChanged), [=](){emit currentsocketChanged(getCurrentSocketDescriptor());});
}
void SystemOption::newlisten()
{
/*
* when the "Listen" button is clicked, the slots is called;
* close the current listen, and get the TextEdit(getPort) Int : port, listen the port;
*/
serverStatus->setText("Listening Port" + QString::number(port));
}
SystemOption::~SystemOption()
{
}
void SystemOption::comboBoxAddItem(int socketDescriptor)
{
/*
* when new socket connects to the server, combo box add new item by QVariant;
*/
QVariant itemData = socketDescriptor;
linkStatus->addItem(QString::number(socketDescriptor), itemData);
}
void SystemOption::comboBoxDeleteItem(int socketDescritor)
{
/*
* when socket disconnect from the host, combo box delete the socket item by socket descriptor
*/
int index = linkStatus->findText(QString::number(socketDescritor));
linkStatus->removeItem(index);
}
int SystemOption::getCurrentSocketDescriptor() const
{
/*
* combox get index of current socket
*/
qDebug() << "this is get current socket calling";
return 0;
}