Skip to content

Commit

Permalink
fix #291699 - Stems and beams for small chords don't align correctly
Browse files Browse the repository at this point in the history
When calculating the length of the beams the width of the stems was neglected.
To support this calculation, a new method lineWidthMag() is the class Stem was
created, returning the scaled width of the stem.
  • Loading branch information
njvdberg committed Feb 3, 2020
1 parent a197b9f commit 57d8a18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions libmscore/beam.cpp
Expand Up @@ -1780,7 +1780,7 @@ void Beam::layout2(std::vector<ChordRest*>crl, SpannerSegmentType, int frag)
crBase[i1] = bl;
}

qreal stemWidth = score()->styleP(Sid::stemWidth);
qreal stemWidth = toChord(cr1)->stem()->lineWidthMag();

This comment has been minimized.

Copy link
@Jojo-Schmitz

Jojo-Schmitz Apr 1, 2020

Contributor

causes #303189
Should be fixed with #5893

This comment has been minimized.

Copy link
@njvdberg

njvdberg Apr 1, 2020

Author Contributor

#5893 Indeed fixes #5893

qreal x2 = cr1->stemPosX() + cr1->pageX() - _pagePos.x();
qreal x3;

Expand All @@ -1797,7 +1797,7 @@ void Beam::layout2(std::vector<ChordRest*>crl, SpannerSegmentType, int frag)
if (cr1->up())
x2 -= stemWidth;
if (!chordRest2->up())
x3 += stemWidth;
x3 += toChord(chordRest2)->stem()->lineWidthMag();

This comment has been minimized.

Copy link
@Jojo-Schmitz

Jojo-Schmitz Apr 1, 2020

Contributor

see above

This comment has been minimized.

Copy link
@njvdberg

njvdberg Apr 1, 2020

Author Contributor

see above

}
}
else {
Expand Down Expand Up @@ -1975,7 +1975,7 @@ void Beam::layout2(std::vector<ChordRest*>crl, SpannerSegmentType, int frag)
Stem* stem = c->stem();
if (stem) {
bool useTablature = staff() && staff()->isTabStaff(cr->tick());
qreal sw2 = useTablature ? 0.f : stem->lineWidth() * .5;
qreal sw2 = useTablature ? 0.f : stem->lineWidthMag() * .5;
if (c->up())
sw2 = -sw2;
stem->rxpos() = c->stemPosX() + sw2;
Expand Down
6 changes: 3 additions & 3 deletions libmscore/stem.cpp
Expand Up @@ -112,7 +112,7 @@ void Stem::layout()
}
}

qreal lw5 = _lineWidth * .5 * mag();
qreal lw5 = 0.5 * lineWidthMag();

line.setLine(0.0, y1, 0.0, l);

Expand Down Expand Up @@ -155,7 +155,7 @@ void Stem::draw(QPainter* painter) const
const StaffType* stt = st ? st->staffType(chord()->tick()) : 0;
bool useTab = stt && stt->isTabStaff();

painter->setPen(QPen(curColor(), _lineWidth * mag(), Qt::SolidLine, Qt::RoundCap));
painter->setPen(QPen(curColor(), lineWidthMag(), Qt::SolidLine, Qt::RoundCap));
painter->drawLine(line);

if (!(useTab && chord()))
Expand Down Expand Up @@ -397,7 +397,7 @@ QPointF Stem::hookPos() const
{
QPointF p(pos() + line.p2());

qreal xoff = _lineWidth * .5 * mag();
qreal xoff = 0.5 * lineWidthMag();
p.rx() += xoff;
return p;
}
Expand Down
1 change: 1 addition & 0 deletions libmscore/stem.h
Expand Up @@ -63,6 +63,7 @@ class Stem final : public Element {
void setUserLen(qreal l) { _userLen = l; }

qreal lineWidth() const { return _lineWidth; }
qreal lineWidthMag() const { return _lineWidth * mag(); }
void setLineWidth(qreal w) { _lineWidth = w; }

void setLen(qreal l);
Expand Down

0 comments on commit 57d8a18

Please sign in to comment.