Skip to content

Commit

Permalink
adjusted vertical offset of multi-measure repeats & rests for 1-staff
Browse files Browse the repository at this point in the history
since staff()->height() treats single-staff lines as having a height > 0, this caused ypos of measure rests and multi-measure rests to be below the single line staff.  This fixes by testing for single-staff lines and giving offset of 0.
  • Loading branch information
Eric Fontaine committed Oct 20, 2016
1 parent 7b48afd commit b74c6d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libmscore/layout.cpp
Expand Up @@ -3288,7 +3288,7 @@ System* Score::collectSystem(LayoutContext& lc)

middleX -= rm->bbox().width() / 2.0; // adjust for boundary box width so is center justified

qreal middleY = e->staff()->height() * .5; // center vertically in staff
qreal middleY = (e->staff()->lines() > 1) ? e->staff()->height() * .5 : 0; // center vertically in staff. Note: repeats on single-staff lines should have y offset = 0.

e->setPos(middleX, middleY);

Expand Down
5 changes: 4 additions & 1 deletion libmscore/measure.cpp
Expand Up @@ -3069,7 +3069,10 @@ void Measure::stretchMeasure(qreal targetWidth)

rest->setMMWidth(w);
qreal x = x1 - s.x() + d;
e->setPos(x, e->staff()->height() * .5); // center vertically in measure

qreal middleY = (e->staff()->lines() > 1) ? e->staff()->height() * .5 : 0; // center vertically in staff. Note: repeats on single-staff lines should have y offset = 0.

e->setPos(x, middleY); // center vertically in measure
rest->layout();
s.createShape(staffIdx);
}
Expand Down
2 changes: 1 addition & 1 deletion libmscore/repeat.cpp
Expand Up @@ -163,7 +163,7 @@ void RepeatMeasure::draw(QPainter* painter) const
drawSymbol(symbol(), painter, QPointF());
}

// draw number of measures above the symbol
// draw number of measures above the repeat measure's parent y position (i.e. above the top of the staff)
if (_repeatMeasureSize > 1) { // maybe use some other condition about toggling display of number...maybe customized via inspector or preferences or style? ...use same condition in layout

std::vector<Ms::SymId> repeatMeasureSizeSymbols = toTimeSigString(QString("%1").arg(_repeatMeasureSize));
Expand Down
20 changes: 9 additions & 11 deletions libmscore/rest.cpp
Expand Up @@ -104,23 +104,22 @@ void Rest::draw(QPainter* painter) const
painter->setPen(pen);

qreal w = _mmWidth;
qreal y = 0.0;
qreal middleY = 0.0;
qreal x1 = 0.0;
qreal x2 = w;
pw *= .5;
painter->drawLine(QLineF(x1 + pw, y, x2 - pw, y));
painter->drawLine(QLineF(x1 + pw, middleY, x2 - pw, middleY));

// draw vertical lines:
pen.setWidthF(_spatium * .2);
painter->setPen(pen);
painter->drawLine(QLineF(x1, y-_spatium, x1, y+_spatium));
painter->drawLine(QLineF(x2, y-_spatium, x2, y+_spatium));
painter->drawLine(QLineF(x1, middleY - _spatium, x1, middleY + _spatium));
painter->drawLine(QLineF(x2, middleY - _spatium, x2, middleY + _spatium));

std::vector<Ms::SymId> s = toTimeSigString(QString("%1").arg(n));
y = -_spatium * 1.5 - staff()->height() *.5;
qreal x = center(x1, x2);
x -= symBbox(s).width() * .5;
drawSymbols(s, painter, QPointF(x, y));
qreal numberYOffset = -_spatium * 1.5 - y(); // numbers go above parent's y
qreal numberXOffset = center(x1, x2) - symBbox(s).width() * .5;
drawSymbols(s, painter, QPointF(numberXOffset, numberYOffset));
}
else {
drawSymbol(_sym, painter);
Expand Down Expand Up @@ -346,9 +345,8 @@ void Rest::layout()
qreal w = _mmWidth + _spatium * verticalLineWidth*.5;
bbox().setRect(-_spatium * verticalLineWidth*.5, -h * .5, w, h);

// text
qreal y = -_spatium * 2.5 - staff()->height() *.5;
addbbox(QRectF(0, y, w, _spatium * 2)); // approximation
// text is placed above parent's y position
addbbox(QRectF(0, -y() - _spatium * 2.5, w, _spatium * 2)); // approximation
return;
}

Expand Down

0 comments on commit b74c6d4

Please sign in to comment.