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.
29 #include <QtGui/QWidget>
30 #include <QtCore/QPoint>
32 #include "AutomatableModelView.h"
33 #include "templates.h"
42 knobDark_28
, knobBright_26
, knobSmall_17
, knobGreen_17
, knobStyled
47 class EXPORT knob
: public QWidget
, public FloatModelView
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
);
63 knob( int _knob_num
, QWidget
* _parent
, const QString
& _name
= QString() );
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
);
99 void sliderReleased();
100 void sliderMoved( float value
);
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
);
116 virtual void enterValue();
118 void friendlyUpdate();
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
);
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
;
147 QPixmap
* m_knobPixmap
;
148 BoolModel m_volumeKnob
;
151 QPoint m_origMousePos
;
152 bool m_buttonPressed
;
158 // Styled knob stuff, could break out
159 QPointF m_centerPoint
;
163 QColor
* m_outerColor
;