Center vertical scroll position when opening the Automation Editor (#5123)
* Center vertical scroll position when opening the Automation Editor
This commit is contained in:
@@ -209,6 +209,7 @@ private:
|
||||
float m_bottomLevel;
|
||||
float m_topLevel;
|
||||
|
||||
void centerTopBottomScroll();
|
||||
void updateTopBottomLevels();
|
||||
|
||||
QScrollBar * m_leftRightScroll;
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user