From ea94e6aa322c5f7d888af0706d1c714253bcac0d Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Wed, 5 Jan 2011 12:31:24 +0100 Subject: [PATCH] SongEditor: added smooth autoscroll Instead of flipping to next page when the play position marker reaches the right edge, scroll to next page smoothly using the QTimeLine class. Closes #3144318. --- src/gui/song_editor.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/gui/song_editor.cpp b/src/gui/song_editor.cpp index 139928400..3e7ed2c65 100644 --- a/src/gui/song_editor.cpp +++ b/src/gui/song_editor.cpp @@ -22,6 +22,7 @@ * */ +#include #include #include #include @@ -649,6 +650,28 @@ void songEditor::updateScrollBar( int _len ) +static inline void animateScroll( QScrollBar *scrollBar, int newVal ) +{ + // do smooth scroll animation using QTimeLine + QTimeLine *t = scrollBar->findChild(); + if( t == NULL ) + { + t = new QTimeLine( 600, scrollBar ); + t->setFrameRange( scrollBar->value(), newVal ); + t->connect( t, SIGNAL( finished() ), SLOT( deleteLater() ) ); + + scrollBar->connect( t, SIGNAL( frameChanged( int ) ), SLOT( setValue( int ) ) ); + + t->start(); + } + else + { + // smooth scrolling is still active, therefore just update the end frame + t->setEndFrame( newVal ); + } +} + + void songEditor::updatePosition( const midiTime & _t ) { if( ( m_s->isPlaying() && m_s->m_playMode == song::Mode_PlaySong @@ -656,11 +679,12 @@ void songEditor::updatePosition( const midiTime & _t ) m_scrollBack == true ) { const int w = width() - DEFAULT_SETTINGS_WIDGET_WIDTH - - TRACK_OP_WIDTH; + - TRACK_OP_WIDTH + - 32; // rough estimation for width of right scrollbar if( _t > m_currentPosition + w * midiTime::ticksPerTact() / pixelsPerTact() ) { - m_leftRightScroll->setValue( _t.getTact() ); + animateScroll( m_leftRightScroll, _t.getTact() ); } else if( _t < m_currentPosition ) { @@ -668,7 +692,7 @@ void songEditor::updatePosition( const midiTime & _t ) (int)( _t - w * midiTime::ticksPerTact() / pixelsPerTact() ), 0 ); - m_leftRightScroll->setValue( t.getTact() ); + animateScroll( m_leftRightScroll, t.getTact() ); } m_scrollBack = false; }