-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriggerOptionsDialog.cpp
More file actions
148 lines (117 loc) · 4.63 KB
/
Copy pathTriggerOptionsDialog.cpp
File metadata and controls
148 lines (117 loc) · 4.63 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
#include "TriggerOptionsDialog.hpp"
TriggerOptionsDialog::TriggerOptionsDialog(QWidget *parent)
: QDialog(parent) {
setWindowTitle("Ustawienia wyzwalacza");
QLayout *ui = createLayoutUI();
setLayout(ui);
setDialogSize(ui);
setOptions(DEFAULT_TRIGGER_OPTIONS);
connectSignalsAndSlots();
}
QLayout *TriggerOptionsDialog::createLayoutUI() {
activeCheck = new QCheckBox("Wyzwalacz aktywny");
channelSelect = new QComboBox();
channelSelect->addItem("Kanał 1", 1);
channelSelect->addItem("Kanał 2", 2);
channelSelect->addItem("Kanał 3", 3);
channelSelect->addItem("Kanał 4", 4);
voltageEdit = new QDoubleSpinBox();
voltageEdit->setSuffix(" V");
voltageEdit->setDecimals(2);
voltageEdit->setSingleStep(0.1);
voltageEdit->setRange(0.0, 5.1);
voltageEdit->setButtonSymbols(QAbstractSpinBox::PlusMinus);
edgeSelect = new QComboBox();
edgeSelect->addItem("Dowolne", TriggerOptions::AnyEdge);
edgeSelect->addItem("Rosnące", TriggerOptions::RisingEdge);
edgeSelect->addItem("Opadające", TriggerOptions::FallingEdge);
oneShotCheck = new QCheckBox("OneShot");
oneShotCheck->setChecked(false);
showCallsCheck = new QCheckBox("Pokaż wywołania");
formLayout = new QFormLayout();
formLayout->addWidget(activeCheck);
formLayout->addRow("Kanał: ", channelSelect);
formLayout->addRow("Napięcie: ", voltageEdit);
formLayout->addRow("Zbocze: ", edgeSelect);
formLayout->addRow("", showCallsCheck);
formLayout->addRow("", oneShotCheck);
return formLayout;
}
void TriggerOptionsDialog::setDialogSize(QLayout *layoutUI) {
int heightHint = layoutUI->sizeHint().height();
this->setFixedHeight(heightHint);
this->setFixedWidth(300);
}
void TriggerOptionsDialog::connectSignalsAndSlots() {
connect(activeCheck, SIGNAL(stateChanged(int)),
this, SLOT(handleActiveChanged(int)));
connect(channelSelect, SIGNAL(currentIndexChanged(int)),
this, SLOT(handleChannelChanged(int)));
connect(voltageEdit, SIGNAL(valueChanged(double)),
this, SLOT(handleVoltageChanged(double)));
connect(edgeSelect, SIGNAL(currentIndexChanged(int)),
this, SLOT(handleEdgeChanged(int)));
connect(oneShotCheck, SIGNAL(stateChanged(int)),
this, SLOT(handleOneShotChanged(int)));
connect(showCallsCheck, SIGNAL(stateChanged(int)),
this, SLOT(handleShowCallsChanged(int)));
}
void TriggerOptionsDialog::handleActiveChanged(int state) {
bool isActive = (bool) state;
currentOptions.isActive = isActive;
setWidgetsEnable(isActive);
emit optionsChanged(currentOptions);
}
void TriggerOptionsDialog::handleChannelChanged(int index) {
int channel = channelSelect->itemData(index).toInt();
currentOptions.channel = channel;
emit optionsChanged(currentOptions);
}
void TriggerOptionsDialog::handleVoltageChanged(double value) {
currentOptions.voltage = value;
emit optionsChanged(currentOptions);
}
void TriggerOptionsDialog::handleEdgeChanged(int index) {
QVariant data = edgeSelect->itemData(index);
TriggerOptions::EdgeType edge = (TriggerOptions::EdgeType) data.toInt();
currentOptions.edge = edge;
emit optionsChanged(currentOptions);
}
void TriggerOptionsDialog::handleOneShotChanged(int state) {
bool showShot = (bool) state;
currentOptions.oneShot = showShot;
emit optionsChanged(currentOptions);
}
void TriggerOptionsDialog::handleShowCallsChanged(int state) {
bool isShowCalls = (bool) state;
currentOptions.isShowCalls = isShowCalls;
emit optionsChanged(currentOptions);
}
TriggerOptions TriggerOptionsDialog::getOptions() {
return currentOptions;
}
void TriggerOptionsDialog::setOptions(TriggerOptions options) {
activeCheck->setChecked(options.isActive);
setWidgetsEnable(options.isActive);
int channelIndex = channelSelect->findData(options.channel);
channelSelect->setCurrentIndex(channelIndex);
voltageEdit->setValue(options.voltage);
int edgeIndex = edgeSelect->findData(options.edge);
edgeSelect->setCurrentIndex(edgeIndex);
showCallsCheck->setChecked(options.isShowCalls);
currentOptions = options;
emit optionsChanged(currentOptions);
}
void TriggerOptionsDialog::setWidgetsEnable(bool enable) {
channelSelect->setEnabled(enable);
voltageEdit->setEnabled(enable);
edgeSelect->setEnabled(enable);
showCallsCheck->setEnabled(enable);
}
void TriggerOptionsDialog::showEvent(QShowEvent *event) {
if (!savedGeometry.isEmpty())
restoreGeometry(savedGeometry);
}
void TriggerOptionsDialog::closeEvent(QCloseEvent *event) {
savedGeometry = saveGeometry();
}