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")); } } } }
void SegmentSelector::mousePressEvent(QMouseEvent *e) { // Let the baseclass have a go. SegmentTool::mousePressEvent(e); // We only care about the left and middle mouse buttons. if (e->button() != Qt::LeftButton && e->button() != Qt::MidButton) return; // No need to propagate. e->accept(); QPoint pos = m_canvas->viewportToContents(e->pos()); // Get the segment that was clicked. ChangingSegmentPtr item = m_canvas->getModel()->getSegmentAt(pos); // If middle button... if (e->button() == Qt::MidButton) { // If clicked on the background, create a new segment. if (!item) { m_dispatchTool = m_canvas->getToolBox()->getTool(SegmentPencil::ToolName()); if (m_dispatchTool) { m_dispatchTool->ready(); // set mouse cursor m_dispatchTool->mousePressEvent(e); } } return; } // Left button was pressed. // ??? Should we split this into a midPress(e) and a leftPress(e)? // Might improve readability a little. // *** Adjust Selection // Shift key adds to selection. m_segmentAddMode = ((e->modifiers() & Qt::ShiftModifier) != 0); // if a segment was clicked if (item) { bool selected = m_canvas->getModel()->isSelected(item->getSegment()); if (m_segmentAddMode) { // toggle item selection m_canvas->getModel()->setSelected(item->getSegment(), !selected); } else { if (!selected) { // make the item the selection m_canvas->getModel()->clearSelected(); m_canvas->getModel()->setSelected(item->getSegment()); } } } else { // the background was clicked if (!m_segmentAddMode) { // clear the selection m_canvas->getModel()->clearSelected(); } } // *** Perform Functions bool ctrl = ((e->modifiers() & Qt::ControlModifier) != 0); // if a segment was clicked if (item) { // * Resize // if only one segment is selected and clicked near the edge, resize if (m_canvas->getModel()->getSelectedSegments().size() == 1 && isNearEdge(item->rect(), pos)) { SegmentResizer *segmentResizer = dynamic_cast<SegmentResizer *>( m_canvas->getToolBox()->getTool(SegmentResizer::ToolName())); // Turn it over to SegmentResizer. m_dispatchTool = segmentResizer; m_dispatchTool->ready(); // set mouse cursor m_dispatchTool->mousePressEvent(e); return; } // * Move // We don't dispatch to SegmentMover because SegmentMover // doesn't support copying/linking. bool alt = ((e->modifiers() & Qt::AltModifier) != 0); // Ctrl and Alt+Ctrl are segment copy. m_segmentCopyMode = ctrl; // Alt+Ctrl is copy as link. m_segmentCopyingAsLink = (alt && ctrl); // If the segment is selected, put it in move mode. if (m_canvas->getModel()->isSelected(item->getSegment())) { m_canvas->getModel()->startChange( item, CompositionModelImpl::ChangeMove); } setChangingSegment(item); m_clickPoint = pos; int guideX = item->rect().x(); int guideY = item->rect().y(); m_canvas->drawGuides(guideX, guideY); setSnapTime(e, SnapGrid::SnapToBeat); } else { // the background was clicked if (ctrl) { // * Create Segment m_dispatchTool = m_canvas->getToolBox()->getTool( SegmentPencil::ToolName()); if (m_dispatchTool) { m_dispatchTool->ready(); // set mouse cursor m_dispatchTool->mousePressEvent(e); } return; } // * Rubber Band m_canvas->drawSelectionRectPos1(pos); } // Make sure the Segment Parameters box is updated. See // RosegardenMainViewWidget::slotSelectedSegments(). m_canvas->getModel()->selectionHasChanged(); m_passedInertiaEdge = false; }