Skip to content

Commit

Permalink
fix #276037 Incorrect dynamics position on 1-line staff
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Sep 12, 2018
1 parent 17a180b commit d15d09a
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 49 deletions.
7 changes: 2 additions & 5 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,11 @@ void BarLine::getY() const
int from = _spanFrom;
int to = _spanTo;
int oneLine = st1->lines() == 1;
if (oneLine && _spanFrom == 0)
if (oneLine && _spanFrom == 0) {
from = BARLINE_SPAN_1LINESTAFF_FROM;
if (!_spanStaff) {
if (oneLine && _spanTo == 0)
if (!_spanStaff)
to = BARLINE_SPAN_1LINESTAFF_TO;
}

SysStaff* sysStaff1 = system->staff(staffIdx1);
qreal yp = sysStaff1->y();
qreal spatium1 = st1->spatium(score());
Expand Down Expand Up @@ -559,7 +557,6 @@ bool BarLine::acceptDrop(EditData& data) const
{
ElementType type = data.element->type();
if (type == ElementType::BAR_LINE) {
printf("may drop\n");
return true;
}
else {
Expand Down
18 changes: 6 additions & 12 deletions libmscore/dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ void Dynamic::layout()
qreal y;
if (placeAbove())
y = score()->styleP(Sid::dynamicsPosAbove);
else {
qreal sh = staff() ? staff()->height() : 0;
y = score()->styleP(Sid::dynamicsPosBelow) + sh + lineSpacing();
}
else
y = score()->styleP(Sid::dynamicsPosBelow) + (staff() ? staff()->height() : 0.0);
setPos(QPointF(0.0, y));
TextBase::layout1();

Expand Down Expand Up @@ -212,24 +210,20 @@ void Dynamic::doAutoplace()
qreal minDistance = score()->styleP(Sid::dynamicsMinDistance);
QRectF r = bbox().translated(pos() + s->pos() + s->measure()->pos());
Skyline& sl = s->measure()->system()->staff(staffIdx())->skyline();
SkylineLine sk(!placeAbove());
sk.add(r);

if (placeAbove()) {
SkylineLine sk(false);
sk.add(r.x(), r.bottom(), r.width());

qreal d = sk.minDistance(sl.north());
if (d > -minDistance)
rUserYoffset() = -d - minDistance;
rUserYoffset() = -(d + minDistance);
}
else {
SkylineLine sk(true);
sk.add(r.x(), r.top(), r.width());

qreal d = sl.south().minDistance(sk);
if (d > -minDistance)
rUserYoffset() = d + minDistance;
}
sl.add(r);
// sl.add(r); do later
}

//---------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ namespace Ms {
//---------------------------------------------------------

class MStaff {
// Shape _shape;
Text* _noText { 0 }; ///< Measure number text object
StaffLines* _lines { 0 };
Spacer* _vspacerUp { 0 };
Expand All @@ -108,9 +107,6 @@ class MStaff {
void setScore(Score*);
void setTrack(int);

// Shape shape() const { return _shape; }
// Shape& shape() { return _shape; }

Text* noText() const { return _noText; }
void setNoText(Text* t) { _noText = t; }

Expand Down
5 changes: 2 additions & 3 deletions libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,13 +1835,12 @@ void Segment::createShape(int staffIdx)

for (int track = staffIdx * VOICES; track < (staffIdx + 1) * VOICES; ++track) {
Element* e = _elist[track];
if (e) {
if (e)
s.add(e->shape().translated(e->pos()));
}
}

for (Element* e : _annotations) {
if (e->staffIdx() == staffIdx
if (e->staffIdx() == staffIdx // whats left?
&& !e->isRehearsalMark()
&& !e->isFretDiagram()
&& !e->isHarmony()
Expand Down
16 changes: 10 additions & 6 deletions libmscore/skyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ void Skyline::add(const QRectF& r)

void SkylineLine::add(const Shape& s)
{
for (const auto& r : s) {
if (north)
add(r.x(), r.top(), r.width());
else
add(r.x(), r.bottom(), r.width());
}
for (const auto& r : s)
add(r);
}

void SkylineLine::add(const QRectF& r)
{
if (north)
add(r.x(), r.top(), r.width());
else
add(r.x(), r.bottom(), r.width());
}

void Skyline::add(const Shape& s)
Expand Down
1 change: 1 addition & 0 deletions libmscore/skyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct SkylineLine : public std::vector<SkylineSegment> {
SkylineLine(bool n) : north(n) {}
void add(qreal x, qreal y, qreal w);
void add(const Shape& s);
void add(const QRectF& r);
void paint(QPainter&) const;
void dump() const;
qreal minDistance(const SkylineLine&) const;
Expand Down
3 changes: 2 additions & 1 deletion libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ bool Staff::readProperties(XmlReader& e)
qreal Staff::height() const
{
int tick = 0; // TODO
return (lines(tick) == 1 ? 2 : lines(tick)-1) * spatium(tick) * staffType(tick)->lineDistance().val();
// return (lines(tick) == 1 ? 2 : lines(tick)-1) * spatium(tick) * staffType(tick)->lineDistance().val();
return (lines(tick)-1) * spatium(tick) * staffType(tick)->lineDistance().val();
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions libmscore/stafflines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void StaffLines::layoutForWidth(qreal w)
dist *= st->lineDistance().val();
_lines = st->lines();
rypos() = st->yoffset().val() * _spatium;
if (_lines == 1)
rypos() = 2 * _spatium;
// if (_lines == 1)
// rypos() = 2 * _spatium;
}
else {
_lines = 5;
Expand Down
25 changes: 15 additions & 10 deletions libmscore/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,16 @@ void System::layoutSystem(qreal xo1)
}
++nVisible;
qreal staffMag = staff->mag(0); // ??? TODO
qreal h;
if (staff->lines(0) == 1)
h = 2;
else
h = (staff->lines(0)-1) * staff->lineDistance(0);
h = h * staffMag * spatium();
s->bbox().setRect(_leftMargin + xo1, 0.0, 0.0, h);
int staffLines = staff->lines(0);
if (staffLines == 1) {
qreal h = staff->lineDistance(0) * staffMag * spatium();
s->bbox().setRect(_leftMargin + xo1, -h, 0.0, 2 * h);
}
else {
qreal h = (staffLines - 1) * staff->lineDistance(0);
h = h * staffMag * spatium();
s->bbox().setRect(_leftMargin + xo1, 0.0, 0.0, h);
}
}

//---------------------------------------------------
Expand Down Expand Up @@ -395,7 +398,8 @@ void System::layout2()

qreal h = staff->height();
if (ni == visibleStaves.end()) {
ss->setYOff(staff->lines(0) == 1 ? _spatium * staff->mag(0) : 0.0);
// ss->setYOff(staff->lines(0) == 1 ? _spatium * staff->mag(0) : 0.0);
ss->setYOff(0.0);
ss->bbox().setRect(_leftMargin, y, width() - _leftMargin, h);
break;
}
Expand Down Expand Up @@ -466,7 +470,8 @@ void System::layout2()
}
#endif

ss->setYOff(staff->lines(0) == 1 ? _spatium * staff->mag(0) : 0.0);
// ss->setYOff(staff->lines(0) == 1 ? _spatium * staff->mag(0) : 0.0);
ss->setYOff(0.0);
ss->bbox().setRect(_leftMargin, y, width() - _leftMargin, h);
y += dist;
}
Expand Down Expand Up @@ -577,7 +582,7 @@ void System::layout2()
break;
}
// t->rypos() = y1 + (y2 - y1) * .5 + t->offset(t->spatium()).y();
t->rypos() = y1 + (y2 - y1) * .5;
t->rypos() = y1 + (y2 - y1 - t->bbox().height()) * .5;
}
}
staffIdx += nstaves;
Expand Down
18 changes: 13 additions & 5 deletions mscore/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "libmscore/shadownote.h"
#include "libmscore/repeatlist.h"
#include "libmscore/select.h"
#include "libmscore/staff.h"

namespace Ms {

Expand Down Expand Up @@ -318,10 +319,17 @@ void ScoreView::mousePressEventNormal(QMouseEvent* ev)
// special case: chacke if measure is selected
int staffIdx;
Measure* m = _score->pos2measure(editData.startMove, &staffIdx, 0, 0, 0);
if (m && m->staffLines(staffIdx)->canvasBoundingRect().contains(editData.startMove)) {
_score->select(m, st, staffIdx);
_score->setUpdateAll();
clickOffElement = false;
if (m) {
QRectF r = m->staffLines(staffIdx)->canvasBoundingRect();
if (_score->staff(staffIdx)->lines(m->tick()) == 1) {
r.setHeight(m->spatium() * 2);
r.translate(0.0, -m->spatium());
}
if (r.contains(editData.startMove)) {
_score->select(m, st, staffIdx);
_score->setUpdateAll();
clickOffElement = false;
}
}
else if (st != SelectType::ADD)
clickOffElement = true;
Expand All @@ -344,7 +352,7 @@ void ScoreView::mousePressEvent(QMouseEvent* ev)
editData.modifiers = qApp->keyboardModifiers();

Element* e = elementNear(editData.startMove);
// qDebug("element %s", e ? e->name() : "--");
// qDebug("element %s", e ? e->name() : "--");

switch (state) {
case ViewState::NORMAL:
Expand Down
2 changes: 1 addition & 1 deletion mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4204,7 +4204,7 @@ Element* ScoreView::elementNear(QPointF p)
qSort(ll.begin(), ll.end(), elementLower);

#if 0
qDebug("elementNear");
qDebug("==");
for (const Element* e : ll)
qDebug(" %s selected %d z %d", e->name(), e->selected(), e->z());
#endif
Expand Down

0 comments on commit d15d09a

Please sign in to comment.