1 // qsynthKnob.h
2 //
3 /****************************************************************************
4    Copyright (C) 2005-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5 
6    This widget is based on a design by Thorsten Wilms,
7    implemented by Chris Cannam in Rosegarden,
8    adapted for QSynth by Pedro Lopez-Cabanillas
9 
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License
12    as published by the Free Software Foundation; either version 2
13    of the License, or (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License along
21    with this program; if not, write to the Free Software Foundation, Inc.,
22    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24 *****************************************************************************/
25 
26 #ifndef __qsynthKnob_h
27 #define __qsynthKnob_h
28 
29 #include <QDial>
30 
31 
32 //-------------------------------------------------------------------------
33 // qsynthKnob - A better QDial for everybody
34 
35 class qsynthKnob : public QDial
36 {
37 	Q_OBJECT
38 	Q_PROPERTY(int defaultValue READ getDefaultValue WRITE setDefaultValue)
39 	Q_PROPERTY(DialMode dialMode READ getDialMode WRITE setDialMode)
40 	Q_ENUMS(DialMode)
41 
42 public:
43 
44 	// Constructor.
45 	qsynthKnob(QWidget *pParent = 0);
46 	// Destructor.
47 	~qsynthKnob();
48 
getDefaultValue()49 	int getDefaultValue() const { return m_iDefaultValue; }
50 
51 	// Knob dial mode behavior:
52 	// DefaultMode - default (old) QDial behavior.
53 	// AngularMode - angularly relative to widget center.
54 	// LinearMode  - proportionally to distance in one ortogonal axis.
55 
56 	enum DialMode { DefaultMode, AngularMode, LinearMode };
57 
getDialMode()58 	DialMode getDialMode() const { return m_dialMode; }
59 
60 public slots:
61 
62 	// Set default (mid) value.
63 	void setDefaultValue(int iDefaultValue);
64 
65 	// Set knob dial mode behavior.
66 	void setDialMode(DialMode dialMode);
67 
68 protected:
69 
70 	// Mouse angle determination.
71 	float mouseAngle(const QPoint& pos);
72 
73 	// Alternate mouse behavior event handlers.
74 	virtual void mousePressEvent(QMouseEvent *pMouseEvent);
75 	virtual void mouseMoveEvent(QMouseEvent *pMouseEvent);
76 	virtual void mouseReleaseEvent(QMouseEvent *pMouseEvent);
77 	virtual void wheelEvent(QWheelEvent *pWheelEvent);
78 
79 private:
80 
81 	// Default (mid) value.
82 	int m_iDefaultValue;
83 
84 	// Knob dial mode behavior.
85 	DialMode m_dialMode;
86 
87 	// Alternate mouse behavior tracking.
88 	bool   m_bMousePressed;
89 	QPoint m_posMouse;
90 
91 	// Just for more precission on the movement
92 	float m_fLastDragValue;
93 };
94 
95 
96 #endif  // __qsynthKnob_h
97 
98 // end of qsynthKnob.h
99