Skip to content

Commit

Permalink
Merge pull request #1285 from MarcSabatella/32441-empty-key
Browse files Browse the repository at this point in the history
fix #32441: bad layout with empty key signature
  • Loading branch information
lasconic committed Sep 9, 2014
2 parents f2f36e1 + 107772a commit 957d26e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 5 additions & 1 deletion libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,7 @@ qreal Score::computeMinWidth(Segment* fs)
}
else {
// if (pt & (Segment::Type::KeySig | Segment::Type::Clef))
bool firstClef = (segmentIdx == 1) && (pt == Segment::Type::Clef);
bool firstClef = (pt == Segment::Type::Clef) && (pSeg && pSeg->rtick() == 0);
if ((pt & Segment::Type::KeySig) || firstClef)
minDistance = qMax(minDistance, clefKeyRightMargin);
}
Expand Down Expand Up @@ -3601,6 +3601,10 @@ qreal Score::computeMinWidth(Segment* fs)
minDistance = styleP(StyleIdx::clefLeftMargin);
else if (segType == Segment::Type::StartRepeatBarLine)
minDistance = .5 * _spatium;
else if (segType == Segment::Type::TimeSig && pt == Segment::Type::Clef) {
// missing key signature, but allocate default margin anyhow
minDistance = styleP(StyleIdx::keysigLeftMargin);
}
else if ((segType == Segment::Type::EndBarLine) && segmentIdx) {
if (pt == Segment::Type::Clef)
minDistance = styleP(StyleIdx::clefBarlineDistance);
Expand Down
34 changes: 21 additions & 13 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3165,7 +3165,7 @@ void Measure::layoutX(qreal stretch)
minDistance = qMax(minDistance, minNoteDistance);
}
else {
bool firstClef = (segmentIdx == 1) && (pt == Segment::Type::Clef);
bool firstClef = (pt == Segment::Type::Clef) && (pSeg && pSeg->rtick() == 0);
if ((pt & Segment::Type::KeySig) || firstClef)
minDistance = qMax(minDistance, clefKeyRightMargin);
}
Expand Down Expand Up @@ -3253,6 +3253,10 @@ void Measure::layoutX(qreal stretch)
minDistance = score()->styleS(StyleIdx::clefLeftMargin).val() * _spatium;
else if (segType == Segment::Type::StartRepeatBarLine)
minDistance = .5 * _spatium;
else if (segType == Segment::Type::TimeSig && pt == Segment::Type::Clef) {
// missing key signature, but allocate default margin anyhow
minDistance = score()->styleS(StyleIdx::keysigLeftMargin).val() * _spatium;
}
else if ((segType == Segment::Type::EndBarLine) && segmentIdx) {
if (pt == Segment::Type::Clef)
minDistance = score()->styleS(StyleIdx::clefBarlineDistance).val() * _spatium;
Expand Down Expand Up @@ -3484,8 +3488,7 @@ void Measure::layoutX(qreal stretch)
continue;
Element::Type t = e->type();
Rest* rest = static_cast<Rest*>(e);
if (((track % VOICES) == 0) &&
(t == Element::Type::REPEAT_MEASURE || (t == Element::Type::REST && (isMMRest() || rest->isFullMeasureRest())))) {
if (t == Element::Type::REPEAT_MEASURE || (t == Element::Type::REST && (isMMRest() || rest->isFullMeasureRest()))) {
//
// element has to be centered in free space
// x1 - left measure position of free space
Expand All @@ -3497,11 +3500,13 @@ void Measure::layoutX(qreal stretch)
//
qreal x1 = 0.0, x2;
Segment* ss = first();
for (; ss->segmentType() != Segment::Type::ChordRest; ss = ss->next())
;
// if (s != first()) {
if (ss != first()) {
ss = ss->prev();
Segment* ps = nullptr;
for (; ss->segmentType() != Segment::Type::ChordRest; ss = ss->next()) {
if (!ss->isEmpty())
ps = ss;
}
if (ps) {
ss = ps;
for (int staffIdx = 0; staffIdx < score()->nstaves(); ++staffIdx) {
int track = staffIdx * VOICES;
Element* e = ss->element(track);
Expand Down Expand Up @@ -3538,10 +3543,13 @@ void Measure::layoutX(qreal stretch)
qreal x1 = 0.0;
qreal x2 = this->width();
Segment* ss = first();
for (; ss->segmentType() != Segment::Type::ChordRest; ss = ss->next())
;
if (ss != first()) {
ss = ss->prev();
Segment* ps = nullptr;
for (; ss->segmentType() != Segment::Type::ChordRest; ss = ss->next()) {
if (!ss->isEmpty())
ps = ss;
}
if (ps) {
ss = ps;
for (int staffIdx = 0; staffIdx < score()->nstaves(); ++staffIdx) {
int track = staffIdx * VOICES;
Element* e = ss->element(track);
Expand All @@ -3557,7 +3565,7 @@ void Measure::layoutX(qreal stretch)
if (ns)
x2 = ns->x();

rest->rxpos() = (x2 - x1 - e->width()) * .5 + x1 - s->x();
rest->rxpos() = (x2 - x1 - e->width()) * .5 + x1 - s->x() - e->bbox().x();
rest->adjustReadPos();
}
}
Expand Down
1 change: 0 additions & 1 deletion libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ void Segment::remove(Element* el)
_elist[track] = 0;
if (!el->generated())
el->staff()->removeKey(tick());
empty = false;
break;

case Element::Type::CLEF:
Expand Down

0 comments on commit 957d26e

Please sign in to comment.