-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmainwindow.cpp
154 lines (136 loc) · 3.74 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDate>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(tr("NetAssistant"));
setFixedHeight(445);
setFixedWidth(685);
status_Label = new QLabel();
status_Label->setMinimumSize(260, 20); // 设置标签最小大小
status_Label->setFrameShape(QFrame::WinPanel);
status_Label->setFrameShadow(QFrame::Sunken);
ui->statusBar->addWidget(status_Label);
status_Label->setText(tr("TCP Server is not active"));
status_Label->setAlignment(Qt::AlignHCenter);
receive_Label = new QLabel();
receive_Label->setMinimumSize(100, 20); // 设置标签最小大小
receive_Label->setFrameShape(QFrame::WinPanel);
receive_Label->setFrameShadow(QFrame::Sunken);
ui->statusBar->addWidget(receive_Label);
receive_Label->setAlignment(Qt::AlignHCenter);
send_Label = new QLabel();
send_Label->setMinimumSize(100, 20); // 设置标签最小大小
send_Label->setFrameShape(QFrame::WinPanel);
send_Label->setFrameShadow(QFrame::Sunken);
ui->statusBar->addWidget(send_Label);
send_Label->setAlignment(Qt::AlignHCenter);
clear_Count_Btn = new QPushButton(tr("Clear Count"));
ui->statusBar->addWidget(clear_Count_Btn);
connect(clear_Count_Btn, SIGNAL(clicked()), this, SLOT(clear_statusbar()));
time_Label = new QLabel();
time_Label->setMinimumSize(87, 20); // 设置标签最小大小
time_Label->setMaximumWidth(90);
time_Label->setFrameShape(QFrame::WinPanel);
time_Label->setFrameShadow(QFrame::Sunken);
ui->statusBar->addWidget(time_Label);
time_Label->setText(QDate::currentDate().toString("yy-MM-dd"));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::clear_statusbar()
{
update_statusbar(QString(), 0, 0);
}
void MainWindow::update_statusbar(QString status, QVariant in_num, QVariant out_num)
{
if (!status.isNull())
{
status_Label->setText(status);
}
if (!in_num.isNull())
{
if ( in_num.toInt() == 0 )
ReceiveNum = 0;
else
ReceiveNum += in_num.toInt();
receive_Label->setText("R:" + QString::number(ReceiveNum));
}
if (!out_num.isNull())
{
if ( out_num.toInt() == 0 )
SendNum = 0;
else
SendNum += out_num.toInt();
send_Label->setText("S:" + QString::number(SendNum));
}
}
void MainWindow::on_Clear_Display_PushButton_clicked()
{
ui->Receive_window_TextEdit->clear();
}
void MainWindow::on_Clear_Transmit_PushButton_clicked()
{
ui->transmit_window_TextEdit->clear();
}
void MainWindow::net_connect()
{
switch (ui->Protocol_ComboBox->currentIndex())
{
case 0:
// TCP Server
TCP_server_connect();
break;
case 1:
// TCP Client
TCP_client_connect();
break;
case 2:
// UDP
UDP_connect();
break;
default:
break;
}
}
// public functions
// TCP Server connections
void MainWindow::TCP_server_connect()
{
qDebug("%s", __func__ );
}
// TCP Server connections
void MainWindow::TCP_client_connect()
{
qDebug("%s", __func__ );
}
// TCP Server connections
void MainWindow::UDP_connect()
{
qDebug("%s", __func__ );
}
void MainWindow::on_Connect_Btn_clicked()
{
switch (ui->Protocol_ComboBox->currentIndex())
{
case 0:
// TCP Server
TCP_server_connect();
break;
case 1:
// TCP Client
TCP_client_connect();
break;
case 2:
// UDP
UDP_connect();
break;
default:
break;
}
}