diff --git a/include/knob.h b/include/knob.h index e50431210..c2e6873f6 100644 --- a/include/knob.h +++ b/include/knob.h @@ -132,6 +132,11 @@ private: void setPosition( const QPoint & _p ); bool updateAngle(); + int angleFromValue( float value, float minValue, float maxValue, float totalAngle ) const + { + return static_cast( ( value - 0.5 * ( minValue + maxValue ) ) / ( maxValue - minValue ) * m_totalAngle ) % 360; + } + inline float pageSize() const { return( qMax( ( model()->maxValue() - diff --git a/src/gui/widgets/knob.cpp b/src/gui/widgets/knob.cpp index 7c7b9bc82..06feb0b03 100644 --- a/src/gui/widgets/knob.cpp +++ b/src/gui/widgets/knob.cpp @@ -255,11 +255,7 @@ bool knob::updateAngle() int angle = 0; if( model() && model()->maxValue() != model()->minValue() ) { - float a = ( model()->value() - 0.5 * ( model()->minValue() + - model()->maxValue() ) ) / - ( model()->maxValue() - model()->minValue() ) * - m_totalAngle; - angle = static_cast( a ) % 360; + angle = angleFromValue( model()->value(), model()->minValue(), model()->maxValue(), m_totalAngle ); } if( qAbs( angle - m_angle ) > 3 ) { @@ -328,6 +324,8 @@ void knob::drawKnob( QPainter * _p ) // p.setPen( QPen( QColor( 200, 0, 0 ), 2 ) ); p.setRenderHint( QPainter::Antialiasing ); + const int centerAngle = angleFromValue( model()->centerValue(), model()->minValue(), model()->maxValue(), m_totalAngle ); + switch( m_knobNum ) { case knobSmall_17: @@ -339,9 +337,9 @@ void knob::drawKnob( QPainter * _p ) } case knobBright_26: { - p.setPen( QPen( QApplication::palette().color( QPalette::Active, - QPalette::WindowText ), 2 ) ); + p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::WindowText ), 2 ) ); p.drawLine( calculateLine( mid, radius-5 ) ); + p.drawArc( 1, 1, width()-1-2*1, width()-1-2*1, (90-centerAngle)*16, -16*(m_angle-centerAngle) );//45*16-16*m_angle, 45*16 ); break; } case knobDark_28: