Skip to content

Commit

Permalink
fix #290968: hardcoded values not always exact
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstrema committed May 21, 2020
1 parent 34defcf commit 3eab17d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions libmscore/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,22 @@ void Rest::draw(QPainter* painter) const
// draw number
int n = measure()->mmRestCount();
std::vector<SymId>&& s = toTimeSigString(QString("%1").arg(n));
QRectF numberBox = symBbox(s);
qreal y = _mmRestNumberPos * spatium() - staff()->height() * .5;
qreal x = (_mmWidth - symBbox(s).width()) * .5;
qreal x = (_mmWidth - numberBox.width()) * .5;
drawSymbols(s, painter, QPointF(x, y));

// draw horizontal line
qreal pw = _spatium * .7;
qreal pw = _spatium * .7; // line width
QPen pen(painter->pen());
pen.setWidthF(pw);
painter->setPen(pen);
qreal x1 = pw * .5;
qreal x1 = pw * .5; // half of the line width
qreal x2 = _mmWidth - x1;
if (_mmRestNumberPos > 0.7 && _mmRestNumberPos < 3.3) { // hack for when number encounters horizontal line
qreal gapDistance = symBbox(s).width() * .5 + _spatium;

// avoid painting the line when it collides with the number.
if ((y + (numberBox.height() * .5 )) > -x1 && (y - (numberBox.height() * .5 )) < x1) {
qreal gapDistance = numberBox.width() * .5 + _spatium;
qreal midpoint = (x1 + x2) * .5;
painter->drawLine(QLineF(x1, 0.0, midpoint - gapDistance, 0.0));
painter->drawLine(QLineF(midpoint + gapDistance, 0.0, x2, 0.0));
Expand Down

0 comments on commit 3eab17d

Please sign in to comment.