Made 0.4.12 release
[lmms/mlankhorst.git] / include / knob.h
blob3e13dec641fa3549774734826144f54933de317f
1 /*
2 * knob.h - powerful knob-widget
4 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
26 #ifndef _KNOB_H
27 #define _KNOB_H
29 #include <QtGui/QWidget>
30 #include <QtCore/QPoint>
32 #include "AutomatableModelView.h"
33 #include "templates.h"
36 class QPixmap;
37 class textFloat;
40 enum knobTypes
42 knobDark_28, knobBright_26, knobSmall_17, knobGreen_17, knobStyled
43 } ;
47 class EXPORT knob : public QWidget, public FloatModelView
49 Q_OBJECT
50 Q_PROPERTY(float innerRadius READ innerRadius WRITE setInnerRadius)
51 Q_PROPERTY(float outerRadius READ outerRadius WRITE setOuterRadius)
53 Q_PROPERTY(float centerPointX READ centerPointX WRITE setCenterPointX)
54 Q_PROPERTY(float centerPointY READ centerPointY WRITE setCenterPointY)
56 Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth)
58 // Unfortunately, the gradient syntax doesn't create our gradient
59 // correctly so we need to do this:
60 Q_PROPERTY(QColor outerColor READ outerColor WRITE setOuterColor)
61 mapPropertyFromModel(bool,isVolumeKnob,setVolumeKnob,m_volumeKnob);
62 public:
63 knob( int _knob_num, QWidget * _parent, const QString & _name = QString() );
64 virtual ~knob();
66 // TODO: remove
67 inline void setHintText( const QString & _txt_before,
68 const QString & _txt_after )
70 setDescription( _txt_before );
71 setUnit( _txt_after );
73 void setLabel( const QString & _txt );
75 void setTotalAngle( float _angle );
77 // Begin styled knob accessors
78 float innerRadius() const;
79 void setInnerRadius( float _r );
81 float outerRadius() const;
82 void setOuterRadius( float _r );
84 QPointF centerPoint() const;
85 float centerPointX() const;
86 void setCenterPointX( float _c );
87 float centerPointY() const;
88 void setCenterPointY( float _c );
90 float lineWidth() const;
91 void setLineWidth( float _w );
93 QColor outerColor() const;
94 void setOuterColor( const QColor & _c );
97 signals:
98 void sliderPressed();
99 void sliderReleased();
100 void sliderMoved( float value );
103 protected:
104 virtual void contextMenuEvent( QContextMenuEvent * _me );
105 virtual void dragEnterEvent( QDragEnterEvent * _dee );
106 virtual void dropEvent( QDropEvent * _de );
107 virtual void focusOutEvent( QFocusEvent * _fe );
108 virtual void mousePressEvent( QMouseEvent * _me );
109 virtual void mouseReleaseEvent( QMouseEvent * _me );
110 virtual void mouseMoveEvent( QMouseEvent * _me );
111 virtual void mouseDoubleClickEvent( QMouseEvent * _me );
112 virtual void paintEvent( QPaintEvent * _me );
113 virtual void wheelEvent( QWheelEvent * _me );
115 private slots:
116 virtual void enterValue();
117 void displayHelp();
118 void friendlyUpdate();
121 private:
122 QString displayValue() const;
124 virtual void doConnections();
126 QLineF calculateLine( const QPointF & _mid, float _radius,
127 float _innerRadius = 1) const;
129 void drawKnob( QPainter * _p );
130 void setPosition( const QPoint & _p );
131 float getValue( const QPoint & _p );
132 bool updateAngle();
134 inline float pageSize() const
136 return( qMax<float>( ( model()->maxValue() -
137 model()->minValue() ) / 100.0f,
138 modelUntyped()->step<float>() ) );
142 static textFloat * s_textFloat;
144 int m_knobNum;
145 QString m_label;
147 QPixmap * m_knobPixmap;
148 BoolModel m_volumeKnob;
150 float m_mouseOffset;
151 QPoint m_origMousePos;
152 bool m_buttonPressed;
154 float m_totalAngle;
155 int m_angle;
156 QImage m_cache;
158 // Styled knob stuff, could break out
159 QPointF m_centerPoint;
160 float m_innerRadius;
161 float m_outerRadius;
162 float m_lineWidth;
163 QColor * m_outerColor;
167 #endif