-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonBar.cpp
More file actions
327 lines (237 loc) · 9.08 KB
/
ButtonBar.cpp
File metadata and controls
327 lines (237 loc) · 9.08 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "ButtonBar.h"
#include <QVBoxLayout>
#include "RCWidgets.h"
ButtonBar::ButtonBar(QWidget* parent) : QWidget(parent) {
//setWindowTitle("Serial Port Manager");
//TextEdit1 = new QLabel("0");
//TextEdit1->setFixedHeight(40);
//TextEdit1->setFixedWidth(50);
//TextEdit1->setStyleSheet("background-color: green; color: white;");
//TextEdit2 = new QLabel("1000");
//TextEdit2->setFixedHeight(40);
//TextEdit2->setFixedWidth(50);
//TextEdit2->setStyleSheet("background-color: lightgray; color: white;");
//// 创建发送按钮
//sendButton1 = new QPushButton("Send");
//sendButton1->setFixedSize(60, 100);
// sendButton1->setEnabled(false); // 初始为禁用状态
for (int i = 0; i < 3; i++)
{
sendButton[i] = new QPushButton("0");
sendButton[i]->setFixedSize(150, 80);
sendButton[i]->setStyleSheet("background-color: gray; color: white;");
}
QHBoxLayout* hlayout1 = new QHBoxLayout();
for (int i = 0; i < 3; i++)
{
hlayout1->addWidget(sendButton[i]);
}
QObject::connect(sendButton[0], &QPushButton::clicked, [=]() {
static bool isClicked = true;
if (isClicked) {
sendButton[0]->setStyleSheet("background-color: green; color: white;");
sendButton[0]->setText("1000"); // 更改按钮文本
mozaData.N = 1;
}
else {
sendButton[0]->setStyleSheet("background-color: gray; color: white;");
sendButton[0]->setText("0"); // 更改按钮文本
mozaData.N = 0;
}
isClicked = !isClicked;
});
QObject::connect(sendButton[0], &QPushButton::clicked, [=]() {
static bool isClicked = true;
if (isClicked) {
sendButton[0]->setStyleSheet("background-color: green; color: white;");
sendButton[0]->setText("1000"); // 更改按钮文本
mozaData.N = 1;
}
else {
sendButton[0]->setStyleSheet("background-color: gray; color: white;");
sendButton[0]->setText("0"); // 更改按钮文本
mozaData.N = 0;
}
isClicked = !isClicked;
});
QObject::connect(sendButton[1], &QPushButton::clicked, [=]() {
static bool isClicked = true;
if (isClicked) {
sendButton[1]->setStyleSheet("background-color: green; color: white;");
sendButton[1]->setText("1000"); // 更改按钮文本
mozaData.WIP = 1;
}
else {
sendButton[1]->setStyleSheet("background-color: gray; color: white;");
sendButton[1]->setText("0"); // 更改按钮文本
mozaData.WIP = 0;
}
isClicked = !isClicked;
});
QObject::connect(sendButton[2], &QPushButton::clicked, [=]() {
static bool isClicked = true;
if (isClicked) {
sendButton[2]->setStyleSheet("background-color: green; color: white;");
sendButton[2]->setText("1000"); // 更改按钮文本
mozaData.L = 1;
}
else {
sendButton[2]->setStyleSheet("background-color: gray; color: white;");
sendButton[2]->setText("0"); // 更改按钮文本
mozaData.L = 0;
}
isClicked = !isClicked;
});
//QHBoxLayout* hlayout2 = new QHBoxLayout();
//for (int i = 3; i < 6; i++)
//{
// hlayout2->addWidget(sendButton[i]);
//}
//QVBoxLayout* vlayout1 = new QVBoxLayout();
//vlayout1->addLayout(hlayout1);
//vlayout1->addLayout(hlayout2);
//setLayout(vlayout1);
// //创建发送框
// TextEdit3 = new QLabel("0");
// TextEdit3->setFixedHeight(40);
// TextEdit3->setFixedWidth(60);
// TextEdit3->setStyleSheet("background-color: green; color: white;");
// TextEdit4 = new QLabel("1000");
// TextEdit4->setFixedHeight(40);
// TextEdit4->setFixedWidth(60);
// TextEdit4->setStyleSheet("background-color: lightgray; color: white;");
// //创建发送按钮
// sendButton2 = new QPushButton("Send");
// sendButton2->setFixedSize(60, 100);
//// sendButton2->setEnabled(false); // 初始为禁用状态
// TextEdit5 = new QLabel("0");
// TextEdit5->setFixedHeight(40);
// TextEdit5->setFixedWidth(60);
// TextEdit5->setStyleSheet("background-color: green; color: white;");
// TextEdit6 = new QLabel("1000");
// TextEdit6->setFixedHeight(40);
// TextEdit6->setFixedWidth(60);
// TextEdit6->setStyleSheet("background-color: lightgray; color: white;");
// //创建发送按钮
// sendButton3 = new QPushButton("Send");
// sendButton3->setFixedSize(60, 100);
//// sendButton3->setEnabled(false); // 初始为禁用状态
// QVBoxLayout* vlayout1 = new QVBoxLayout();
// vlayout1->addWidget(TextEdit1);
// vlayout1->addWidget(TextEdit2);
// QHBoxLayout* hlayout1 = new QHBoxLayout;
// hlayout1->addLayout(vlayout1);
// hlayout1->addWidget(sendButton1);
// QVBoxLayout* vlayout2 = new QVBoxLayout();
// vlayout2->addWidget(TextEdit3);
// vlayout2->addWidget(TextEdit4);
// QHBoxLayout* hlayout2 = new QHBoxLayout;
// hlayout2->addLayout(vlayout2);
// hlayout2->addWidget(sendButton2);
// QVBoxLayout* vlayout3 = new QVBoxLayout();
// vlayout3->addWidget(TextEdit5);
// vlayout3->addWidget(TextEdit6);
// QHBoxLayout* hlayout3 = new QHBoxLayout;
// hlayout3->addLayout(vlayout3);
// hlayout3->addWidget(sendButton3);
// QHBoxLayout* hlayout4 = new QHBoxLayout;
// hlayout4->addLayout(hlayout1);
// hlayout4->addLayout(hlayout2);
// hlayout4->addLayout(hlayout3);
// hlayout4->addWidget(slider);
QHBoxLayout* hlayout5 = new QHBoxLayout;
// 创建 QLabel 用于显示滑条的值
label = new QLabel("0");
label->setFixedWidth(30);
slider = new QSlider(Qt::Horizontal); // 创建水平滑条
slider->setRange(-500, 500); // 设置范围
slider->setValue(-500); // 设置初始值
// 自定义滑条的大小和颜色
slider->setFixedHeight(40); // 设置滑条的高度
// 使用样式表设置滑条的颜色
slider->setStyleSheet(
"QSlider {"
" background: lightgray;" // 背景颜色,表示未滑过的部分
" border-radius: 5px;"
"}"
"QSlider::handle {"
" background: white;" // 滑块颜色
" width: 40px;" // 滑块宽度
" height: 30px;"
" border-radius: 5px;" // 滑块圆角
"}"
"QSlider::groove:horizontal {"
" background: lightgray;" // 轨道的背景颜色,表示未滑过的部分
" border-radius: 5px;"
"}"
"QSlider::sub-page:horizontal {"
" background: green;" // 滑条已滑过部分的颜色
" border-radius: 5px;"
"}"
"QSlider::add-page:horizontal {"
" background: lightgray;" // 滑条未滑过部分的颜色
" border-radius: 5px;"
"}"
);
// 连接信号与槽函数
QObject::connect(slider, &QSlider::valueChanged, [this](int value) {
label->setText(QString::number(value+500)); // 更新 QLabel 的文本
mozaData.ch = value;
slider->setStyleSheet(
QString(
"QSlider {"
" background: lightgray;" // 背景颜色,表示未滑过的部分 " border-radius: 10px;"
"border-radius: 10px;"
"}"
"QSlider::handle {"
" background: white;" // 滑块颜色
" width: 40px;" // 滑块宽度
"height: 30px;"
" border-radius: 5px;" // 滑块圆角
"}"
"QSlider::groove:horizontal {"
"background: lightgray;" // 轨道的背景颜色,表示未滑过的部分
"border-radius: 5px;"
"}"
"QSlider::sub-page:horizontal {"
" background: green;" // 滑条已滑过部分的颜色
" width: %1px;" // 使用当前值设置已滑过部分的宽度
" border-radius: 5px;"
"}"
"QSlider::add-page:horizontal {"
" background: lightgray;" // 滑条未滑过部分的颜色
" border-radius: 5px;"
"}"
) .arg(value * 2)); // 根据滑条的值设置宽度(乘以 2 以适应滑条的宽度)
});
hlayout5->addWidget(slider);
hlayout5->addWidget(label);
QVBoxLayout* vlayout4 = new QVBoxLayout();
vlayout4->addLayout(hlayout1);
vlayout4->addLayout(hlayout5);
setLayout(vlayout4);
// 连接按钮点击事件
// connect(connectButton, &QPushButton::clicked, this, &ButtonBar::toggleConnection);
//// 发送按钮点击事件
//connect(sendButton, &QPushButton::clicked, this, &ButtonBar::sendData);
// 安装事件过滤器以捕获下拉框打开事件
// portSelector->view()->installEventFilter(this);
}
ButtonBar::~ButtonBar() {
}
void ButtonBar::toggleConnection() {
}
void ButtonBar::sendData() {
}
void ButtonBar::readData() {
}
void ButtonBar::refreshPorts() {
}
void ButtonBar::setConnectButtonStyle(bool connected) {
if (connected) {
connectButton->setStyleSheet("background-color: green; color: white;");
}
else {
connectButton->setStyleSheet("background-color: red; color: white;");
}
}