Skip to content

Commit

Permalink
fix #24895: ties can collide with staff lines
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Mar 31, 2014
1 parent d438623 commit 7ec3b0f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
31 changes: 30 additions & 1 deletion libmscore/slur.cpp
Expand Up @@ -55,7 +55,7 @@ SlurSegment::SlurSegment(const SlurSegment& b)

void SlurSegment::move(const QPointF& s)
{
move(s);
Element::move(s);
for (int k = 0; k < SLUR_GRIPS; ++k)
ups[k].p += s;
}
Expand Down Expand Up @@ -551,6 +551,35 @@ void SlurSegment::layout(const QPointF& p1, const QPointF& p2)
ups[GRIP_START].p = p1;
ups[GRIP_END].p = p2;
slurTie()->computeBezier(this);
QRectF bbox = path.boundingRect();
qreal sp = spatium();
qreal ld = staff()->lineDistance(); // TODO: factor this in if not already incorporated in sp
qreal minDistance = 0.3;
if (bbox.height() < minDistance * 2 * sp) {
// path is fairly flat
// adjust position to avoid staff line if necessary
bool up = slurTie()->up();
qreal topY = bbox.top() / sp;
qreal bottomY = bbox.bottom() / sp;
int closestLine = up ? qRound(topY) : qRound(bottomY);
if (closestLine >= 0 && closestLine < staff()->lines()) {
// on staff
QPointF zeroP;
if (qAbs(topY - closestLine) < minDistance && qAbs(bottomY - closestLine) < minDistance) {
// too close to line
if (userOff() == zeroP && userOff2() == zeroP
&& ups[GRIP_START].off == zeroP && ups[GRIP_END].off == zeroP
&& ups[GRIP_BEZIER1].off == zeroP && ups[GRIP_BEZIER2].off == zeroP
&& ups[GRIP_SHOULDER].off == zeroP) {
// user has not edited
qreal offset = (up ? -0.5 : 0.5) * sp;
path.translate(0, offset);
shapePath.translate(0, offset);
bbox = path.boundingRect();
}
}
}
}
setbbox(path.boundingRect());
adjustReadPos();
}
Expand Down
3 changes: 1 addition & 2 deletions libmscore/tie.cpp
Expand Up @@ -71,8 +71,7 @@ void Tie::computeBezier(SlurSegment* ss, QPointF p6o)
double smallH = 0.38;
qreal d = p2.x() / _spatium;
shoulderH = d * 0.4 * smallH;
if (shoulderH > 1.3) // maximum tie shoulder height
shoulderH = 1.3;
shoulderH = qBound(0.4, shoulderH, 1.3);
shoulderH *= _spatium;
shoulderW = .6;

Expand Down

0 comments on commit 7ec3b0f

Please sign in to comment.