-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingslider.cpp
More file actions
51 lines (42 loc) · 1.16 KB
/
settingslider.cpp
File metadata and controls
51 lines (42 loc) · 1.16 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
#include "settingslider.h"
#include "ui_settingslider.h"
#define MAXSLIDER 1000.0
SettingSlider::SettingSlider(QWidget *parent) :
QWidget(parent),
ui(new Ui::SettingSlider)
{
ui->setupUi(this);
ui->horizontalSlider->setMinimum(0);
ui->horizontalSlider->setMaximum(MAXSLIDER);
}
void SettingSlider::setSetting(const Setting &s)
{
setting = s;
ui->label->setText( s.name );
float d = s.max - s.min;
ui->horizontalSlider->setValue( (s.val - s.min) / d * MAXSLIDER );
ui->doubleSpinBox->setMinimum(s.min);
ui->doubleSpinBox->setMaximum(s.max);
ui->doubleSpinBox->setValue(s.val);
ui->doubleSpinBox->setSingleStep(d/MAXSLIDER);
}
void SettingSlider::updateValueFromSpin()
{
#define s setting
s.val = ui->doubleSpinBox->value();
ui->horizontalSlider->setValue( (s.val - s.min) / (s.max - s.min) * MAXSLIDER );
updateSetting(s);
#undef s
}
void SettingSlider::updateValueFromSlide()
{
#define s setting
s.val = ui->horizontalSlider->value() / MAXSLIDER * (s.max - s.min) + s.min;
ui->doubleSpinBox->setValue(s.val);
updateSetting(s);
#undef s
}
SettingSlider::~SettingSlider()
{
delete ui;
}