-
Notifications
You must be signed in to change notification settings - Fork 0
/
formsliderinfo.cpp
94 lines (79 loc) · 2.39 KB
/
formsliderinfo.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
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
#include "formsliderinfo.h"
#include "ui_formsliderinfo.h"
#include <QDebug>
FormSliderInfo::FormSliderInfo(QString name, int rMin, int rMax, int val, QWidget *parent) :
QWidget(parent),
ui(new Ui::FormSliderInfo),
value(val)
{
ui->setupUi(this);
ui->label->setText(name);
setWindowFlags(Qt::Tool | Qt::WindowCloseButtonHint);
//setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
validator = new QIntValidator(rMin, rMax);
ui->value->setValidator(validator);
ui->slider->setRange(rMin, rMax);
ui->slider->setValue(value);
ui->value->setText(QString::number(value));
ui->slider->setSingleStep(10);
ui->slider->setPageStep(100);
connect(ui->slider, SIGNAL (valueChanged(int)), this, SLOT (handleValue(int)));
connect(ui->value, SIGNAL(editingFinished()), this, SLOT(valueBoxEditingFinished()));
}
FormSliderInfo::~FormSliderInfo()
{
delete ui;
}
void FormSliderInfo::setValue(int v) {
ui->slider->setValue(v);
}
void FormSliderInfo::setSingleStep(int s) {
ui->slider->setSingleStep(s);
}
void FormSliderInfo::setPageStep(int s) {
ui->slider->setPageStep(s);
}
void FormSliderInfo::setRange(int rMin, int rMax) {
// qDebug() << "setRange: " << rMin << " / " << rMax;
ui->slider->setRange(rMin, rMax);
validator->setRange(rMin, rMax);
}
void FormSliderInfo::extendRange(int rMin, int rMax) {
extendMinimum(rMin);
extendMaximum(rMax);
}
void FormSliderInfo::setMinimum(int rMin) {
ui->slider->setMinimum(rMin);
validator->setBottom(rMin);
}
void FormSliderInfo::extendMinimum(int rMin) {
if (rMin < ui->slider->minimum()) {
ui->slider->setMinimum(rMin);
validator->setBottom(rMin);
}
}
int FormSliderInfo::minimum() const {
return ui->slider->minimum();
}
void FormSliderInfo::setMaximum(int rMax) {
ui->slider->setMaximum(rMax);
validator->setTop(rMax);
}
void FormSliderInfo::extendMaximum(int rMax) {
if (rMax > ui->slider->maximum()) {
ui->slider->setMaximum(rMax);
validator->setTop(rMax);
}
}
int FormSliderInfo::maximum() const {
return ui->slider->maximum();
}
void FormSliderInfo::handleValue(int i) {
// qDebug() << "Value: " << i;
value = i;
ui->value->setText(QString::number(value));
emit valueChanged(i);
}
void FormSliderInfo::valueBoxEditingFinished() {
ui->slider->setValue(ui->value->text().toInt());
}