From 8d5e2742698a9d79f488a4078cd1392dc4191f68 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 14 Mar 2006 14:18:30 +0000 Subject: [PATCH] bugfixes git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@105 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 15 +++++ include/automatable_button.h | 10 ++- include/automatable_object.h | 46 ++++++++----- include/knob.h | 2 +- src/widgets/automatable_button.cpp | 8 +-- src/widgets/group_box.cpp | 1 + src/widgets/knob.cpp | 101 +---------------------------- src/widgets/lcd_spinbox.cpp | 6 +- 8 files changed, 63 insertions(+), 126 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fc04bdcd..36b801057 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-03-14 Tobias Doerffel + + * include/automatable_object.h: + * include/automatable_button.h: + * include/knob.h: + * src/widgets/automatable_button.cpp: + * src/widgets/knob.cpp: + added second template-parameter to automatableObject which specifies + the type to be used for internal calculations (neccessary for working + undo/redo-implementation for bool-objects like buttons) + + * include/led_checkbox.h: + * src/widgets/led_checkbox.cpp: + fixed some bugs + 2006-03-13 Tobias Doerffel * include/main_window.h: diff --git a/include/automatable_button.h b/include/automatable_button.h index def1d6d21..ab483bbd3 100755 --- a/include/automatable_button.h +++ b/include/automatable_button.h @@ -45,7 +45,8 @@ class automatableButtonGroup; -class automatableButton : public QWidget, public automatableObject +class automatableButton : public QWidget, public automatableObject { Q_OBJECT public: @@ -58,6 +59,8 @@ public: return( value() ); } + virtual void setValue( const bool _on ); + inline void setToggleButton( bool _on ) { m_toggleButton = _on; @@ -67,7 +70,10 @@ public: public slots: virtual void toggle( void ); - virtual void setChecked( bool _on ); + virtual void setChecked( bool _on ) + { + setValue( _on ); + } protected: diff --git a/include/automatable_object.h b/include/automatable_object.h index 703b1f17f..2b54c3dfc 100755 --- a/include/automatable_object.h +++ b/include/automatable_object.h @@ -32,10 +32,12 @@ #include "templates.h" -template +template class automatableObject : public editableObject { public: + typedef automatableObject autoObj; + automatableObject( engine * _engine, const T _val = 0, const T _min = 0, const T _max = 0, const T _step = defaultRelStep() ) : @@ -139,21 +141,27 @@ public: if( old_val != m_value ) { // add changes to history so user can undo it - addStep( editStep( 0, m_value - old_val ) ); + addStep( editStep( 0, static_cast( + m_value ) - + static_cast( + old_val ) ) ); // notify linked objects // doesn't work because of implicit typename T - // for( autoObjVector::iterator it = m_linkedObjects.begin(); - // it != m_linkedObjects.end(); ++it ) + // for( autoObjVector::iterator it = + // m_linkedObjects.begin(); + // it != m_linkedObjects.end(); ++it ) for( csize i = 0; i < m_linkedObjects.size(); ++i ) { - automatableObject * it = m_linkedObjects[i]; + autoObj * it = m_linkedObjects[i]; if( value() != it->value() && - it->fittedValue( value() ) != it->value() ) + it->fittedValue( value() ) != + it->value() ) { const bool sr = it->isRecordingSteps(); - it->setStepRecording( isRecordingSteps() ); + it->setStepRecording( + isRecordingSteps() ); it->setValue( value() ); it->setStepRecording( sr ); } @@ -177,7 +185,7 @@ public: qSwap( m_minValue, m_maxValue ); } // re-adjust value - automatableObject::setInitValue( value() ); + autoObj::setInitValue( value() ); } inline virtual void setStep( const T _step ) @@ -209,7 +217,7 @@ public: m_step = _step; } - inline void linkObject( automatableObject * _object ) + inline void linkObject( autoObj * _object ) { if( qFind( m_linkedObjects.begin(), m_linkedObjects.end(), _object ) == m_linkedObjects.end() ) @@ -218,15 +226,15 @@ public: } } - inline void unlinkObject( automatableObject * _object ) + inline void unlinkObject( autoObj * _object ) { m_linkedObjects.erase( qFind( m_linkedObjects.begin(), m_linkedObjects.end(), _object ) ); } - static inline void linkObjects( automatableObject * _object1, - automatableObject * _object2 ) + static inline void linkObjects( autoObj * _object1, + autoObj * _object2 ) { _object1->linkObject( _object2 ); _object2->linkObject( _object1 ); @@ -239,10 +247,11 @@ protected: const bool sr = isRecordingSteps(); setStepRecording( FALSE ); #ifndef QT3 - setValue( value() + _edit_step.data().value() ); + setValue( static_cast( value() + + _edit_step.data().value() ) ); #else - setValue( value() + static_cast( - _edit_step.data().toDouble() ) ); + setValue( static_cast( value() + static_cast( + _edit_step.data().toDouble() ) ) ); #endif setStepRecording( sr ); } @@ -251,10 +260,11 @@ protected: { #ifndef QT3 redoStep( editStep( _edit_step.actionID(), - -_edit_step.data().value() ) ); + -_edit_step.data().value() ) ); #else redoStep( editStep( _edit_step.actionID(), - static_cast( -_edit_step.data().toDouble() ) ) ); + static_cast( + -_edit_step.data().toDouble() ) ) ); #endif } @@ -273,7 +283,7 @@ private: T m_maxValue; T m_step; - typedef vvector *> autoObjVector; + typedef vvector autoObjVector; autoObjVector m_linkedObjects; } ; diff --git a/include/knob.h b/include/knob.h index 837aa7228..c904d56f1 100644 --- a/include/knob.h +++ b/include/knob.h @@ -77,7 +77,7 @@ public: inline virtual void setInitValue( const float _val ) { m_initValue = _val; - automatableObject::setInitValue( _val ); + autoObj::setInitValue( _val ); } virtual void setValue( const float _x ); diff --git a/src/widgets/automatable_button.cpp b/src/widgets/automatable_button.cpp index 76b092f8a..9585771ae 100644 --- a/src/widgets/automatable_button.cpp +++ b/src/widgets/automatable_button.cpp @@ -31,7 +31,7 @@ automatableButton::automatableButton( QWidget * _parent, engine * _engine ) : QWidget( _parent ), - automatableObject( _engine, FALSE, TRUE, FALSE ), + autoObj( _engine, FALSE, TRUE, FALSE ), m_group( NULL ), m_toggleButton( FALSE ) { @@ -106,11 +106,11 @@ void automatableButton::toggle( void ) -void automatableButton::setChecked( bool _on ) +void automatableButton::setValue( const bool _on ) { - if( _on != isChecked() ) + if( _on != value() ) { - setValue( _on ); + autoObj::setValue( _on ); update(); emit( toggled( value() ) ); } diff --git a/src/widgets/group_box.cpp b/src/widgets/group_box.cpp index 73d4ba8fd..bd05f1162 100644 --- a/src/widgets/group_box.cpp +++ b/src/widgets/group_box.cpp @@ -74,6 +74,7 @@ groupBox::groupBox( const QString & _caption, QWidget * _parent, updatePixmap(); m_led = new pixmapButton( this, eng() ); + m_led->setToggleButton( TRUE ); m_led->move( 2, 3 ); m_led->setActiveGraphic( embed::getIconPixmap( "led_green" ) ); m_led->setInactiveGraphic( embed::getIconPixmap( "led_off" ) ); diff --git a/src/widgets/knob.cpp b/src/widgets/knob.cpp index c62c37b54..433ddb0d2 100644 --- a/src/widgets/knob.cpp +++ b/src/widgets/knob.cpp @@ -94,7 +94,7 @@ knob::knob( int _knob_num, QWidget * _parent, const QString & _name, , _name.ascii() #endif ), - automatableObject( _engine ), + autoObj( _engine ), m_mouseOffset( 0.0f ), m_buttonPressed( FALSE ), m_angle( 0.0f ), @@ -606,7 +606,7 @@ void knob::setPosition( const QPoint & _p ) void knob::setValue( const float _x ) { const float prev_value = value(); - automatableObject::setValue( _x ); + autoObj::setValue( _x ); if( prev_value != value() ) { valueChange(); @@ -614,27 +614,12 @@ void knob::setValue( const float _x ) } -/* -void knob::fitValue( float _val ) -{ - setValue( _val ); -} - - - - -void knob::incValue( int _steps ) -{ - setValue( m_value + float( _steps ) * m_step ); -} -*/ - void knob::setRange( const float _min, const float _max, const float _step ) { bool rchg = ( ( maxValue() != _max ) || ( minValue() != _min ) ); - automatableObject::setRange( _min, _max, _step ); + autoObj::setRange( _min, _max, _step ); m_pageSize = tMax( ( maxValue() - minValue() ) / 100.0f, step() ); @@ -646,86 +631,6 @@ void knob::setRange( const float _min, const float _max, const float _step ) } } -/* - - -void knob::setNewValue( float _x, bool _align ) -{ - m_prevValue = m_value; - - m_value = tLimit( _x, m_minValue, m_maxValue ); - - m_exactPrevValue = m_exactValue; - m_exactValue = m_value; - - // align to grid - if( _align ) - { - if( m_step != 0.0 ) - { - m_value = floorf( m_value / m_step ) * m_step; - } - else - { - m_value = m_minValue; - } - - // correct rounding error at the border - if( tAbs( m_value - m_maxValue ) < MinEps * - tAbs( m_step ) ) - { - m_value = m_maxValue; - } - - // correct rounding error if value = 0 - if( tAbs( m_value ) < MinEps * tAbs( m_step ) ) - { - m_value = 0.0; - } - } - - if( m_prevValue != m_value ) - { - valueChange(); - } -} - - - - -void knob::setStep( float _vstep ) -{ - float intv = m_maxValue - m_minValue; - - float newStep; - - if( _vstep == 0.0 ) - { - newStep = intv * DefaultRelStep; - } - else - { - if( ( intv > 0 ) && ( _vstep < 0 ) || ( intv < 0 ) && - ( _vstep > 0 ) ) - { - newStep = -_vstep; - } - else - { - newStep = _vstep; - } - if( tAbs( newStep ) < - tAbs( MinRelStep * intv ) ) - { - newStep = MinRelStep * intv; - } - } - if( newStep != m_step ) - { - m_step = newStep; - } -} -*/ diff --git a/src/widgets/lcd_spinbox.cpp b/src/widgets/lcd_spinbox.cpp index 3691149c8..06835b4d8 100644 --- a/src/widgets/lcd_spinbox.cpp +++ b/src/widgets/lcd_spinbox.cpp @@ -51,7 +51,7 @@ lcdSpinBox::lcdSpinBox( int _min, int _max, int _num_digits, QWidget * _parent, engine * _engine ) : QWidget( _parent ), - automatableObject( _engine, 0, _min, _max ), + autoObj( _engine, 0, _min, _max ), m_label( NULL ), m_origMousePos() { @@ -80,7 +80,7 @@ lcdSpinBox::~lcdSpinBox() void lcdSpinBox::setStep( const int _step ) { - automatableObject::setStep( tMax( _step, 1 ) ); + autoObj::setStep( tMax( _step, 1 ) ); } @@ -88,7 +88,7 @@ void lcdSpinBox::setStep( const int _step ) void lcdSpinBox::setValue( const int _value ) { - automatableObject::setValue( _value ); + autoObj::setValue( _value ); QString s = m_textForValue[value()]; if( s == "" ) {