Skip to content

Commit

Permalink
Fix #270337: True dotted lines
Browse files Browse the repository at this point in the history
Fix #270337: True dotted lines
  • Loading branch information
elerouxx committed Jul 21, 2020
1 parent f469566 commit 9f05247
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
18 changes: 12 additions & 6 deletions libmscore/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,35 @@ void SlurSegment::draw(QPainter* painter) const
QPen pen(curColor());
qreal mag = staff() ? staff()->mag(slur()->tick()) : 1.0;

QVector<qreal> dotted = { 0.01, 1.99 }; // tighter than Qt Dotline equivalent { 0.01, 2.99 }
QVector<qreal> dashed = { 3.00, 3.00 };
QVector<qreal> wideDashed = { 5.00, 6.00 };

switch (slurTie()->lineType()) {
case 0:
painter->setBrush(QBrush(pen.color()));
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
pen.setWidthF(score()->styleP(Sid::SlurEndWidth) * mag);
break;
case 1:
case 1:
painter->setBrush(Qt::NoBrush);
pen.setCapStyle(Qt::RoundCap); // round dots
pen.setWidthF(score()->styleP(Sid::SlurDottedWidth) * mag);
pen.setStyle(Qt::DotLine);
break;
pen.setStyle(Qt::CustomDashLine);
pen.setDashPattern(dotted);
break;
case 2:
painter->setBrush(Qt::NoBrush);
pen.setWidthF(score()->styleP(Sid::SlurDottedWidth) * mag);
pen.setStyle(Qt::DashLine);
pen.setStyle(Qt::CustomDashLine);
pen.setDashPattern(dashed);
break;
case 3:
painter->setBrush(Qt::NoBrush);
pen.setWidthF(score()->styleP(Sid::SlurDottedWidth) * mag);
pen.setStyle(Qt::CustomDashLine);
QVector<qreal> dashes { 5.0, 5.0 };
pen.setDashPattern(dashes);
pen.setDashPattern(wideDashed);
break;
}
painter->setPen(pen);
Expand Down
35 changes: 29 additions & 6 deletions libmscore/textlinebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,36 @@ void TextLineBaseSegment::draw(QPainter* painter) const
qreal textlineLineWidth = tl->lineWidth();
if (staff())
textlineLineWidth *= mag();
QPen pen(color, textlineLineWidth, tl->lineStyle());
QPen solidPen(color, textlineLineWidth, Qt::SolidLine);
if (tl->lineStyle() == Qt::CustomDashLine) {
QVector<qreal> dashes { tl->dashLineLen(), tl->dashGapLen() };
pen.setDashPattern(dashes);
QPen pen(color, textlineLineWidth, tl->lineStyle(), Qt::SquareCap);
QPen solidPen(color, textlineLineWidth, Qt::SolidLine, Qt::SquareCap);

//Replace generic Qt dash patterns with improved equivalents to show true dots
QVector<qreal> dotted = { 0.01, 1.99 }; // tighter than Qt Dotline equivalent { 0.01, 2.99 }
QVector<qreal> dashed = { 3.0, 3.0 };
QVector<qreal> dashDotted = { 3.01, 2.99, 0.01, 2.99 };
QVector<qreal> dashDotDotted = { 3.01, 2.99, 0.01, 2.99, 0.01, 2.99 };
QVector<qreal> customDashes = { tl->dashLineLen(), tl->dashGapLen() };

switch (tl->lineStyle()) {
case Qt::DashLine:
pen.setDashPattern(dashed);
break;
case Qt::DotLine:
pen.setDashPattern(dotted);
pen.setCapStyle(Qt::RoundCap); // round dots
break;
case Qt::DashDotLine:
pen.setDashPattern(dashDotted);
break;
case Qt::DashDotDotLine:
pen.setDashPattern(dashDotDotted);
break;
case Qt::CustomDashLine:
pen.setDashPattern(customDashes);
break;
}

//Draw lines
if (twoLines) { // hairpins
painter->setPen(pen);
painter->drawLines(&points[0], 1);
Expand All @@ -119,7 +142,7 @@ void TextLineBaseSegment::draw(QPainter* painter) const
else {
int start = 0;
int end = npoints;
//draw hooks as solid
//draw centered hooks as solid
painter->setPen(solidPen);
if (tl->beginHookType() == HookType::HOOK_90T) {
painter->drawLines(&points[0], 1);
Expand Down
15 changes: 11 additions & 4 deletions libmscore/tie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ void TieSegment::draw(QPainter* painter) const

QPen pen(curColor());
qreal mag = staff() ? staff()->mag(tie()->tick()) : 1.0;

QVector<qreal> dotted = { 0.01, 1.99 }; // tighter than Qt Dotline equivalent { 0.01, 2.99 }
QVector<qreal> dashed = { 3.00, 3.00 };
QVector<qreal> wideDashed = { 5.00, 6.00 };

switch (slurTie()->lineType()) {
case 0:
painter->setBrush(QBrush(pen.color()));
Expand All @@ -43,20 +48,22 @@ void TieSegment::draw(QPainter* painter) const
break;
case 1:
painter->setBrush(Qt::NoBrush);
pen.setCapStyle(Qt::RoundCap); // True dots
pen.setWidthF(score()->styleP(Sid::SlurDottedWidth) * mag);
pen.setStyle(Qt::DotLine);
pen.setStyle(Qt::CustomDashLine);
pen.setDashPattern(dotted);
break;
case 2:
painter->setBrush(Qt::NoBrush);
pen.setWidthF(score()->styleP(Sid::SlurDottedWidth) * mag);
pen.setStyle(Qt::DashLine);
pen.setStyle(Qt::CustomDashLine);
pen.setDashPattern(dashed);
break;
case 3:
painter->setBrush(Qt::NoBrush);
pen.setWidthF(score()->styleP(Sid::SlurDottedWidth) * mag);
pen.setStyle(Qt::CustomDashLine);
QVector<qreal> dashes { 5.0, 5.0 };
pen.setDashPattern(dashes);
pen.setDashPattern(wideDashed);
break;
}
painter->setPen(pen);
Expand Down
4 changes: 2 additions & 2 deletions mscore/inspector/inspector_line.ui
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@
<string>Dash line length</string>
</property>
<property name="minimum">
<double>1.000000000000000</double>
<double>0.010000000000000</double>
</property>
<property name="maximum">
<double>20.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
<double>0.250000000000000</double>
</property>
</widget>
</item>
Expand Down

0 comments on commit 9f05247

Please sign in to comment.