1 #pragma once
2 
3 #include <QWidget>
4 #include <QPainter>
5 #include <QMouseEvent>
6 
7 class RangeSlider : public QWidget
8 {
9     Q_OBJECT
10 
11 public:
12     RangeSlider(QWidget* aParent = Q_NULLPTR);
13 
14     QSize minimumSizeHint() const override;
15 
16     int GetMinimun() const;
17     void SetMinimum(int aMinimum);
18 
19     int GetMaximun() const;
20     void SetMaximum(int aMaximum);
21 
22     int GetLowerValue() const;
23     void SetLowerValue(int aLowerValue);
24 
25     int GetUpperValue() const;
26     void SetUpperValue(int aUpperValue);
27 
28     void SetRange(int aMinimum, int aMaximum);
29 
30 protected:
31     void paintEvent(QPaintEvent* aEvent) override;
32     void mousePressEvent(QMouseEvent* aEvent) override;
33     void mouseMoveEvent(QMouseEvent* aEvent) override;
34     void mouseReleaseEvent(QMouseEvent* aEvent) override;
35     void changeEvent(QEvent* aEvent) override;
36 
37     QRectF firstHandleRect() const;
38     QRectF secondHandleRect() const;
39     QRectF handleRect(int aValue) const;
40 
41 signals:
42     void lowerValueChanged(int aLowerValue);
43     void upperValueChanged(int aUpperValue);
44     void rangeChanged(int aMin, int aMax);
45 
46 public slots:
47     void setLowerValue(int aLowerValue);
48     void setUpperValue(int aUpperValue);
49     void setMinimum(int aMinimum);
50     void setMaximum(int aMaximum);
51 
52 private:
53     Q_DISABLE_COPY(RangeSlider)
54     float currentPercentage();
55     int validWidth() const;
56 
57     int mMinimum;
58     int mMaximum;
59     int mLowerValue;
60     int mUpperValue;
61     bool mFirstHandlePressed;
62     bool mSecondHandlePressed;
63     int mInterval;
64     int mDelta;
65     QColor mBackgroudColorEnabled;
66     QColor mBackgroudColorDisabled;
67     QColor mBackgroudColor;
68 };
69