Skip to content

Commit

Permalink
implement text offset for misc. other elements
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Sep 20, 2018
1 parent 34b892d commit 7a2b518
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 32 deletions.
10 changes: 1 addition & 9 deletions libmscore/dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,7 @@ void Dynamic::read(XmlReader& e)

void Dynamic::layout()
{
qreal y;
if (placeAbove())
y = score()->styleP(Sid::dynamicsPosAbove);
else
y = score()->styleP(Sid::dynamicsPosBelow) + (staff() ? staff()->height() : 0.0);

QPointF o(offset() * (offsetType() == OffsetType::SPATIUM ? spatium() : DPI));
setPos(QPointF(0.0, y) + o);
TextBase::layout1();
layout2(Sid::dynamicsPosAbove, Sid::dynamicsPosBelow);

Segment* s = segment();
if (s) {
Expand Down
4 changes: 1 addition & 3 deletions libmscore/jump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ QString Jump::jumpTypeUserName() const

void Jump::layout()
{
setPos(QPointF(0.0, score()->styleP(Sid::jumpPosAbove)));
TextBase::layout1();

layout2(Sid::jumpPosAbove, Sid::jumpPosAbove);
autoplaceMeasureElement(0.5 * spatium());
}

Expand Down
3 changes: 1 addition & 2 deletions libmscore/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ Marker::Type Marker::markerType(const QString& s) const

void Marker::layout()
{
setPos(QPointF(0.0, score()->styleP(Sid::markerPosAbove)));
TextBase::layout1();
layout2(Sid::markerPosAbove, Sid::markerPosAbove);

// although normally laid out to parent (measure) width,
// force to center over barline if left-aligned
Expand Down
5 changes: 2 additions & 3 deletions libmscore/rehearsalmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ RehearsalMark::RehearsalMark(Score* s)

void RehearsalMark::layout()
{
qreal y = placeAbove() ? styleP(Sid::rehearsalMarkPosAbove) : styleP(Sid::rehearsalMarkPosBelow) + staff()->height();
setPos(QPointF(0.0, y));
TextBase::layout1();
layout2(Sid::rehearsalMarkPosAbove, Sid::rehearsalMarkPosBelow);

Segment* s = segment();
if (s) {
if (!s->rtick()) {
Expand Down
6 changes: 1 addition & 5 deletions libmscore/stafftext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ StaffText::StaffText(Score* s, Tid tid)

void StaffText::layout()
{
Staff* s = staff();
qreal y = placeAbove() ? styleP(Sid::staffTextPosAbove) : styleP(Sid::staffTextPosBelow) + (s ? s->height() : 0.0);
QPointF o(offset() * (offsetType() == OffsetType::SPATIUM ? spatium() : DPI));
setPos(o + QPointF(0.0, y));
TextBase::layout1();
layout2(Sid::staffTextPosAbove, Sid::staffTextPosBelow);
autoplaceSegmentElement(styleP(Sid::staffTextMinDistance));
}

Expand Down
6 changes: 1 addition & 5 deletions libmscore/systemtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ QVariant SystemText::propertyDefault(Pid id) const

void SystemText::layout()
{
Staff* s = staff();
qreal y = placeAbove() ? styleP(Sid::systemTextPosAbove) : styleP(Sid::systemTextPosBelow) + (s ? s->height() : 0.0);
QPointF o(offset() * (offsetType() == OffsetType::SPATIUM ? spatium() : DPI));
setPos(o + QPointF(0.0, y));
TextBase::layout1();
layout2(Sid::systemTextPosAbove, Sid::systemTextPosBelow);
autoplaceSegmentElement(styleP(Sid::systemTextMinDistance));
}

Expand Down
5 changes: 1 addition & 4 deletions libmscore/tempotext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ QVariant TempoText::propertyDefault(Pid id) const

void TempoText::layout()
{
qreal y = placeAbove() ? styleP(Sid::tempoPosAbove) : styleP(Sid::tempoPosBelow) + staff()->height();
QPointF o(offset() * (offsetType() == OffsetType::SPATIUM ? spatium() : DPI));
setPos(QPointF(0.0, y) + o);
TextBase::layout1();
layout2(Sid::tempoPosAbove, Sid::tempoPosBelow);

Segment* s = segment();
if (!s) // for use in palette
Expand Down
14 changes: 14 additions & 0 deletions libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,20 @@ void TextBase::layout()
layout1();
}

//---------------------------------------------------------
// layout2
//---------------------------------------------------------

void TextBase::layout2(Sid posAbove, Sid posBelow)
{
qreal y = placeAbove() ? styleP(posAbove) : styleP(posBelow) + staff()->height();

QPointF o(offset() * (offsetType() == OffsetType::SPATIUM ? spatium() : DPI));
setPos(QPointF(0.0, y) + o);

layout1();
}

//---------------------------------------------------------
// layout1
//---------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion libmscore/textbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class TextBase : public Element {

protected:
bool layoutInvalid { true };

QColor textColor() const;
QRectF frame; // calculated in layout()
void layoutFrame();
Expand Down Expand Up @@ -274,6 +274,7 @@ class TextBase : public Element {

virtual void layout() override;
virtual void layout1();
void layout2(Sid placeAbove, Sid placeBelow); // helper function
qreal lineSpacing() const;
qreal lineHeight() const;
virtual qreal baseLine() const override;
Expand Down

0 comments on commit 7a2b518

Please sign in to comment.