MatrixResizer::FollowMode MatrixResizer::handleMouseMove(const MatrixMouseEvent *e) { if (!e) return NoFollow; setBasicContextHelp(); if (!m_currentElement || !m_currentViewSegment) return NoFollow; if (getSnapGrid()->getSnapSetting() != SnapGrid::NoSnap) { setContextHelp(tr("Hold Shift to avoid snapping to beat grid")); } else { clearContextHelp(); } // snap in the closest direction timeT snapTime = e->snappedLeftTime; if (e->snappedRightTime - e->time < e->time - e->snappedLeftTime) { snapTime = e->snappedRightTime; } timeT newDuration = snapTime - m_currentElement->getViewAbsoluteTime(); timeT durationDiff = newDuration - m_currentElement->getViewDuration(); EventSelection* selection = m_scene->getSelection(); if (!selection || selection->getAddedEvents() == 0) return NoFollow; EventSelection::eventcontainer::iterator it = selection->getSegmentEvents().begin(); for (; it != selection->getSegmentEvents().end(); ++it) { MatrixElement *element = 0; ViewElementList::iterator vi = m_currentViewSegment->findEvent(*it); if (vi != m_currentViewSegment->getViewElementList()->end()) { element = static_cast<MatrixElement *>(*vi); } if (!element) continue; timeT t = element->getViewAbsoluteTime(); timeT d = element->getViewDuration(); d = d + durationDiff; if (d < 0) { t = t + d; d = -d; } else if (d == 0) { d = getSnapGrid()->getSnapTime(t); } element->reconfigure(t, d); // m_currentStaff->positionElement(element); // } } // m_mParentView->canvas()->update(); return FollowHorizontal; }
void SegmentSelector::setContextHelpFor(QPoint pos, Qt::KeyboardModifiers modifiers) { // If we are moving something if (m_selectionMoveStarted) { const bool shift = ((modifiers & Qt::ShiftModifier) != 0); // If shift isn't being held down if (!shift) { setContextHelp(tr("Hold Shift to avoid snapping to beat grid")); } else { clearContextHelp(); } return; } ChangingSegmentPtr segment = m_canvas->getModel()->getSegmentAt(pos); // If the mouse is hovering over the background if (!segment) { setContextHelp(tr("Click and drag to select segments; middle-click and drag to draw an empty segment")); return; } // The mouse is hovering over a segment. const bool ctrl = ((modifiers & Qt::ControlModifier) != 0); // If clicking would resize if (m_canvas->getModel()->getSelectedSegments().size() <= 1 && isNearEdge(segment->rect(), pos)) { if (!ctrl) { setContextHelp(tr("Click and drag to resize a segment; hold Ctrl as well to rescale its contents")); } else { setContextHelp(tr("Click and drag to rescale segment")); } } else { // clicking would move if (m_canvas->getModel()->haveMultipleSelection()) { if (!ctrl) { setContextHelp(tr("Click and drag to move segments; hold Ctrl as well to copy them; Ctrl + Alt for linked copies")); } else { setContextHelp(tr("Click and drag to copy segments")); } } else { if (!ctrl) { setContextHelp(tr("Click and drag to move segment; hold Ctrl as well to copy it; Ctrl + Alt for a linked copy; double-click to edit")); } else { setContextHelp(tr("Click and drag to copy segment")); } } } }
int SegmentPencil::mouseMoveEvent(QMouseEvent *e) { // No need to propagate. e->accept(); QPoint pos = m_canvas->viewportToContents(e->pos()); if (!m_newRect) { setContextHelpFor(pos); return RosegardenScrollView::NoFollow; } // If shift isn't being held down if ((e->modifiers() & Qt::ShiftModifier) == 0) { setContextHelp(tr("Hold Shift to avoid snapping to bar lines")); } else { clearContextHelp(); } QRect tmpRect = m_canvas->getNewSegmentRect(); SnapGrid &snapGrid = m_canvas->grid(); setSnapTime(e, SnapGrid::SnapToBar); int mouseX = pos.x(); // if mouse X is to the right of the original Press point if (mouseX >= m_pressX) { m_startTime = snapGrid.snapX(m_pressX, SnapGrid::SnapLeft); m_endTime = snapGrid.snapX(mouseX, SnapGrid::SnapRight); // Make sure the segment is never smaller than the smallest note. if (m_endTime - m_startTime < Note(Note::Shortest).getDuration()) m_endTime = m_startTime + Note(Note::Shortest).getDuration(); } else { // we are to the left of the original Press point m_startTime = snapGrid.snapX(mouseX, SnapGrid::SnapLeft); m_endTime = snapGrid.snapX(m_pressX, SnapGrid::SnapRight); // Make sure the segment is never smaller than the smallest note. if (m_endTime - m_startTime < Note(Note::Shortest).getDuration()) m_startTime = m_endTime - Note(Note::Shortest).getDuration(); } int leftX = snapGrid.getRulerScale()->getXForTime(m_startTime); int rightX = snapGrid.getRulerScale()->getXForTime(m_endTime); // Adjust the rectangle to go from leftX to rightX tmpRect.setLeft(leftX); tmpRect.setRight(rightX); m_canvas->drawNewSegment(tmpRect); return RosegardenScrollView::FollowHorizontal; }
MatrixSelector::FollowMode MatrixSelector::handleMouseMove(const MatrixMouseEvent *e) { if (m_dispatchTool) { return m_dispatchTool->handleMouseMove(e); } if (!m_updateRect) { setContextHelpFor (e, getSnapGrid()->getSnapSetting() == SnapGrid::NoSnap); return NoFollow; } else { clearContextHelp(); } QPointF p0(m_selectionOrigin); QPointF p1(e->sceneX, e->sceneY); QRectF r = QRectF(p0, p1).normalized(); m_selectionRect->setRect(r.x() + 0.5, r.y() + 0.5, r.width(), r.height()); m_selectionRect->show(); setViewCurrentSelection(false); /* int w = int(p.x() - m_selectionRect->x()); int h = int(p.y() - m_selectionRect->y()); // Qt rectangle dimensions appear to be 1-based if (w > 0) ++w; else --w; if (h > 0) ++h; else --h; // Workaround for #930420 Positional error in sweep-selection box boundary int wFix = (w > 0) ? 3 : 0; int hFix = (h > 0) ? 3 : 0; int xFix = (w < 0) ? 3 : 0; m_selectionRect->setSize(w - wFix, h - hFix); m_selectionRect->setX(m_selectionRect->x() + xFix); setViewCurrentSelection(); m_selectionRect->setSize(w, h); m_selectionRect->setX(m_selectionRect->x() - xFix); m_widget->canvas()->update(); */ return FollowMode(FollowHorizontal | FollowVertical); }
void SegmentMover::setContextHelp2(Qt::KeyboardModifiers modifiers) { // If we're moving something if (getChangingSegment()) { bool shift = ((modifiers & Qt::ShiftModifier) != 0); // If shift isn't being held down if (!shift) { setContextHelp(tr("Hold Shift to avoid snapping to beat grid")); } else { clearContextHelp(); } return; } setContextHelp(tr("Click and drag to move a segment")); }
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; }