1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //  $Id: ./muse/widgets/knob.h $
5 //
6 //  Copyright (C) 1999-2011 by Werner Schweer and others
7 //  (C) Copyright 2011 Orcan Ogetbil (ogetbilo at sf.net) completely redesigned.
8 //
9 //  This program is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU General Public License
11 //  as published by the Free Software Foundation; version 2 of
12 //  the License, or (at your option) any later version.
13 //
14 //  This program is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 //  GNU General Public License for more details.
18 //
19 //  You should have received a copy of the GNU General Public License
20 //  along with this program; if not, write to the Free Software
21 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 //
23 //=========================================================
24 #ifndef QWT_KNOB_H
25 #define QWT_KNOB_H
26 
27 #include "sliderbase.h"
28 #include "sclif.h"
29 #include <QColor>
30 #include <QResizeEvent>
31 #include <QPaintEvent>
32 
33 namespace MusEGui {
34 
35 //---------------------------------------------------------
36 //   Knob
37 //---------------------------------------------------------
38 
39 class Knob : public SliderBase, public ScaleIf
40       {
41   Q_OBJECT
42 
43    public:
44       enum Symbol { Line, Dot };
45 
46       enum KnobType {
47           panType,
48           auxType,
49           gainType,
50       };
51 
52    protected:
53       bool hasScale;
54 
55       int d_borderWidth;
56       int d_shineWidth;
57       int d_scaleDist;
58       int d_maxScaleTicks;
59       int d_newVal;
60       int d_knobWidth;
61       int d_dotWidth;
62 
63       Symbol d_symbol;
64       double d_angle;
65       double d_oldAngle;
66       double d_totalAngle;
67       double d_nTurns;
68 
69       double l_const;
70       double l_slope;
71 
72       QRect  kRect;
73       bool _faceColSel;
74       QColor d_faceColor;
75       QColor d_shinyColor;
76       QColor d_rimColor;
77       QColor d_curFaceColor;
78       QColor d_altFaceColor;
79       QColor d_markerColor;
80 
81       void recalcAngle();
82       void valueChange();
83       void rangeChange();
84       virtual void drawKnob(QPainter *p, const QRect &r);
85       void drawMarker(QPainter *p, double arc, const QColor &c);
86 
87       virtual void paintEvent(QPaintEvent *);
88       virtual void resizeEvent(QResizeEvent *e);
89       double getValue(const QPoint &p);
90       //  Determine the value corresponding to a specified mouse movement.
91       double moveValue(const QPoint& /*deltaP*/, bool /*fineMode*/ = false);
92       void getScrollMode( QPoint &p, const Qt::MouseButton &button, const Qt::KeyboardModifiers& modifiers, int &scrollMode, int &direction );
scaleChange()93       void scaleChange()             { repaint(); }
fontChange(const QFont &)94       void fontChange(const QFont &) { repaint(); }
95 
96    public:
97       Knob(QWidget* parent = 0, const char *name = 0);
~Knob()98       ~Knob() {}
99 
100       void setRange(double vmin, double vmax, double vstep = 0.0,
101 		    int pagesize = 1);
102       void setKnobWidth(int w);
103       void setTotalAngle (double angle);
104       void setBorderWidth(int bw);
105       void selectFaceColor(bool alt);
selectedFaceColor()106       bool selectedFaceColor() { return _faceColSel; }
faceColor()107       QColor faceColor() { return d_faceColor; }
108       void setFaceColor(const QColor c);
altFaceColor()109       QColor altFaceColor() { return d_altFaceColor; }
110       void setAltFaceColor(const QColor c);
markerColor()111       QColor markerColor() { return d_markerColor; }
112       void setMarkerColor(const QColor c);
113       };
114 
115 } // namespace MusEGui
116 
117 #endif
118