forked from mrkite/minutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabelledslider.cpp
62 lines (51 loc) · 1.5 KB
/
labelledslider.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
/** Copyright (c) 2013, Sean Kasun */
#include <QVBoxLayout>
#include "./labelledslider.h"
LabelledSlider::LabelledSlider(Qt::Orientation orientation, QWidget *parent) :
QWidget(parent) {
slider = new MSlider(orientation);
slider->setRange(0, 255);
label = new QLabel();
label->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
label->setFixedWidth(label->fontMetrics().width("888"));
label->setNum(255);
connect(slider, SIGNAL(valueChanged(int)),
this, SLOT(intValueChange(int)));
QBoxLayout *myLayout;
if (orientation == Qt::Vertical) {
myLayout = new QVBoxLayout;
myLayout->addWidget(label);
myLayout->addWidget(slider);
} else {
myLayout = new QHBoxLayout;
myLayout->addWidget(slider);
myLayout->addWidget(label);
}
setLayout(myLayout);
setFocusProxy(slider);
}
int LabelledSlider::value() const {
return slider->value();
}
// public slot
void LabelledSlider::setValue(int v) {
slider->setValue(v);
}
// public slot
void LabelledSlider::changeValue(int v) {
slider->setValue(slider->value() + v);
}
// private slot
void LabelledSlider::intValueChange(int v) {
label->setNum(v);
emit valueChanged(v);
}
void LabelledSlider::wheelEvent(QWheelEvent* event) {
slider->wheelEvent(event);
}
MSlider::MSlider(Qt::Orientation orientation, QWidget* parent) :
QSlider(orientation, parent) {}
void MSlider::wheelEvent(QWheelEvent* event) {
int delta = event->delta() / 120; // in order to make wheel intuitive
this->setValue(this->value() + delta);
}