From 9c5335482e4419c6146fda4d1c8099bc965b9cf2 Mon Sep 17 00:00:00 2001 From: ws Date: Wed, 22 May 2013 14:12:47 +0200 Subject: [PATCH] fix #20996 #20994 --- libmscore/chord.cpp | 15 +++++---- libmscore/layout.cpp | 76 ++++++++++++++++++++++++++++++++------------ libmscore/score.h | 2 +- libmscore/stem.cpp | 14 ++++---- 4 files changed, 72 insertions(+), 35 deletions(-) diff --git a/libmscore/chord.cpp b/libmscore/chord.cpp index c3f94ac6ab07..2379dad2dae9 100644 --- a/libmscore/chord.cpp +++ b/libmscore/chord.cpp @@ -1388,7 +1388,6 @@ void Chord::layout() qreal x = stemX - fretWidth*0.5; note->setPos(x, _spatium * tab->physStringToVisual(note->string()) * lineDist); // note->layout2(); // needed? it is repeated later right before computing bbox - } // horiz. spacing: leave half width at each side of the (potential) stem qreal halfHeadWidth = headWidth * 0.5; @@ -1495,27 +1494,30 @@ void Chord::layout() // - position //----------------------------------------- - qreal stepDistance = _spatium * .5; - int stepOffset = staff()->staffType()->stepOffset(); +// qreal stepDistance = _spatium * .5; +// int stepOffset = staff()->staffType()->stepOffset(); int lx = 0.0; adjustReadPos(); - qreal stemWidth5; +// qreal stemWidth5; qreal noteWidth = _notes.size() ? downNote()->headWidth() : symbols[score()->symIdx()][quartheadSym].width(magS()); qreal stemX = _up ? noteWidth : 0.0; +#if 0 if (stem()) { stemWidth5 = stem()->lineWidth() * .5; _stem->rxpos() = _up ? stemX - stemWidth5 : stemWidth5; } else stemWidth5 = 0.0; +#endif int n = _notes.size(); for (int i = 0; i < n; ++i) { Note* note = _notes.at(i); note->layout(); +#if 0 qreal x; qreal hw = note->headWidth(); @@ -1531,9 +1533,10 @@ void Chord::layout() else x = 0.0; } - - note->rypos() = (note->line() + stepOffset) * stepDistance; note->rxpos() = x; + note->rypos() = (note->line() + stepOffset) * stepDistance; +#endif + qreal x = note->rxpos(); Accidental* accidental = note->accidental(); if (accidental) { diff --git a/libmscore/layout.cpp b/libmscore/layout.cpp index a1e07e1e9d3a..47e582d0d79a 100644 --- a/libmscore/layout.cpp +++ b/libmscore/layout.cpp @@ -140,7 +140,6 @@ void Score::layoutChords1(Segment* segment, int staffIdx) endIdx = -1; } - bool moveLeft = false; int ll = 1000; // line distance to previous note head bool isLeft = notes[startIdx]->chord()->up(); int move1 = notes[startIdx]->chord()->staffMove(); @@ -192,7 +191,6 @@ void Score::layoutChords1(Segment* segment, int staffIdx) notes[idx-incIdx]->chord()->rxpos() = note->headWidth() - note->point(styleS(ST_stemWidth)); note->rxpos() = 0.0; } - moveLeft = true; } } if (note->userMirror() == MScore::DH_AUTO) { @@ -204,9 +202,6 @@ void Score::layoutChords1(Segment* segment, int staffIdx) mirror = !mirror; } note->setMirror(mirror); - if (mirror) //?? - moveLeft = true; - move1 = move; ll = line; lastHeadGroup = headGroup; @@ -218,7 +213,11 @@ void Score::layoutChords1(Segment* segment, int staffIdx) // find column for dots //--------------------------------------------------- - QList aclist; + std::vector aclist; + + qreal _spatium = spatium(); + qreal stepDistance = _spatium * .5; + int stepOffset = staff->staffType()->stepOffset(); qreal dotPosX = 0.0; int nNotes = notes.size(); @@ -231,12 +230,46 @@ void Score::layoutChords1(Segment* segment, int staffIdx) AcEl acel; acel.note = note; acel.x = 0.0; - aclist.append(acel); + aclist.push_back(acel); } - qreal xx = note->pos().x() + note->headWidth() + note->chord()->pos().x(); + qreal hw = note->headWidth(); + qreal xx = note->pos().x() + hw + note->chord()->pos().x(); if (xx > dotPosX) dotPosX = xx; + + Chord* chord = note->chord(); + bool _up = chord->up(); + + qreal stemX; + if (_up) + stemX = symbols[symIdx()][quartheadSym].width(_spatium / (MScore::DPI * SPATIUM20)); + else + stemX = 0; + qreal stemWidth5; + if (chord->stem()) { + stemWidth5 = chord->stem()->lineWidth() * .5; + chord->stem()->rxpos() = _up ? stemX - stemWidth5 : stemWidth5; + } + else + stemWidth5 = 0.0; + + qreal x; + if (note->mirror()) { + if (_up) + x = stemX - stemWidth5 * 2; + else + x = stemX - hw + stemWidth5 * 2; + } + else { + if (_up) + x = stemX - hw; + else + x = 0.0; + } + note->rypos() = (note->line() + stepOffset) * stepDistance; + note->rxpos() = x; } + segment->setDotPosX(staffIdx, dotPosX); int nAcc = aclist.size(); @@ -255,23 +288,23 @@ void Score::layoutChords1(Segment* segment, int staffIdx) // layout bottom accidental // if (nAcc > 1) { - note = aclist[nAcc-1].note; + note = aclist[nAcc-1].note; // last note acc = note->accidental(); int l1 = aclist[0].note->line(); int l2 = note->line(); int st1 = aclist[0].note->accidental()->accidentalType(); - int st2 = acc->accidentalType(); int ldiff = st1 == Accidental::ACC_FLAT ? 4 : 5; if (qAbs(l1-l2) > ldiff) { aclist[nAcc-1].x = -pnd * acc->mag() - acc->width() - acc->bbox().x(); } else { + int st2 = acc->accidentalType(); if ((st1 == Accidental::ACC_FLAT) && (st2 == Accidental::ACC_FLAT) && (qAbs(l1-l2) > 2)) aclist[nAcc-1].x = aclist[0].x - acc->width() * .5; else - aclist[nAcc-1].x = aclist[0].x - acc->width(); + aclist[nAcc-1].x = aclist[0].x - acc->width() - pd; } } @@ -312,16 +345,17 @@ void Score::layoutChords1(Segment* segment, int staffIdx) } } - int n = aclist.size(); - for (int i = 0; i < n; ++i) { - const AcEl& e = aclist.at(i); + qreal lx = 10000.0; + for (const AcEl& e : aclist) { Note* note = e.note; - qreal x = e.x; - if (moveLeft) { - Chord* chord = note->chord(); - if (((note->mirror() && chord->up()) || (!note->mirror() && !chord->up()))) - x -= note->headWidth(); - } + qreal x = note->x(); + if (x < lx) + lx = x; + } + + for (const AcEl& e : aclist) { + Note* note = e.note; + qreal x = e.x + lx - note->x(); note->accidental()->setPos(x, 0); note->accidental()->adjustReadPos(); } @@ -2518,7 +2552,7 @@ void Score::respace(QList* elements) /// segment list fs //--------------------------------------------------------- -qreal Score::computeMinWidth(Segment* fs) const +qreal Score::computeMinWidth(Segment* fs) { int _nstaves = nstaves(); if (_nstaves == 0) diff --git a/libmscore/score.h b/libmscore/score.h index d593bb7d5dbd..28ecdb39e9fb 100644 --- a/libmscore/score.h +++ b/libmscore/score.h @@ -920,7 +920,7 @@ class Score : public QObject { Q_INVOKABLE void appendMeasures(int); Q_INVOKABLE void addText(const QString&, const QString&); Q_INVOKABLE Cursor* newCursor(); - qreal computeMinWidth(Segment* fs) const; + qreal computeMinWidth(Segment* fs); void updateBarLineSpans(int idx, int linesOld, int linesNew); Sym& sym(int id) { return symbols[symIdx()][id]; } diff --git a/libmscore/stem.cpp b/libmscore/stem.cpp index d73ba579a34c..830bf8507c20 100644 --- a/libmscore/stem.cpp +++ b/libmscore/stem.cpp @@ -94,12 +94,12 @@ void Stem::layout() } else { // non-TAB // move stem start to note attach point - Note* n = up() ? chord()->downNote() : chord()->upNote(); - const Sym& sym = symbols[score()->symIdx()][n->noteHead()]; - if (n->mirror()) - _up *= -1; - y1 -= sym.attach(n->magS()).y() * _up; - } + Note* n = up() ? chord()->downNote() : chord()->upNote(); + const Sym& sym = symbols[score()->symIdx()][n->noteHead()]; + if (n->mirror()) + _up *= -1; + y1 -= sym.attach(n->magS()).y() * _up; + } } line.setLine(0.0, y1, 0.0, l); @@ -137,7 +137,7 @@ void Stem::spatiumChanged(qreal oldValue, qreal newValue) void Stem::draw(QPainter* painter) const { // hide if second chord of a cross-measure pair - if(chord() && chord()->crossMeasure() == CROSSMEASURE_SECOND) + if (chord() && chord()->crossMeasure() == CROSSMEASURE_SECOND) return; Staff* st = staff();