int SegmentMover::mouseMoveEvent(QMouseEvent *e) { // No need to propagate. e->accept(); // If we aren't moving anything, bail. if (!getChangingSegment()) return RosegardenScrollView::NoFollow; QPoint pos = m_canvas->viewportToContents(e->pos()); setSnapTime(e, SnapGrid::SnapToBeat); // If shift isn't being held down if ((e->modifiers() & Qt::ShiftModifier) == 0) { setContextHelp(tr("Hold Shift to avoid snapping to beat grid")); } else { clearContextHelp(); } const SnapGrid &grid = m_canvas->grid(); // Compute how far we've moved vertically. const int startTrackPos = grid.getYBin(m_clickPoint.y()); const int currentTrackPos = grid.getYBin(pos.y()); const int deltaTrack = currentTrackPos - startTrackPos; const int dx = pos.x() - m_clickPoint.x(); Composition &comp = m_doc->getComposition(); CompositionModelImpl::ChangingSegmentSet &changingSegments = m_canvas->getModel()->getChangingSegments(); // For each changing segment, move it for (CompositionModelImpl::ChangingSegmentSet::iterator it = changingSegments.begin(); it != changingSegments.end(); ++it) { ChangingSegmentPtr changingSegment = *it; const timeT newStartTime = grid.snapX(changingSegment->savedRect().x() + dx); const int newX = int(grid.getRulerScale()->getXForTime(newStartTime)); int trackPos = grid.getYBin(changingSegment->savedRect().y()) + deltaTrack; if (trackPos < 0) trackPos = 0; if (trackPos >= (int)comp.getNbTracks()) trackPos = comp.getNbTracks() - 1; const int newY = grid.getYBinCoordinate(trackPos); changingSegment->moveTo(newX, newY); m_changeMade = true; } if (m_changeMade) { // Make sure the segments are redrawn. m_canvas->slotUpdateAll(); } // Draw the guides int guideX = getChangingSegment()->rect().x(); int guideY = getChangingSegment()->rect().y(); m_canvas->drawGuides(guideX, guideY); // Format and draw the text float timeT guideTime = grid.snapX(guideX); RealTime time = comp.getElapsedRealTime(guideTime); int bar, beat, fraction, remainder; comp.getMusicalTimeForAbsoluteTime(guideTime, bar, beat, fraction, remainder); QString timeString = QString("%1.%2s (%3, %4, %5)") .arg(time.sec).arg(time.msec(), 3, 10, QChar('0')) .arg(bar + 1).arg(beat).arg(fraction); m_canvas->drawTextFloat(guideX + 10, guideY - 30, timeString); m_canvas->update(); return RosegardenScrollView::FollowHorizontal | RosegardenScrollView::FollowVertical; }
int SegmentSelector::mouseMoveEvent(QMouseEvent *e) { // No need to propagate. e->accept(); QPoint pos = m_canvas->viewportToContents(e->pos()); m_lastMousePos = pos; // If no buttons are pressed, update the context help and bail. // Note: Mouse tracking must be on for this to work. See // QWidget::setMouseTracking(). if (e->buttons() == Qt::NoButton) { setContextHelpFor(pos, e->modifiers()); return RosegardenScrollView::NoFollow; } // If another tool has taken over, delegate. if (m_dispatchTool) return m_dispatchTool->mouseMoveEvent(e); // We only handle the left button. The middle button is handled by // the dispatch tool (segment pencil) or ignored. if (e->buttons() != Qt::LeftButton) return RosegardenScrollView::NoFollow; // If we aren't moving anything, rubber band. if (!getChangingSegment()) { m_canvas->drawSelectionRectPos2(pos); m_canvas->getModel()->selectionHasChanged(); return RosegardenScrollView::FollowHorizontal | RosegardenScrollView::FollowVertical; } // Moving // If the segment that was clicked on isn't selected, bail. if (!m_canvas->getModel()->isSelected(getChangingSegment()->getSegment())) return RosegardenScrollView::NoFollow; const int dx = pos.x() - m_clickPoint.x(); const int dy = pos.y() - m_clickPoint.y(); const int inertiaDistance = 8; // If we've not already exceeded the inertia distance, and we // still haven't, bail. if (!m_passedInertiaEdge && abs(dx) < inertiaDistance && abs(dy) < inertiaDistance) { return RosegardenScrollView::NoFollow; } m_passedInertiaEdge = true; m_canvas->viewport()->setCursor(Qt::SizeAllCursor); #if 0 // ??? Moving to mouseReleaseEvent(). if (m_segmentCopyMode && !m_segmentQuickCopyDone) { // Make copies of the original Segment(s). These copies will // take the place of the originals as the user drags the // the originals to a new location. MacroCommand *macroCommand = 0; if (m_segmentCopyingAsLink) { macroCommand = new MacroCommand( SegmentQuickLinkCommand::getGlobalName()); } else { macroCommand = new MacroCommand( SegmentQuickCopyCommand::getGlobalName()); } SegmentSelection selectedItems = m_canvas->getSelectedSegments(); // for each selected segment for (SegmentSelection::iterator it = selectedItems.begin(); it != selectedItems.end(); ++it) { Segment *segment = *it; Command *command = 0; if (m_segmentCopyingAsLink) { command = new SegmentQuickLinkCommand(segment); } else { // if it's a link, copy as link if (segment->isTrulyLinked()) command = new SegmentQuickLinkCommand(segment); else // copy as a non-link segment command = new SegmentQuickCopyCommand(segment); } macroCommand->addCommand(command); } CommandHistory::getInstance()->addCommand(macroCommand); m_canvas->update(); // Make sure we don't do it again. m_segmentQuickCopyDone = true; } #endif setSnapTime(e, SnapGrid::SnapToBeat); // start move on selected items only once if (!m_selectionMoveStarted) { m_selectionMoveStarted = true; m_canvas->getModel()->startChangeSelection( m_segmentCopyMode ? CompositionModelImpl::ChangeCopy : CompositionModelImpl::ChangeMove); // The call to startChangeSelection() generates a new changing segment. // Get it. ChangingSegmentPtr newChangingSegment = m_canvas->getModel()->findChangingSegment( getChangingSegment()->getSegment()); if (newChangingSegment) { // Toss the local "changing" segment since it isn't going to // be moving at all. Swap it for the same changing segment in // CompositionModelImpl. That one *will* be moving and can be // used to drive the guides. setChangingSegment(newChangingSegment); } } // Display help for the Shift key. setContextHelpFor(pos, e->modifiers()); Composition &comp = m_doc->getComposition(); const int startDragTrackPos = m_canvas->grid().getYBin(m_clickPoint.y()); const int currentTrackPos = m_canvas->grid().getYBin(pos.y()); const int trackDiff = currentTrackPos - startDragTrackPos; CompositionModelImpl::ChangingSegmentSet &changingSegments = m_canvas->getModel()->getChangingSegments(); // For each changing segment for (CompositionModelImpl::ChangingSegmentSet::iterator it = changingSegments.begin(); it != changingSegments.end(); ++it) { ChangingSegmentPtr changingSegment = *it; const timeT newStartTime = m_canvas->grid().snapX( changingSegment->savedRect().x() + dx); const int newX = lround( m_canvas->grid().getRulerScale()->getXForTime(newStartTime)); int newTrackPos = m_canvas->grid().getYBin( changingSegment->savedRect().y()) + trackDiff; // Limit to [0, comp.getNbTracks()-1]. if (newTrackPos < 0) newTrackPos = 0; if (newTrackPos > static_cast<int>(comp.getNbTracks()) - 1) newTrackPos = comp.getNbTracks() - 1; const int newY = m_canvas->grid().getYBinCoordinate(newTrackPos); changingSegment->moveTo(newX, newY); m_changeMade = true; } if (m_changeMade) { // Make sure the segments are redrawn. // Note: The update() call below doesn't cause the segments to be // redrawn. It just updates from the cache. m_canvas->slotUpdateAll(); } // Guides const int guideX = getChangingSegment()->rect().x(); const int guideY = getChangingSegment()->rect().y(); m_canvas->drawGuides(guideX, guideY); // Text Float const timeT guideTime = m_canvas->grid().snapX(guideX); RealTime time = comp.getElapsedRealTime(guideTime); QString msecs; msecs.sprintf("%03d", time.msec()); int bar; int beat; int fraction; int remainder; comp.getMusicalTimeForAbsoluteTime(guideTime, bar, beat, fraction, remainder); QString posString = QString("%1.%2s (%3, %4, %5)"). arg(time.sec).arg(msecs).arg(bar + 1).arg(beat).arg(fraction); m_canvas->drawTextFloat(guideX + 10, guideY - 30, posString); m_canvas->update(); return RosegardenScrollView::FollowHorizontal | RosegardenScrollView::FollowVertical; }