From da2472b9ad3974bd227c25af750132df037c7384 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 21 Apr 2008 08:38:35 +0000 Subject: [PATCH] added fast and leightweight timer-framework - widgets requiring periodic updates can simply connect their update-slots to songEditor::periodicUpdate() git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@929 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/song_editor.h | 14 ++++++++++++-- src/gui/song_editor.cpp | 26 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/song_editor.h b/include/song_editor.h index 309b30daf..48fa00490 100644 --- a/include/song_editor.h +++ b/include/song_editor.h @@ -27,6 +27,8 @@ #ifndef _SONG_EDITOR_H #define _SONG_EDITOR_H +#include + #include "track_container_view.h" #include "lcd_spinbox.h" #include "automatable_slider.h" @@ -46,10 +48,14 @@ class songEditor : public trackContainerView { Q_OBJECT public: - songEditor( song * _song ); + songEditor( song * _song, songEditor * & _engine_ptr ); virtual ~songEditor(); +signals: + void periodicUpdate( void ); + + private slots: void scrolled( int _new_pos ); void updateTimeLinePosition( void ); @@ -70,8 +76,9 @@ private slots: private: virtual void keyPressEvent( QKeyEvent * _ke ); - virtual void wheelEvent( QWheelEvent * _we ); virtual void paintEvent( QPaintEvent * _pe ); + virtual void timerEvent( QTimerEvent * _ev ); + virtual void wheelEvent( QWheelEvent * _we ); virtual bool allowRubberband( void ) const; @@ -80,6 +87,9 @@ private: song * m_s; + QBasicTimer m_updateTimer; + + QScrollBar * m_leftRightScroll; QWidget * m_toolBar; diff --git a/src/gui/song_editor.cpp b/src/gui/song_editor.cpp index 8cbecbabe..7c08a64dd 100644 --- a/src/gui/song_editor.cpp +++ b/src/gui/song_editor.cpp @@ -80,11 +80,13 @@ -songEditor::songEditor( song * _song ) : +songEditor::songEditor( song * _song, songEditor * & _engine_ptr ) : trackContainerView( _song ), m_s( _song ), m_scrollBack( FALSE ) { + _engine_ptr = this; + setWindowTitle( tr( "Song-Editor" ) ); setWindowIcon( embed::getIconPixmap( "songeditor" ) ); @@ -371,6 +373,7 @@ songEditor::songEditor( song * _song ) : w->show(); + m_updateTimer.start( 1000 / 20, this ); // 20 fps } @@ -383,10 +386,10 @@ songEditor::~songEditor() -void songEditor::paintEvent( QPaintEvent * _pe ) +void songEditor::scrolled( int _new_pos ) { - m_leftRightScroll->setMaximum( m_s->length() ); - trackContainerView::paintEvent( _pe ); + update(); + emit positionChanged( m_currentPosition = midiTime( _new_pos, 0 ) ); } @@ -448,11 +451,18 @@ void songEditor::keyPressEvent( QKeyEvent * _ke ) - -void songEditor::scrolled( int _new_pos ) +void songEditor::paintEvent( QPaintEvent * _pe ) { - update(); - emit positionChanged( m_currentPosition = midiTime( _new_pos, 0 ) ); + m_leftRightScroll->setMaximum( m_s->length() ); + trackContainerView::paintEvent( _pe ); +} + + + + +void songEditor::timerEvent( QTimerEvent * ) +{ + emit periodicUpdate(); }