Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / QtCollider / widgets / QcRangeSlider.h
blob3d1a42df9ee750e90dece0f25ae1a993be0abb55
1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
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 3 of the License, or
10 * (at your option) any later version.
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.
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/>.
20 ************************************************************************/
22 #ifndef QC_RANGE_SLIDER
23 #define QC_RANGE_SLIDER
25 #include "QcAbstractStepValue.h"
26 #include "../QcHelper.h"
27 #include "../style/style.hpp"
29 #include <QWidget>
31 class QcRangeSlider :
32 public QWidget, QcHelper, QcAbstractStepValue, QtCollider::Style::Client
34 Q_OBJECT
35 Q_PROPERTY( Qt::Orientation orientation
36 READ orientation WRITE setOrientation );
37 Q_PROPERTY( double loValue READ loValue WRITE setLoValue )
38 Q_PROPERTY( double hiValue READ hiValue WRITE setHiValue )
39 Q_PROPERTY( double shiftScale READ dummyFloat WRITE setShiftScale );
40 Q_PROPERTY( double ctrlScale READ dummyFloat WRITE setCtrlScale );
41 Q_PROPERTY( double altScale READ dummyFloat WRITE setAltScale );
42 Q_PROPERTY( double step READ dummyFloat WRITE setStep )
43 Q_PROPERTY( QColor grooveColor READ grooveColor WRITE setGrooveColor );
44 Q_PROPERTY( QColor focusColor READ focusColor WRITE setFocusColor );
45 Q_PROPERTY( QColor knobColor READ knobColor WRITE setKnobColor );
47 public:
48 enum MouseMode {
49 None = 0,
50 Move,
51 MoveHi,
52 MoveLo,
53 SetLo,
54 SetHi
57 QcRangeSlider();
58 Qt::Orientation orientation() const { return _ort; }
59 void setOrientation( Qt::Orientation o );
60 double loValue() const { return _lo; }
61 void setLoValue( double );
62 double hiValue() const { return _hi; }
63 void setHiValue( double );
64 void setRange( double val, double range );
65 void setStep( double f ) { _step = f; }
66 QSize sizeHint() const;
67 QSize minimumSizeHint() const;
69 const QColor & knobColor() const
70 { return _knobColor.isValid() ? _knobColor : palette().color(QPalette::ButtonText); }
71 void setKnobColor(const QColor &c) { _knobColor = c; update(); }
73 public Q_SLOTS:
74 void increment( double factor );
75 void decrement( double factor );
77 Q_SIGNALS:
78 void action();
80 private:
81 QRect thumbRect();
82 QRect valueRect();
83 double valueFromPos( const QPoint& pos );
84 void moveBy( double );
85 void increment();
86 void decrement();
87 void mouseMoveEvent ( QMouseEvent * );
88 void mousePressEvent ( QMouseEvent * );
89 void mouseReleaseEvent ( QMouseEvent * );
90 void keyPressEvent ( QKeyEvent * );
91 void paintEvent ( QPaintEvent * );
93 Qt::Orientation _ort;
94 double _lo;
95 double _hi;
96 double _step;
97 QPoint dragOrigin;
98 double dragVal, dragRange;
99 MouseMode mouseMode;
101 QColor _knobColor;
104 #endif