From ef77f21e6240c0fe305456db300b0b98e20abab1 Mon Sep 17 00:00:00 2001 From: Premik Date: Thu, 28 Sep 2017 12:52:59 +0200 Subject: [PATCH 1/3] Horizontal mouse-wheel zooming. Ensure zoom center is always on the current mouse position. --- src/gui/editors/PianoRoll.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 9b65c684798..f8e2026a6b9 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3289,6 +3289,14 @@ void PianoRoll::wheelEvent(QWheelEvent * we ) z--; } z = qBound( 0, z, m_zoomingModel.size() - 1 ); + + int x = (we->x() - WHITE_KEY_WIDTH); + // ticks based on the mouse x-position when the scroll wheel was used + int ticks = x * MidiTime::ticksPerTact() / m_ppt + m_currentPosition; + // what would be the ticks in the new zoom level on the very same mouse x + int newTicks = x * MidiTime::ticksPerTact() / DEFAULT_PR_PPT / m_zoomLevels[z] + m_currentPosition; + // 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 ); } From 70620be4cc4be4e5273d66daccb7fe1cae019871 Mon Sep 17 00:00:00 2001 From: Premik Date: Thu, 28 Sep 2017 18:18:03 +0200 Subject: [PATCH 2/3] Horizontal zoom using mouse wheel center on the mouse position. For the SongEditor too. --- include/SongEditor.h | 1 + src/gui/editors/PianoRoll.cpp | 8 ++++---- src/gui/editors/SongEditor.cpp | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index d6e904acecf..e31d0f862d8 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -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 diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index f8e2026a6b9..8238ab418d7 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -3290,11 +3290,11 @@ void PianoRoll::wheelEvent(QWheelEvent * we ) } z = qBound( 0, z, m_zoomingModel.size() - 1 ); - int x = (we->x() - WHITE_KEY_WIDTH); - // ticks based on the mouse x-position when the scroll wheel was used - int ticks = x * MidiTime::ticksPerTact() / m_ppt + m_currentPosition; + 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 * MidiTime::ticksPerTact() / DEFAULT_PR_PPT / m_zoomLevels[z] + m_currentPosition; + 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 diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index a0685444789..bc71bb2f709 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -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, this ); @@ -384,6 +384,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 ); From 44fa554ba5b6a2978b234901bf8e2a325afbe3db Mon Sep 17 00:00:00 2001 From: Premik Date: Sat, 30 Sep 2017 17:52:32 +0200 Subject: [PATCH 3/3] Wheel center on the Automation editor too. --- src/gui/editors/AutomationEditor.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index 1e94c1b50e7..674931715fc 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -1634,6 +1634,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