Skip to content

Commit

Permalink
fix #279259: chord symbol spacing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Mar 15, 2019
1 parent 8d4160f commit b401907
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
8 changes: 2 additions & 6 deletions libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,12 +1207,8 @@ Shape ChordRest::shape() const
continue;
if (e->isHarmony() && e->staffIdx() == staffIdx()) {
Harmony* h = toHarmony(e);
// this layout is needed just to calculate the correct bbox
// so only do it if necessary, as it will reset position to default
// and there might not be an autoplace after this
// since ChordRest::shape() can be called at several points
if (h->isLayoutInvalid())
h->layout();
// calculate bbox only (do not reset position)
h->layout1();
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
59 changes: 40 additions & 19 deletions libmscore/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,18 @@ const ChordDescription* Harmony::parseHarmony(const QString& ss, int* root, int*
void Harmony::startEdit(EditData& ed)
{
if (!textList.empty()) {
// convert chord symbol to plain text
setXmlText(harmonyName());
// force layout, but restore original position
QPointF p = ipos();
layout();
setPos(p);
// clear rendering
for (const TextSegment* t : textList)
delete t;
textList.clear();
}

// layout as text, without position reset
TextBase::layout1();
triggerLayout();

TextBase::startEdit(ed);
}

Expand All @@ -724,20 +729,21 @@ bool Harmony::edit(EditData& ed)
{
if (ed.key == Qt::Key_Return)
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);
// layout as text, without position reset
TextBase::layout1();
triggerLayout();

int root, base;
// check spelling
int root = TPC_INVALID;
int base = TPC_INVALID;
QString str = xmlText();
showSpell = !str.isEmpty() && !parseHarmony(str, &root, &base, true);

showSpell = !str.isEmpty() && !parseHarmony(str, &root, &base, true) && root == TPC_INVALID;
if (showSpell)
qDebug("bad spell");

return rv;
}

Expand All @@ -747,8 +753,12 @@ bool Harmony::edit(EditData& ed)

void Harmony::endEdit(EditData& ed)
{
// render to layout as chord symbol
setHarmony(plainText());
// disable spell check
showSpell = false;
TextBase::endEdit(ed);

TextBase::endEdit(ed); // layout happens here

if (links()) {
for (ScoreElement* e : *links()) {
Expand All @@ -774,6 +784,7 @@ void Harmony::endEdit(EditData& ed)
h->setBaseTpc(baseTpc);
h->setXmlText(h->harmonyName());
h->setHarmony(h->plainText());
h->triggerLayout();
}
}
}
Expand Down Expand Up @@ -1007,20 +1018,17 @@ const ChordDescription* Harmony::generateDescription()

void Harmony::layout()
{
if (isLayoutInvalid())
createLayout();
if (textBlockList().empty())
textBlockList().append(TextBlock());
calculateBoundingRect(); // for normal symbols this is called in layout: computeMinWidth()

if (!parent()) {
setPos(0.0, 0.0);
setOffset(0.0, 0.0);
layout1();
return;
}
//if (isStyled(Pid::OFFSET))
// setOffset(propertyDefault(Pid::OFFSET).toPointF());

layout1();

qreal yy = 0.0;
qreal xx = 0.0;

Expand Down Expand Up @@ -1052,9 +1060,22 @@ void Harmony::layout()
}

setPos(xx, yy);
}

//---------------------------------------------------------
// layout1
//---------------------------------------------------------

void Harmony::layout1()
{
if (isLayoutInvalid())
createLayout();
if (textBlockList().empty())
textBlockList().append(TextBlock());
calculateBoundingRect(); // for normal symbols this is called in layout: computeMinWidth()
if (hasFrame())
layoutFrame();
score()->addRefresh(canvasBoundingRect());
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/harmony.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Harmony final : public TextBase {

void textChanged();
virtual void layout() override;
virtual void layout1() override;

virtual bool isEditable() const override { return true; }
virtual void startEdit(EditData&) override;
Expand Down
12 changes: 10 additions & 2 deletions libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "system.h"
#include "xml.h"
#include "undo.h"
#include "harmony.h"

namespace Ms {

Expand Down Expand Up @@ -1904,8 +1905,15 @@ void Segment::createShape(int staffIdx)
if (!e->autoplace())
continue;

if (!e->isRehearsalMark()
&& !e->isRehearsalMark()
if (e->isHarmony()) {
// use same spacing calculation as for chordrest
toHarmony(e)->layout1();
const qreal margin = styleP(Sid::minHarmonyDistance) * 0.5;
qreal x1 = e->bbox().x() - margin + e->pos().x();
qreal x2 = e->bbox().x() + e->bbox().width() + margin + e->pos().x();
s.addHorizontalSpacing(Shape::SPACING_HARMONY, x1, x2);
}
else if (!e->isRehearsalMark()
&& !e->isFretDiagram()
&& !e->isHarmony()
&& !e->isTempoText()
Expand Down
1 change: 1 addition & 0 deletions libmscore/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void TextBase::endEdit(EditData& ed)
undoChangeProperty(Pid::TEXT, actualText); // change property to set text to actual value again
// this also changes text of linked elements
layout1();
triggerLayout(); // force relayout even if text did not change
score()->endCmd();

static const qreal w = 2.0;
Expand Down

0 comments on commit b401907

Please sign in to comment.