Skip to content

Commit

Permalink
Merge pull request #4392 from MarcSabatella/chord-symbol-forced-layout
Browse files Browse the repository at this point in the history
fix #279950, fix #279804, fix #279666: force chord symbol layout
  • Loading branch information
anatoly-os committed Dec 14, 2018
2 parents 558a327 + aed4c73 commit 2355d24
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
4 changes: 3 additions & 1 deletion libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,9 @@ Shape ChordRest::shape() const
if (!e || !e->visible() || !e->autoplace())
continue;
if (e->isHarmony() && e->staffIdx() == staffIdx()) {
e->layout();
Harmony* h = toHarmony(e);
if (h->isLayoutInvalid())
h->layout();
const qreal margin = styleP(Sid::minHarmonyDistance) * 0.5;
x1 = qMin(x1, e->bbox().x() - margin + e->pos().x());
x2 = qMax(x2, e->bbox().x() + e->bbox().width() + margin + e->pos().x());
Expand Down
28 changes: 24 additions & 4 deletions libmscore/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,13 @@ const ChordDescription* Harmony::parseHarmony(const QString& ss, int* root, int*

void Harmony::startEdit(EditData& ed)
{
if (!textList.empty())
if (!textList.empty()) {
setXmlText(harmonyName());
// force layout, but restore original position
QPointF p = ipos();
layout();
setPos(p);
}

TextBase::startEdit(ed);
}
Expand All @@ -721,12 +726,17 @@ bool Harmony::edit(EditData& ed)
return true; // Harmony only single line
bool rv = TextBase::edit(ed);
setHarmony(plainText());

// force layout, but restore original position
QPointF p = ipos();
layout();
setPos(p);

int root, base;
QString str = xmlText();
bool badSpell = !str.isEmpty() && !parseHarmony(str, &root, &base, true);
setProperty(Pid::COLOR, badSpell ? QColor(Qt::red) : QColor(Qt::black));
showSpell = !str.isEmpty() && !parseHarmony(str, &root, &base, true);

if (badSpell)
if (showSpell)
qDebug("bad spell");
return rv;
}
Expand All @@ -737,6 +747,7 @@ bool Harmony::edit(EditData& ed)

void Harmony::endEdit(EditData& ed)
{
showSpell = false;
TextBase::endEdit(ed);

if (links()) {
Expand Down Expand Up @@ -1123,10 +1134,19 @@ void Harmony::drawEditMode(QPainter* p, EditData& ed)
{
TextBase::drawEditMode(p, ed);

QColor originalColor = color();
if (showSpell) {
setColor(QColor(Qt::red));
setSelected(false);
}
QPointF pos(canvasPos());
p->translate(pos);
TextBase::draw(p);
p->translate(-pos);
if (showSpell) {
setColor(originalColor);
setSelected(true);
}
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/harmony.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Harmony final : public TextBase {
QString _userName; // name as typed by user if applicable
QString _textName; // name recognized from chord list, read from score file, or constructed from imported source
ParsedChord* _parsedForm; // parsed form of chord
bool showSpell = false; // show spell check warning

QList<HDegree> _degreeList;
QList<QFont> fontList; // temp values used in render()
Expand Down
2 changes: 1 addition & 1 deletion libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2951,7 +2951,7 @@ void layoutHarmonies(const std::vector<Segment*>& sl)
// can exist without chord or rest too.
if (h->isLayoutInvalid())
h->layout();
toHarmony(e)->autoplaceSegmentElement(s->score()->styleP(Sid::minHarmonyDistance));
h->autoplaceSegmentElement(s->score()->styleP(Sid::minHarmonyDistance));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion libmscore/textbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ class TextBase : public Element {
QList<TextBlock>& textBlockList() { return _layout; }
int rows() const { return _layout.size(); }

void setTextInvalid() { textInvalid = true; };
void setTextInvalid() { textInvalid = true; }
bool isTextInvalid() const { return textInvalid; }
void setLayoutInvalid() { layoutInvalid = true; }
bool isLayoutInvalid() const { return layoutInvalid; }

// helper functions
Expand Down

0 comments on commit 2355d24

Please sign in to comment.