Skip to content

Commit

Permalink
Zooming with mouse wheel center (#3835)
Browse files Browse the repository at this point in the history
* Horizontal mouse-wheel zooming. Ensure zoom center is always on the current mouse position.

* Horizontal zoom using mouse wheel center on the mouse position. For the SongEditor too.

* Wheel center on the Automation editor too.
  • Loading branch information
Premik authored and Umcaruje committed May 9, 2018
1 parent 82972ca commit e8b69b9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private slots:

bool m_scrollBack;
bool m_smoothScroll;
int m_widgetWidthTotal;

EditMode m_mode;
EditMode m_ctrlMode; // mode they were in before they hit ctrl
Expand Down
11 changes: 11 additions & 0 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,17 @@ void AutomationEditor::wheelEvent(QWheelEvent * we )
x--;
}
x = qBound( 0, x, m_zoomingXModel.size() - 1 );

int mouseX = (we->x() - VALUES_WIDTH)* MidiTime::ticksPerTact();
// ticks based on the mouse x-position where the scroll wheel was used
int ticks = mouseX / m_ppt;
// what would be the ticks in the new zoom level on the very same mouse x
int newTicks = mouseX / (DEFAULT_PPT * m_zoomXLevels[x]);

// scroll so the tick "selected" by the mouse x doesn't move on the screen
m_leftRightScroll->setValue(m_leftRightScroll->value() + ticks - newTicks);


m_zoomingXModel.setValue( x );
}
else if( we->modifiers() & Qt::ShiftModifier
Expand Down
8 changes: 8 additions & 0 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3296,6 +3296,14 @@ void PianoRoll::wheelEvent(QWheelEvent * we )
z--;
}
z = qBound( 0, z, m_zoomingModel.size() - 1 );

int x = (we->x() - WHITE_KEY_WIDTH)* MidiTime::ticksPerTact();
// ticks based on the mouse x-position where the scroll wheel was used
int ticks = x / m_ppt;
// what would be the ticks in the new zoom level on the very same mouse x
int newTicks = x / (DEFAULT_PR_PPT * m_zoomLevels[z]);
// scroll so the tick "selected" by the mouse x doesn't move on the screen
m_leftRightScroll->setValue(m_leftRightScroll->value() + ticks - newTicks);
// update combobox with zooming-factor
m_zoomingModel.setValue( z );
}
Expand Down
14 changes: 12 additions & 2 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ SongEditor::SongEditor( Song * song ) :
{
m_zoomingModel->setParent(this);
// create time-line
int widgetTotal = ConfigManager::inst()->value( "ui",
m_widgetWidthTotal = ConfigManager::inst()->value( "ui",
"compacttrackbuttons" ).toInt()==1 ?
DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + TRACK_OP_WIDTH_COMPACT :
DEFAULT_SETTINGS_WIDGET_WIDTH + TRACK_OP_WIDTH;
m_timeLine = new TimeLineWidget( widgetTotal, 32,
m_timeLine = new TimeLineWidget( m_widgetWidthTotal, 32,
pixelsPerTact(),
m_song->m_playPos[Song::Mode_PlaySong],
m_currentPosition,
Expand Down Expand Up @@ -385,6 +385,16 @@ void SongEditor::wheelEvent( QWheelEvent * we )
z--;
}
z = qBound( 0, z, m_zoomingModel->size() - 1 );


int x = (we->x() - m_widgetWidthTotal);
// tact based on the mouse x-position where the scroll wheel was used
int tact= x / pixelsPerTact();
// what would be the tact in the new zoom level on the very same mouse x
int newTact = x / DEFAULT_PIXELS_PER_TACT / m_zoomLevels[z];
// scroll so the tact "selected" by the mouse x doesn't move on the screen
m_leftRightScroll->setValue(m_leftRightScroll->value() + tact - newTact);

// update combobox with zooming-factor
m_zoomingModel->setValue( z );

Expand Down

0 comments on commit e8b69b9

Please sign in to comment.