Skip to content

Commit

Permalink
fix #286188: text on prebend misplaced
Browse files Browse the repository at this point in the history
For some reason, we place the text on prebends differently than others,
and while the code worked in 2.3.2, it no longer does,
and I think it has to do with changes made for screen scaling.
Fixing the screen scaling is possible but hard to test
and hard to guarantee it will be correct on all systems.
So instead, I am fixing this by changing the code that places the text
to use the same approach as other bends:
setitng the alignment to bottom center
rather than try to align ourselves using font metrics.
  • Loading branch information
MarcSabatella committed Oct 8, 2019
1 parent 8f5c957 commit ad7bd1a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libmscore/bend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ void Bend::draw(QPainter* painter) const

QFont f = font(_spatium * MScore::pixelRatio);
painter->setFont(f);
QFontMetrics fm(f, MScore::paintDevice());

qreal x = noteWidth + _spatium * .2;
qreal y = -_spatium * .8;
Expand All @@ -214,9 +213,18 @@ void Bend::draw(QPainter* painter) const
int idx = (pitch + 12)/25;
const char* l = label[idx];
QString s(l);
#if 1
painter->drawText(QRectF(x2, y2, .0, .0), Qt::AlignHCenter | Qt::AlignBottom | Qt::TextDontClip, s);
#else
// this is the code used originally,
// and it worked in 2.3.2, but fails currently - textWidth & textHeight are too large
// presumably they would need to be scaled accoridng to pixelRatio, DPI, and/or SPATIUM20
// now that the font & fontmetrics are also scaled
QFontMetrics fm(f, MScore::paintDevice());
qreal textWidth = fm.width(s);
qreal textHeight = fm.height();
painter->drawText(QRectF(x2 - textWidth / 2, y2 - textHeight / 2, .0, .0), Qt::AlignVCenter|Qt::TextDontClip, s);
#endif

y = y2;
}
Expand Down

0 comments on commit ad7bd1a

Please sign in to comment.