-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntegerControl.cpp
48 lines (36 loc) · 1.11 KB
/
IntegerControl.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
// SPDX-License-Identifier: MIT
#include "IntegerControl.hpp"
IntegerControl::IntegerControl(vcap_device* vd, vcap_control_info info) : ControlWrapper(vd, info), slider_(Qt::Horizontal)
{
slider_.setMinimum(info.min);
slider_.setMaximum(info.max);
slider_.setTickInterval(info.step);
update();
connect(&slider_, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
}
void IntegerControl::check()
{
vcap_control_status status;
if (vcap_get_control_status(vd_, info_.id, &status) != VCAP_OK)
throw std::runtime_error(vcap_get_error(vd_));
bool enabled = slider_.isEnabled();
if (!status.read_only && !status.write_only && !status.disabled && !status.inactive)
{
if (!enabled)
update();
slider_.setDisabled(false);
}
else
{
slider_.setDisabled(true);
}
}
void IntegerControl::update()
{
int32_t value;
if (vcap_get_control(vd_, info_.id, &value) != VCAP_OK)
throw std::runtime_error(vcap_get_error(vd_));
slider_.blockSignals(true);
slider_.setValue(value);
slider_.blockSignals(false);
}