1 //=============================================================================
2 //  Awl
3 //  Audio Widget Library
4 //
5 //  Copyright (C) 2002-2006 by Werner Schweer and others
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __STYLEDSLIDER_H__
21 #define __STYLEDSLIDER_H__
22 
23 #include <QWidget>
24 #include <QIcon>
25 
26 
27 namespace Awl {
28 
29 class StyledSlider : public QWidget
30       {
31       Q_OBJECT
32 
33       QList<double> marks;
34 
35       double _minValue = 0;
36       double _maxValue = 127;
37       double _value;
38       double _barThickness = 4;
39       double _margin = 20;
40       int _numMajorTicks = 10;
41       int _numMinorTicks = 4;
42       double _majorTickWidth = 30;
43       double _minorTickWidth = 10;
44       double _doubleClickValue = 63;
45 
46       QColor _backgroundColor = QColor(10, 10, 10);
47       QColor _hilightColor = QColor(0, 255, 0);
48       QColor _tickColor = QColor(150, 150, 150);
49 
50       bool draggingMouse;
51       QPoint mouseDownPos;
52       double mouseDownVal;
53 
54       QIcon _sliderHeadIcon;
55 
56 public:
57       explicit StyledSlider(QWidget *parent = nullptr);
sizeHint()58       virtual QSize sizeHint() const { return QSize(50, 50); }
59       virtual void paintEvent(QPaintEvent *ev);
60       virtual void mousePressEvent(QMouseEvent*);
61       virtual void mouseReleaseEvent(QMouseEvent*);
62       virtual void mouseMoveEvent(QMouseEvent*);
63       virtual void wheelEvent(QWheelEvent*);
64       virtual void keyPressEvent(QKeyEvent*);
65 
maxValue()66       double maxValue() const { return _maxValue; }
minValue()67       double minValue() const { return _minValue; }
value()68       double value() const { return _value; }
barThickness()69       double barThickness() const { return _barThickness; }
margin()70       double margin() const { return _margin; }
numMajorTicks()71       double numMajorTicks() const { return _numMajorTicks; }
numMinorTicks()72       int numMinorTicks() const { return _numMinorTicks; }
majorTickWidth()73       double majorTickWidth() const { return _majorTickWidth; }
minorTickWidth()74       double minorTickWidth() const { return _minorTickWidth; }
backgroundColor()75       QColor backgroundColor() const { return _backgroundColor; }
hilightColor()76       QColor hilightColor() const { return _hilightColor; }
tickColor()77       QColor tickColor() const { return _tickColor; }
sliderHeadIcon()78       QIcon sliderHeadIcon() const { return _sliderHeadIcon; }
addMark(double value)79       void addMark(double value) { marks.append(value); }
80       void mouseDoubleClickEvent(QMouseEvent*);
setDoubleClickValue(double value)81       void setDoubleClickValue(double value) { _doubleClickValue = value; }
82 
83 signals:
84       void valueChanged(double);
85       void minValueChanged(double);
86       void maxValueChanged(double);
87       void sliderPressed();
88 
89 public slots:
90       void setValue(double v);
91       void setMinValue(double v);
92       void setMaxValue(double v);
93       void setBarThickness(double v);
94       void setMargin(double v);
95       void setNumMajorTicks(int v);
96       void setNumMinorTicks(int v);
97       void setMajorTickWidth(double v);
98       void setMinorTickWidth(double v);
99 
100       void setBackgroundColor(QColor v);
101       void setHilightColor(QColor v);
102       void setTickColor(QColor v);
103       void setSliderHeadIcon(QIcon v);
104       };
105 
106 }
107 #endif // __STYLEDSLIDER_H__
108