-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclickslider.cpp
More file actions
63 lines (56 loc) · 1.36 KB
/
Copy pathclickslider.cpp
File metadata and controls
63 lines (56 loc) · 1.36 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
/**********************
** clickslider.cpp
**********************/
#include <QtGui>
#include <QStyleOptionSlider>
#include <QDebug>
#include "clickslider.h"
ClickSlider::ClickSlider( QWidget * parent) :QSlider(parent)
{
}
/*
void ClickSlider::mousePressEvent ( QMouseEvent * mouseEvent )
{
if(mouseEvent->button()==Qt::LeftButton && isEnabled())
{
int duration = maximum() - minimum();
int pos = minimum() + duration * ((double)mouseEvent->x() / width());
qDebug() << Q_FUNC_INFO << " pos" << pos;
if(pos != sliderPosition())
{
setValue(pos);
}
// else ok.
emit(sliderMoved(pos));
}
}
*/
void ClickSlider::mousePressEvent ( QMouseEvent * event )
{
QStyleOptionSlider opt;
initStyleOption(&opt);
int pos;
QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
if (event->button() == Qt::LeftButton &&
sr.contains(event->pos()) == false)
{
int newVal;
if (orientation() == Qt::Vertical)
newVal = minimum() + ((maximum()-minimum()) * (height()-event->y())) / height();
else
newVal = minimum() + ((maximum()-minimum()) * event->x()) / width();
if (invertedAppearance() == true)
{
setValue( maximum() - newVal );
pos = maximum() - newVal;
}
else
{
setValue(newVal);
pos = newVal;
}
event->accept();
}
QSlider::mousePressEvent(event);
emit(sliderMoved(pos));
}