-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelPanel.cpp
More file actions
77 lines (61 loc) · 2.05 KB
/
Copy pathChannelPanel.cpp
File metadata and controls
77 lines (61 loc) · 2.05 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
#include <QtWidgets/QBoxLayout>
#include "ChannelPanel.hpp"
ChannelPanel::ChannelPanel(int channel, QString name, QColor color)
: channel(channel) {
nameLabel = new QLabel(name);
toggleBtn = new QPushButton("On");
toggleBtn->setCheckable(true);
toggleBtn->setChecked(true);
toggleBtn->setFixedWidth(35);
voltageLabel = new QLabel();
voltageLabel->setLineWidth(2);
voltageLabel->setFrameStyle(QFrame::Box);
QFont voltageFont("Courier New");
voltageFont.setPixelSize(18);
voltageFont.setBold(true);
voltageLabel->setFont(voltageFont);
voltageLabel->setAlignment(Qt::AlignRight);
QHBoxLayout *topLayout = new QHBoxLayout();
topLayout->addWidget(nameLabel);
topLayout->addWidget(toggleBtn);
QVBoxLayout *layout = new QVBoxLayout();
layout->addLayout(topLayout);
layout->addWidget(voltageLabel);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setLayout(layout);
paletteEnabled.setColor(foregroundRole(), color);
paletteDisabled.setColor(foregroundRole(), Qt::gray);
setChannelVisible(true);
connect(toggleBtn, SIGNAL(toggled(bool)),
this, SLOT(setChannelVisible(bool)));
}
void ChannelPanel::setChannelColor(QColor color) {
paletteEnabled.setColor(foregroundRole(), color);
}
void ChannelPanel::setVoltage(double value) {
if (channelVisible) {
QString text = QString("%1 V")
.arg(QString::number(value, 'f', 2));
voltageLabel->setText(text);
}
}
void ChannelPanel::setChannelVisible(bool visible) {
channelVisible = visible;
if (visible) {
toggleBtn->setText("On");
toggleBtn->setChecked(visible);
setPalette(paletteEnabled);
} else {
toggleBtn->setText("Off");
toggleBtn->setChecked(visible);
setNullVoltage();
setPalette(paletteDisabled);
}
emit channelVisibleChanged(channel, visible);
}
void ChannelPanel::setNullVoltage() {
voltageLabel->setText("-.-- V");
}
bool ChannelPanel::isChannelVisible() {
return channelVisible;
}