Skip to content

Commit

Permalink
Adding proportional scrolling (#7476)
Browse files Browse the repository at this point in the history
Add proportional scrolling to the song editor, piano roll and automation editor. Proportional scrolling means that if for example a certain measure is on the right side of the song editor then it will take a certain number of mouse wheel moves to get it to the left side of the editor. It is the same number of wheel moves regardless of the zoom level.
  • Loading branch information
regulus79 authored Oct 6, 2024
1 parent 0363ee6 commit 7dbc809
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ protected slots:
QScrollBar * m_leftRightScroll;
QScrollBar * m_topBottomScroll;

void adjustLeftRightScoll(int value);

TimePos m_currentPosition;

Action m_action;
Expand Down
2 changes: 2 additions & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ protected slots:
QScrollBar * m_leftRightScroll;
QScrollBar * m_topBottomScroll;

void adjustLeftRightScoll(int value);

TimePos m_currentPosition;
bool m_recording;
bool m_doAutoQuantization{false};
Expand Down
2 changes: 2 additions & 0 deletions include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private slots:

QScrollBar * m_leftRightScroll;

void adjustLeftRightScoll(int value);

LcdSpinBox * m_tempoSpinBox;

TimeLineWidget * m_timeLine;
Expand Down
12 changes: 7 additions & 5 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,11 @@ void AutomationEditor::resizeEvent(QResizeEvent * re)
update();
}


void AutomationEditor::adjustLeftRightScoll(int value)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
value * 0.3f / m_zoomXLevels[m_zoomingXModel.value()]);
}


// TODO: Move this method up so it's closer to the other mouse events
Expand Down Expand Up @@ -1625,13 +1629,11 @@ void AutomationEditor::wheelEvent(QWheelEvent * we )
// FIXME: Reconsider if determining orientation is necessary in Qt6.
else if(abs(we->angleDelta().x()) > abs(we->angleDelta().y())) // scrolling is horizontal
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().x() * 2 / 15);
adjustLeftRightScoll(we->angleDelta().x());
}
else if(we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().y() * 2 / 15);
adjustLeftRightScoll(we->angleDelta().y());
}
else
{
Expand Down
12 changes: 8 additions & 4 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,12 @@ void PianoRoll::resizeEvent(QResizeEvent* re)
}


void PianoRoll::adjustLeftRightScoll(int value)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
value * 0.3f / m_zoomLevels[m_zoomingModel.value()]);
}



void PianoRoll::wheelEvent(QWheelEvent * we )
Expand Down Expand Up @@ -3875,13 +3881,11 @@ void PianoRoll::wheelEvent(QWheelEvent * we )
// FIXME: Reconsider if determining orientation is necessary in Qt6.
else if(abs(we->angleDelta().x()) > abs(we->angleDelta().y())) // scrolling is horizontal
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().x() * 2 / 15);
adjustLeftRightScoll(we->angleDelta().x());
}
else if(we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().y() * 2 / 15);
adjustLeftRightScoll(we->angleDelta().y());
}
else
{
Expand Down
12 changes: 8 additions & 4 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ void SongEditor::keyPressEvent( QKeyEvent * ke )



void SongEditor::adjustLeftRightScoll(int value)
{
m_leftRightScroll->setValue(m_leftRightScroll->value()
- value * DEFAULT_PIXELS_PER_BAR / pixelsPerBar());
}


void SongEditor::wheelEvent( QWheelEvent * we )
{
Expand Down Expand Up @@ -544,13 +550,11 @@ void SongEditor::wheelEvent( QWheelEvent * we )
// FIXME: Reconsider if determining orientation is necessary in Qt6.
else if (std::abs(we->angleDelta().x()) > std::abs(we->angleDelta().y())) // scrolling is horizontal
{
m_leftRightScroll->setValue(m_leftRightScroll->value()
- we->angleDelta().x());
adjustLeftRightScoll(we->angleDelta().x());
}
else if (we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value()
- we->angleDelta().y());
adjustLeftRightScoll(we->angleDelta().y());
}
else
{
Expand Down

0 comments on commit 7dbc809

Please sign in to comment.