-
Notifications
You must be signed in to change notification settings - Fork 3
/
customslider.h
50 lines (35 loc) · 1.02 KB
/
customslider.h
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
#ifndef CUSTOMSLIDER_H
#define CUSTOMSLIDER_H
#include <QPropertyAnimation>
#include <QWidget>
#include <QPen>
#include <QPainter>
#include <QPixmap>
#include <QPoint>
#include <QColor>
#include <QMouseEvent>
#include <cmath>
class CustomSlider : public QWidget
{
Q_OBJECT
Q_PROPERTY(qreal position READ position WRITE setSliderPosition)
public:
explicit CustomSlider(QWidget * parent = 0);
~CustomSlider();
qreal position() const { return sliderPosition; }
void setSliderPosition(qreal p) { sliderPosition = p; }
QSize sizeHint() const { return QSize(width(), height()); }
protected:
void paintEvent(QPaintEvent * event = 0);
void mousePressEvent(QMouseEvent * event = 0);
signals:
void clicked();
private:
bool withinArea(QPoint pos) const;
// euclidian distance --
qreal dist(qreal x1, qreal y1, qreal x2, qreal y2) const { return sqrt( pow(x1 - x2, 2) + pow(y1 - y2, 2) ); }
private:
QPropertyAnimation * animation;
qreal sliderPosition;
};
#endif // CUSTOMSLIDER_H