void Slur::slurPos(SlurPos* sp) { qreal _spatium = spatium(); Element* e1 = startElement(); Element* e2 = endElement(); if (e2 == 0) { sp->p1 = e1->pagePos(); sp->p1.rx() += e1->width(); sp->p2 = sp->p1; sp->p2.rx() += 5 * _spatium; sp->system1 = static_cast<ChordRest*>(e1)->measure()->system(); sp->system2 = sp->system1; return; } if ((e1->type() != CHORD) || (e2->type() != CHORD)) { sp->p1 = e1->pagePos(); sp->p2 = e2->pagePos(); sp->p1.rx() += e1->width(); sp->p2.rx() += e2->width(); sp->system1 = static_cast<ChordRest*>(e1)->measure()->system(); sp->system2 = static_cast<ChordRest*>(e2)->measure()->system(); return; } Chord* sc = static_cast<Chord*>(e1); Chord* ec = static_cast<Chord*>(e2); Note* note1 = _up ? sc->upNote() : sc->downNote(); Note* note2 = _up ? ec->upNote() : ec->downNote(); sp->system1 = sc->measure()->system(); sp->system2 = ec->measure()->system(); sp->p1 = sc->pagePos() - sp->system1->pagePos(); sp->p2 = ec->pagePos() - sp->system2->pagePos(); qreal xo, yo; Stem* stem1 = sc->stem(); Stem* stem2 = ec->stem(); enum SlurAnchor { SA_NONE, SA_STEM }; SlurAnchor sa1 = SA_NONE; SlurAnchor sa2 = SA_NONE; if ((sc->up() == ec->up()) && !sc->beam() && !ec->beam() && (_up == sc->up())) { if (stem1) sa1 = SA_STEM; if (stem2) sa2 = SA_STEM; } qreal __up = _up ? -1.0 : 1.0; qreal hw = note1->headWidth(); switch (sa1) { case SA_STEM: sp->p1 += sc->stemPosBeam() - sc->pagePos() + sc->stem()->p2(); sp->p1 += QPointF(0.35 * _spatium, 0.25 * _spatium); break; case SA_NONE: break; } switch(sa2) { case SA_STEM: sp->p2 += ec->stemPosBeam() - ec->pagePos() + ec->stem()->p2(); sp->p2 += QPointF(-0.35 * _spatium, 0.25 * _spatium); break; case SA_NONE: break; } // // default position: // horizontal: middle of note head // vertical: _spatium * .4 above/below note head // //------p1 bool stemPos = false; // p1 starts at chord stem side yo = note1->pos().y() + _spatium * .9 * __up; xo = hw * .5; if (stem1) { Beam* beam1 = sc->beam(); if (beam1 && (beam1->elements().back() != sc) && (sc->up() == _up)) { qreal sh = stem1->height() + _spatium; yo = sc->downNote()->pos().y() + sh * __up; xo = stem1->pos().x(); stemPos = true; } else { if (sc->up() && _up) xo = hw + _spatium * .3; // // handle case: stem up - stem down // stem down - stem up // if ((sc->up() != ec->up()) && (sc->up() == _up)) { Note* n1 = sc->up() ? sc->downNote() : sc->upNote(); Note* n2 = ec->up() ? ec->downNote() : ec->upNote(); qreal yd = n2->pos().y() - n1->pos().y(); yd *= .5; qreal sh = stem1->height(); // limit y move if (yd > 0.0) { if (yd > sh) yd = sh; } else { if (yd < - sh) yd = -sh; } stemPos = true; if ((_up && (yd < -_spatium)) || (!_up && (yd > _spatium))) yo += yd; } else if (sc->up() != _up) yo = fixArticulations(yo, sc, __up); } } if (sa1 == SA_NONE) sp->p1 += QPointF(xo, yo); //------p2 xo = hw * .5; yo = note2->pos().y() + _spatium * .9 * __up; if (stem2) { Beam* beam2 = ec->beam(); if ((stemPos && (sc->up() == ec->up())) || (beam2 && (!beam2->elements().isEmpty()) && (beam2->elements().front() != ec) && (ec->up() == _up) && (sc->noteType() == NOTE_NORMAL) ) ) { qreal sh = stem2->height() + _spatium; if (_up) yo = ec->downNote()->pos().y() - sh; else yo = ec->upNote()->pos().y() + sh; xo = stem2->pos().x(); } else if (!ec->up() && !_up) xo = -_spatium * .3 + note2->x(); // // handle case: stem up - stem down // stem down - stem up // if ((sc->up() != ec->up()) && (ec->up() == _up)) { Note* n1 = sc->up() ? sc->downNote() : sc->upNote(); Note* n2 = ec->up() ? ec->downNote() : ec->upNote(); qreal yd = n2->pos().y() - n1->pos().y(); yd *= .5; qreal mh = stem2->height(); // limit y move if (yd > 0.0) { if (yd > mh) yd = mh; } else { if (yd < - mh) yd = -mh; } if ((_up && (yd > _spatium)) || (!_up && (yd < -_spatium))) yo -= yd; } else if (ec->up() != _up) yo = fixArticulations(yo, ec, __up); } if (sa2 == SA_NONE) sp->p2 += QPointF(xo, yo); }