bool LineSegment::edit(MuseScoreView* sv, int curGrip, int key, Qt::KeyboardModifiers modifiers, const QString&) { if (!((modifiers & Qt::ShiftModifier) && ((subtype() == SEGMENT_SINGLE) || (subtype() == SEGMENT_BEGIN && curGrip == GRIP_LINE_START) || (subtype() == SEGMENT_END && curGrip == GRIP_LINE_END)))) return false; LineSegment* ls = 0; SLine* l = line(); bool bspDirty = false; SpannerSegmentType st = subtype(); int track = l->track(); if (l->anchor() == ANCHOR_SEGMENT) { Segment* s1 = static_cast<Segment*>(l->startElement()); Segment* s2 = static_cast<Segment*>(l->endElement()); bool removeSegment = false; if (key == Qt::Key_Left) { if (curGrip == GRIP_LINE_START) { s1 = prevSeg1(s1, track); } else if (curGrip == GRIP_LINE_END) { s2 = prevSeg1(s2, track); if (s2 && (s2->system()->firstMeasure() == s2->measure()) && (s2->tick() == s2->measure()->tick())) { removeSegment = true; } } } else if (key == Qt::Key_Right) { if (curGrip == GRIP_LINE_START) s1 = nextSeg1(s1, track); else if (curGrip == GRIP_LINE_END) { if ((s2->system()->firstMeasure() == s2->measure()) && (s2->tick() == s2->measure()->tick())) bspDirty = true; s2 = nextSeg1(s2, track); } } if (s1 == 0 || s2 == 0 || s1->tick() >= s2->tick()) return true; if (l->startElement() != s1) { if (s1->system() != (static_cast<Segment*>(l->startElement())->system())) { bspDirty = true; if (key == Qt::Key_Right) ls = l->takeFirstSegment(); } static_cast<Segment*>(l->startElement())->remove(l); l->setStartElement(s1); s1->add(l); } else if (l->endElement() != s2) { if (removeSegment) { bspDirty = true; if (key == Qt::Key_Left) ls = l->takeLastSegment(); } static_cast<Segment*>(l->endElement())->removeSpannerBack(l); l->setEndElement(s2); s2->addSpannerBack(l); } } else { Measure* m1 = static_cast<Measure*>(l->startElement()); Measure* m2 = static_cast<Measure*>(l->endElement()); bool removeSegment = false; if (key == Qt::Key_Left) { if (curGrip == GRIP_LINE_START) { if (m1->prevMeasure()) m1 = m1->prevMeasure(); } else if (curGrip == GRIP_LINE_END) { if (m2 && (m2->system()->firstMeasure() == m2)) removeSegment = true; Measure* m = m2->prevMeasure(); if (m) m2 = m; } } else if (key == Qt::Key_Right) { if (curGrip == GRIP_LINE_START) { if (m1->nextMeasure()) m1 = m1->nextMeasure(); } else if (curGrip == GRIP_LINE_END) { if (m2->nextMeasure()) m2 = m2->nextMeasure(); if (m2->system()->firstMeasure() == m2) bspDirty = true; } } if (m1->tick() > m2->tick()) return true; if (l->startElement() != m1) { if (m1->system() != (static_cast<Measure*>(l->startElement())->system())) { bspDirty = true; if (key == Qt::Key_Right) ls = l->takeFirstSegment(); } l->startElement()->remove(l); l->setStartElement(m1); m1->add(l); } else if (l->endElement() != m2) { if (removeSegment) { bspDirty = true; if (key == Qt::Key_Left) ls = l->takeLastSegment(); } static_cast<Measure*>(l->endElement())->removeSpannerBack(l); l->setEndElement(m2); m2->addSpannerBack(l); } } l->layout(); LineSegment* nls = 0; if (st == SEGMENT_SINGLE) { if (curGrip == GRIP_LINE_START) nls = l->frontSegment(); else if (curGrip == GRIP_LINE_END) nls = l->backSegment(); } else if (st == SEGMENT_BEGIN) nls = l->frontSegment(); else if (st == SEGMENT_END) nls = l->backSegment(); if (nls && (nls != this)) sv->changeEditElement(nls); if (bspDirty) _score->rebuildBspTree(); if (ls) _score->undoRemoveElement(ls); return true; }