1 /************************************************************************
2  *
3  * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
4  *
5  * This file is part of SuperCollider Qt GUI.
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 as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  ************************************************************************/
21 
22 #pragma once
23 
24 #include "QcAbstractStepValue.h"
25 #include "../QcHelper.h"
26 #include "../style/style.hpp"
27 
28 #include <QWidget>
29 
30 class QcRangeSlider : public QWidget, QcHelper, QcAbstractStepValue, QtCollider::Style::Client {
31     Q_OBJECT
32     Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation);
33     Q_PROPERTY(double loValue READ loValue WRITE setLoValue)
34     Q_PROPERTY(double hiValue READ hiValue WRITE setHiValue)
35     Q_PROPERTY(double shiftScale READ dummyFloat WRITE setShiftScale);
36     Q_PROPERTY(double ctrlScale READ dummyFloat WRITE setCtrlScale);
37     Q_PROPERTY(double altScale READ dummyFloat WRITE setAltScale);
38     Q_PROPERTY(double step READ dummyFloat WRITE setStep)
39     Q_PROPERTY(QColor grooveColor READ grooveColor WRITE setGrooveColor);
40     Q_PROPERTY(QColor focusColor READ focusColor WRITE setFocusColor);
41     Q_PROPERTY(QColor knobColor READ knobColor WRITE setKnobColor);
42 
43 public:
44     enum MouseMode { None = 0, Move, MoveHi, MoveLo, SetLo, SetHi };
45 
46     QcRangeSlider();
orientation()47     Qt::Orientation orientation() const { return _ort; }
48     void setOrientation(Qt::Orientation o);
loValue()49     double loValue() const { return _lo; }
50     void setLoValue(double);
hiValue()51     double hiValue() const { return _hi; }
52     void setHiValue(double);
53     void setRange(double val, double range);
setStep(double f)54     void setStep(double f) { _step = f; }
55     QSize sizeHint() const;
56     QSize minimumSizeHint() const;
57 
knobColor()58     const QColor& knobColor() const {
59         return _knobColor.isValid() ? _knobColor : palette().color(QPalette::ButtonText);
60     }
setKnobColor(const QColor & c)61     void setKnobColor(const QColor& c) {
62         _knobColor = c;
63         update();
64     }
65 
66 public Q_SLOTS:
67     void increment(double factor);
68     void decrement(double factor);
69 
70 Q_SIGNALS:
71     void action();
72 
73 private:
74     QRect thumbRect();
75     QRect valueRect();
76     double valueFromPos(const QPoint& pos);
77     void moveBy(double);
78     void increment();
79     void decrement();
80     void mouseMoveEvent(QMouseEvent*);
81     void mousePressEvent(QMouseEvent*);
82     void mouseReleaseEvent(QMouseEvent*);
83     void keyPressEvent(QKeyEvent*);
84     void paintEvent(QPaintEvent*);
85 
86     Qt::Orientation _ort;
87     double _lo;
88     double _hi;
89     double _step;
90     QPoint dragOrigin;
91     double dragVal, dragRange;
92     MouseMode mouseMode;
93 
94     QColor _knobColor;
95 };
96