Skip to content

Commit

Permalink
SongEditorPanel : clean up scroll signals
Browse files Browse the repository at this point in the history
protect against looping event
prepare the road to complete #584,
(update vertical position on add/remove pattern)
  • Loading branch information
jeremyz committed Jul 18, 2018
1 parent 33002d3 commit 42293e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
58 changes: 26 additions & 32 deletions src/gui/src/SongEditor/SongEditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ SongEditorPanel::SongEditorPanel(QWidget *pParent)

// ZOOM
m_pHScrollBar = new QScrollBar( Qt::Horizontal,NULL );
connect( m_pHScrollBar, SIGNAL(valueChanged(int)), this, SLOT( syncToExternalScrollBar() ) );
connect( m_pHScrollBar, SIGNAL(valueChanged(int)), this, SLOT( hScrollTo(int) ) );

// zoom-in btn
Button* pZoomInBtn = new Button(
Expand Down Expand Up @@ -275,7 +275,7 @@ SongEditorPanel::SongEditorPanel(QWidget *pParent)
m_pPatternListScrollView->setFixedWidth( m_nPatternListWidth );
m_pPatternListScrollView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
m_pPatternListScrollView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
connect( m_pPatternListScrollView->verticalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( on_patternListScroll() ) );
connect( m_pPatternListScrollView->verticalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( vScrollTo(int) ) );

m_pPatternList = new SongEditorPatternList( m_pPatternListScrollView->viewport() );
m_pPatternListScrollView->setWidget( m_pPatternList );
Expand All @@ -289,8 +289,8 @@ SongEditorPanel::SongEditorPanel(QWidget *pParent)
m_pSongEditor = new SongEditor( m_pEditorScrollView->viewport() );
m_pEditorScrollView->setWidget( m_pSongEditor );

connect( m_pEditorScrollView->horizontalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( on_EditorScroll() ) );
connect( m_pEditorScrollView->verticalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( on_EditorScroll() ) );
connect( m_pEditorScrollView->horizontalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( hScrollTo() ) );
connect( m_pEditorScrollView->verticalScrollBar(), SIGNAL( valueChanged(int) ), this, SLOT( vScrollTo(int) ) );


// POSITION RULER
Expand Down Expand Up @@ -333,7 +333,7 @@ SongEditorPanel::SongEditorPanel(QWidget *pParent)
m_pAutomationCombo->select( 0 );

m_pVScrollBar = new QScrollBar( Qt::Vertical, NULL );
connect( m_pVScrollBar, SIGNAL(valueChanged(int)), this, SLOT( syncToExternalScrollBar() ) );
connect( m_pVScrollBar, SIGNAL(valueChanged(int)), this, SLOT( vScrollTo(int) ) );


// ok...let's build the layout
Expand Down Expand Up @@ -399,13 +399,12 @@ void SongEditorPanel::updatePlayHeadPosition()

int nPlayHeadPosition = Hydrogen::get_instance()->getPatternPos() * m_pSongEditor->getGridWidth();

int value = m_pEditorScrollView->horizontalScrollBar()->value();
if ( nPlayHeadPosition > ( x + w - 50 ) ) {
m_pEditorScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() + 100 );
on_EditorScroll(); // force a re-sync
hScrollTo( value + 100 );
}
else if ( nPlayHeadPosition < x ) {
m_pEditorScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() - 100 );
on_EditorScroll(); // force a re-sync
hScrollTo( value - 100 );
}
}
}
Expand Down Expand Up @@ -449,35 +448,30 @@ void SongEditorPanel::updatePlaybackFaderPeaks()
}
}

void SongEditorPanel::on_patternListScroll()
void SongEditorPanel::vScrollTo( int value )
{
m_pEditorScrollView->verticalScrollBar()->setValue( m_pPatternListScrollView->verticalScrollBar()->value() );
}



///
/// Synchronize the patternlist with the patternsequence
///
void SongEditorPanel::on_EditorScroll()
{
resyncExternalScrollBar();
m_pPatternListScrollView->verticalScrollBar()->setValue( m_pEditorScrollView->verticalScrollBar()->value() );
m_pPositionRulerScrollView->horizontalScrollBar()->setValue( m_pEditorScrollView->horizontalScrollBar()->value() );
static bool inside = false;
if ( !inside ) {
inside = true;
m_pVScrollBar->setValue( value );
m_pPatternListScrollView->verticalScrollBar()->setValue( value );
m_pEditorScrollView->verticalScrollBar()->setValue( value );
inside = false;
}
}



void SongEditorPanel::syncToExternalScrollBar()
void SongEditorPanel::hScrollTo( int value )
{
m_pEditorScrollView->horizontalScrollBar()->setValue( m_pHScrollBar->value() );
m_pEditorScrollView->verticalScrollBar()->setValue( m_pVScrollBar->value() );
m_pAutomationPathScrollView->horizontalScrollBar()->setValue( m_pHScrollBar->value() );
m_pAutomationPathScrollView->verticalScrollBar()->setValue( m_pVScrollBar->value() );
static bool inside = false;
if ( !inside ) {
inside = true;
m_pHScrollBar->setValue( value );
m_pEditorScrollView->horizontalScrollBar()->setValue( value );
m_pAutomationPathScrollView->horizontalScrollBar()->setValue( value );
inside = false;
}
}



///
/// Update and redraw all...
///
Expand Down
5 changes: 2 additions & 3 deletions src/gui/src/SongEditor/SongEditorPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ class SongEditorPanel : public QWidget, public EventListener, public H2Core::Obj
void deletePattern( int idx );

private slots:
void on_patternListScroll();
void on_EditorScroll();
void syncToExternalScrollBar();
void vScrollTo( int value );
void hScrollTo( int value );

void newPatBtnClicked( Button* );
void upBtnClicked( Button* );
Expand Down

0 comments on commit 42293e2

Please sign in to comment.