Skip to content

Commit

Permalink
Center vertical scroll position when opening the Automation Editor (L…
Browse files Browse the repository at this point in the history
…MMS#5123)

* Center vertical scroll position when opening the Automation Editor
  • Loading branch information
Veratil authored Aug 11, 2020
1 parent 5f24aab commit ff7b25b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ protected slots:
float m_bottomLevel;
float m_topLevel;

void centerTopBottomScroll();
void updateTopBottomLevels();

QScrollBar * m_leftRightScroll;
Expand Down
31 changes: 27 additions & 4 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void AutomationEditor::updateAfterPatternChange()
m_minLevel = m_pattern->firstObject()->minValue<float>();
m_maxLevel = m_pattern->firstObject()->maxValue<float>();
m_step = m_pattern->firstObject()->step<float>();
m_scrollLevel = ( m_minLevel + m_maxLevel ) / 2;
centerTopBottomScroll();

m_tensionModel->setValue( m_pattern->getTension() );

Expand Down Expand Up @@ -1595,12 +1595,36 @@ void AutomationEditor::drawLevelTick(QPainter & p, int tick, float value)

p.fillRect( x, y_start, rect_width, rect_height, currentColor );
}

#ifdef LMMS_DEBUG
else
{
printf("not in range\n");
}
#endif
}




// center the vertical scroll position on the first object's value
void AutomationEditor::centerTopBottomScroll()
{
// default to the m_scrollLevel position
int pos = static_cast<int>(m_scrollLevel);
// If a pattern exists...
if (m_pattern)
{
// get time map of current pattern
timeMap & time_map = m_pattern->getTimeMap();
// If time_map is not empty...
if (!time_map.empty())
{
// set the position to the inverted value ((max + min) - value)
// If we set just (max - value), we're off by m_pattern's minimum
pos = m_pattern->getMax() + m_pattern->getMin() - static_cast<int>(time_map.begin().value());
}
}
m_topBottomScroll->setValue(pos);
}


Expand Down Expand Up @@ -1632,8 +1656,7 @@ void AutomationEditor::resizeEvent(QResizeEvent * re)
m_topBottomScroll->setRange( (int) m_scrollLevel,
(int) m_scrollLevel );
}

m_topBottomScroll->setValue( (int) m_scrollLevel );
centerTopBottomScroll();

if( Engine::getSong() )
{
Expand Down

0 comments on commit ff7b25b

Please sign in to comment.