From 2ee02d97cba4ce9275ff0e830236ea7f3d68fbf3 Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Sun, 6 Jan 2019 19:21:35 +0900 Subject: [PATCH] Keep off-grid position of TCOs on group moving (#4262) --- src/core/Track.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index bf10a10a0ce..b300d94a347 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -865,10 +865,18 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) else if( m_action == MoveSelection ) { const int dx = me->x() - m_initialMousePos.x(); + const bool snap = !(me->modifiers() & Qt::AltModifier) && + me->button() == Qt::NoButton; QVector so = m_trackView->trackContainerView()->selectedObjects(); QVector tcos; - MidiTime smallest_pos, t; + int smallestPos = 0; + MidiTime dtick = MidiTime( static_cast( dx * + MidiTime::ticksPerTact() / ppt ) ); + if( snap ) + { + dtick = dtick.toNearestTact(); + } // find out smallest position of all selected objects for not // moving an object before zero for( QVector::iterator it = so.begin(); @@ -882,23 +890,18 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) } TrackContentObject * tco = tcov->m_tco; tcos.push_back( tco ); - smallest_pos = qMin( smallest_pos, - (int)tco->startPosition() + - static_cast( dx * - MidiTime::ticksPerTact() / ppt ) ); + smallestPos = qMin( smallestPos, + (int)tco->startPosition() + dtick ); + } + dtick -= smallestPos; + if( snap ) + { + dtick = dtick.toAbsoluteTact(); // round toward 0 } for( QVector::iterator it = tcos.begin(); it != tcos.end(); ++it ) { - t = ( *it )->startPosition() + - static_cast( dx *MidiTime::ticksPerTact() / - ppt )-smallest_pos; - if( ! ( me->modifiers() & Qt::AltModifier ) - && me->button() == Qt::NoButton ) - { - t = t.toNearestTact(); - } - ( *it )->movePosition( t ); + ( *it )->movePosition( ( *it )->startPosition() + dtick ); } } else if( m_action == Resize )