Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Center vertical scroll position when opening the Automation Editor #5123

Merged
merged 2 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -323,7 +323,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 @@ -1587,12 +1587,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 @@ -1624,8 +1648,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