Skip to content

Commit 79cd428

Browse files
iveshenry18Jojo-Schmitz
authored andcommitted
ENG-53: FretDiagrams create horizontal space
This commit adds a case for including fretboard diagrams when creating horizontal spacing in the ChordRest::shape() function. In pursuit of this, it also extracts a calculateBoundingRect function from FretDiagram::layout(). NOTE: In order to allow "orphaned" FretDiagrams to still create space, the spacer is added to all staves. This is redundant in some cases, so a more performant solution may be desirable in the future. Duplicate of musescore#8296
1 parent 711d9d5 commit 79cd428

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

libmscore/chordrest.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,12 +1305,28 @@ Shape ChordRest::shape() const
13051305
if (e->isHarmony() && e->staffIdx() == staffIdx()) {
13061306
Harmony* h = toHarmony(e);
13071307
// calculate bbox only (do not reset position)
1308-
h->layout1();
1308+
if (h->bbox().isEmpty()) h->layout1();
13091309
const qreal margin = styleP(Sid::minHarmonyDistance) * 0.5;
13101310
x1 = qMin(x1, e->bbox().x() - margin + e->pos().x());
13111311
x2 = qMax(x2, e->bbox().x() + e->bbox().width() + margin + e->pos().x());
13121312
adjustWidth = true;
13131313
}
1314+
else if (e->isFretDiagram()) {
1315+
FretDiagram* fd = toFretDiagram(e);
1316+
if (fd->bbox().isEmpty()) fd->calculateBoundingRect();
1317+
qreal margin = styleP(Sid::fretMinDistance) * 0.5;
1318+
x1 = qMin(x1, e->bbox().x() - margin + e->pos().x());
1319+
x2 = qMax(x2, e->bbox().x() + e->bbox().width() + margin + e->pos().x());
1320+
adjustWidth = true;
1321+
if (fd->harmony()) {
1322+
Harmony* h = fd->harmony();
1323+
if (h->bbox().isEmpty()) h->layout1();
1324+
margin = styleP(Sid::minHarmonyDistance) * 0.5;
1325+
x1 = qMin(x1, h->bbox().x() - margin + h->pos().x() + e->pos().x());
1326+
x2 = qMax(x2, h->bbox().x() + h->bbox().width() + margin + h->pos().x() + e->pos().x());
1327+
adjustWidth = true;
1328+
}
1329+
}
13141330
}
13151331
if (adjustWidth)
13161332
shape.addHorizontalSpacing(Shape::SPACING_HARMONY, x1, x2);

libmscore/fret.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ void FretDiagram::draw(QPainter* painter) const
452452
}
453453

454454
//---------------------------------------------------------
455-
// layout
455+
// calculateBoundingRect()
456456
//---------------------------------------------------------
457457

458-
void FretDiagram::layout()
458+
void FretDiagram::calculateBoundingRect()
459459
{
460460
qreal _spatium = spatium() * _userMag;
461461
stringLw = _spatium * 0.08;
@@ -492,7 +492,15 @@ void FretDiagram::layout()
492492
}
493493

494494
bbox().setRect(x, y, w, h);
495+
}
495496

497+
//---------------------------------------------------------
498+
// layout
499+
//---------------------------------------------------------
500+
501+
void FretDiagram::layout()
502+
{
503+
calculateBoundingRect();
496504
if (!parent() || !parent()->isSegment()) {
497505
setPos(QPointF());
498506
return;
@@ -522,7 +530,7 @@ void FretDiagram::layout()
522530
mainWidth = stringDist * (_strings - 1);
523531
else if (_orientation == Orientation::HORIZONTAL)
524532
mainWidth = fretDist * (_frets + 0.5);
525-
setPos((noteheadWidth - mainWidth)/2, -(h + styleP(Sid::fretY)));
533+
setPos((noteheadWidth - mainWidth)/2, -(bbox().height() + styleP(Sid::fretY)));
526534

527535
autoplaceSegmentElement();
528536

libmscore/fret.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class FretDiagram final : public Element {
173173

174174
ElementType type() const override { return ElementType::FRET_DIAGRAM; }
175175
void layout() override;
176+
void calculateBoundingRect();
176177
void write(XmlWriter& xml) const override;
177178
void writeNew(XmlWriter& xml) const;
178179
void writeOld(XmlWriter& xml) const;

0 commit comments

Comments
 (0)