Skip to content

Commit

Permalink
fix #276472: do not move slur if it doesn't intersect staff shape
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrio95 committed Nov 21, 2018
1 parent cca24ff commit c36be96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 13 additions & 0 deletions libmscore/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ bool Shape::intersects(const QRectF& rr) const
return false;
}

//---------------------------------------------------------
// intersects
//---------------------------------------------------------

bool Shape::intersects(const Shape& other) const
{
for (const QRectF& r : other) {
if (intersects(r))
return true;
}
return false;
}

//---------------------------------------------------------
// paint
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Shape : public std::vector<ShapeElement> {

bool contains(const QPointF&) const;
bool intersects(const QRectF& rr) const;
bool intersects(const Shape&) const;
void paint(QPainter&) const;

#ifndef NDEBUG
Expand Down
10 changes: 7 additions & 3 deletions libmscore/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ void SlurSegment::layoutSegment(const QPointF& p1, const QPointF& p2)
Segment* fs = system()->firstMeasure()->first();
QPointF pp1 = ups(Grip::START).p;
QPointF pp2 = ups(Grip::END).p;
bool intersection = false;
for (Segment* s = fs; s && s != ls; s = s->next1()) {
if (!s->enabled())
continue;
Expand All @@ -534,20 +535,23 @@ void SlurSegment::layoutSegment(const QPointF& p1, const QPointF& p2)
continue;
if (pp2.x() < x1)
break;
const Shape& segShape = s->staffShape(staffIdx()).translated(s->pos() + s->measure()->pos());
if (!intersection)
intersection = segShape.intersects(_shape);
if (up) {
//QPointF pt = QPointF(s->x() + s->measure()->x(), s->staffShape(staffIdx()).top() + s->y() + s->measure()->y());
qreal dist = _shape.minVerticalDistance(s->staffShape(staffIdx()).translated(s->pos() + s->measure()->pos()));
qreal dist = _shape.minVerticalDistance(segShape);
if (dist > 0.0)
gdist = qMax(gdist, dist);
}
else {
//QPointF pt = QPointF(s->x() + s->measure()->x(), s->staffShape(staffIdx()).bottom() + s->y() + s->measure()->y());
qreal dist = s->staffShape(staffIdx()).translated(s->pos() + s->measure()->pos()).minVerticalDistance(_shape);
qreal dist = segShape.minVerticalDistance(_shape);
if (dist > 0.0)
gdist = qMax(gdist, dist);
}
}
if (gdist > 0.0) {
if (intersection && gdist > 0.0) {
if (up) {
ryoffset() -= (gdist + spatium() * .5);
}
Expand Down

0 comments on commit c36be96

Please sign in to comment.