Skip to content

Commit

Permalink
implement 'fixed' spacer
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Oct 12, 2016
1 parent 3c02b5e commit 2b44d04
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 82 deletions.
6 changes: 3 additions & 3 deletions libmscore/layout.cpp
Expand Up @@ -1791,7 +1791,7 @@ static void layoutPage(Page* page, qreal restHeight)
for (int i = 0; i < nsystems - 1; ++i) {
System* s1 = page->systems().at(i);
System* s2 = page->systems().at(i+1);
if (s1->vbox() || s2->vbox())
if (s1->vbox() || s2->vbox() || s1->hasFixedDownDistance())
continue;
++gaps;
}
Expand Down Expand Up @@ -1825,7 +1825,7 @@ static void layoutPage(Page* page, qreal restHeight)
for (int i = 0; i < nsystems - 1; ++i) {
System* s1 = page->systems().at(i);
System* s2 = page->systems().at(i+1);
if (!(s1->vbox() || s2->vbox())) {
if (!(s1->vbox() || s2->vbox() || s1->hasFixedDownDistance())) {
qreal dist = (s2->y() + yoff) - (s1->y() + s1->height());
qreal offset = stretch;
if (dist + stretch > maxDistance) { // limit stretch
Expand Down Expand Up @@ -3731,7 +3731,7 @@ bool Score::collectPage(LayoutContext& lc)
VBox* vbox = s3->vbox();
if (vbox)
dist += vbox->bottomGap();
else
else if (!s2->hasFixedDownDistance())
dist += qMax(s3->minBottom(), slb);
breakPage = (y + dist) >= ey;
}
Expand Down
74 changes: 62 additions & 12 deletions libmscore/measure.cpp
Expand Up @@ -613,11 +613,16 @@ void Measure::add(Element* e)

case Element::Type::SPACER:
{
Spacer* sp = static_cast<Spacer*>(e);
if (sp->spacerType() == SpacerType::UP)
_mstaves[e->staffIdx()]->_vspacerUp = sp;
else if (sp->spacerType() == SpacerType::DOWN)
_mstaves[e->staffIdx()]->_vspacerDown = sp;
Spacer* sp = toSpacer(e);
switch (sp->spacerType()) {
case SpacerType::UP:
_mstaves[e->staffIdx()]->_vspacerUp = sp;
break;
case SpacerType::DOWN:
case SpacerType::FIXED:
_mstaves[e->staffIdx()]->_vspacerDown = sp;
break;
}
}
break;
case Element::Type::SEGMENT:
Expand Down Expand Up @@ -689,16 +694,21 @@ void Measure::remove(Element* e)
Q_ASSERT(e->parent() == this);
Q_ASSERT(e->score() == score());

switch(e->type()) {
switch (e->type()) {
case Element::Type::TEXT:
_mstaves[e->staffIdx()]->setNoText(static_cast<Text*>(0));
break;

case Element::Type::SPACER:
if (toSpacer(e)->spacerType() == SpacerType::DOWN)
_mstaves[e->staffIdx()]->_vspacerDown = 0;
else if (toSpacer(e)->spacerType() == SpacerType::UP)
_mstaves[e->staffIdx()]->_vspacerUp = 0;
switch (toSpacer(e)->spacerType()) {
case SpacerType::DOWN:
case SpacerType::FIXED:
_mstaves[e->staffIdx()]->_vspacerDown = 0;
break;
case SpacerType::UP:
_mstaves[e->staffIdx()]->_vspacerUp = 0;
break;
}
break;

case Element::Type::SEGMENT:
Expand Down Expand Up @@ -1277,6 +1287,33 @@ Element* Measure::drop(const DropData& data)
Spacer* spacer = static_cast<Spacer*>(e);
spacer->setTrack(staffIdx * VOICES);
spacer->setParent(this);
if (spacer->spacerType() == SpacerType::FIXED) {
qreal gap = spatium() * 10;
System* s = system();
if (staffIdx == score()->nstaves()-1) {
System* ns = 0;
for (System* ts : score()->systems()) {
if (ns) {
ns = ts;
break;
}
if (ts == s)
ns = ts;
}
if (ns) {
qreal y1 = s->staffYpage(staffIdx);
qreal y2 = ns->staffYpage(0);
printf("=====%f %f\n", y1, y2);
gap = y2 - y1 - score()->staff(staffIdx)->height();
}
}
else {
qreal y1 = s->staffYpage(staffIdx);
qreal y2 = s->staffYpage(staffIdx+1);
gap = y2 - y1 - score()->staff(staffIdx)->height();
}
spacer->setGap(gap);
}
score()->undoAddElement(spacer);
return spacer;
}
Expand Down Expand Up @@ -1546,8 +1583,12 @@ void Measure::write(Xml& xml, int staff, bool writeSystemElements) const

if (mstaff->_vspacerUp)
xml.tag("vspacerUp", mstaff->_vspacerUp->gap() / _spatium);
if (mstaff->_vspacerDown)
xml.tag("vspacerDown", mstaff->_vspacerDown->gap() / _spatium);
if (mstaff->_vspacerDown) {
if (mstaff->_vspacerDown->spacerType() == SpacerType::FIXED)
xml.tag("vspacerFixed", mstaff->_vspacerDown->gap() / _spatium);
else
xml.tag("vspacerDown", mstaff->_vspacerDown->gap() / _spatium);
}
if (!mstaff->_visible)
xml.tag("visible", mstaff->_visible);
if (mstaff->_slashStyle)
Expand Down Expand Up @@ -1971,6 +2012,15 @@ void Measure::read(XmlReader& e, int staffIdx)
}
_mstaves[staffIdx]->_vspacerDown->setGap(e.readDouble() * _spatium);
}
else if (tag == "vspacerFixed") {
if (_mstaves[staffIdx]->_vspacerDown == 0) {
Spacer* spacer = new Spacer(score());
spacer->setSpacerType(SpacerType::FIXED);
spacer->setTrack(staffIdx * VOICES);
add(spacer);
}
_mstaves[staffIdx]->_vspacerDown->setGap(e.readDouble() * _spatium);
}
else if (tag == "vspacer" || tag == "vspacerUp") {
if (_mstaves[staffIdx]->_vspacerUp == 0) {
Spacer* spacer = new Spacer(score());
Expand Down
86 changes: 54 additions & 32 deletions libmscore/spacer.cpp
Expand Up @@ -31,8 +31,8 @@ Spacer::Spacer(Score* score)
Spacer::Spacer(const Spacer& s)
: Element(s)
{
_gap = s._gap;
path = s.path;
_gap = s._gap;
path = s.path;
_spacerType = s._spacerType;
}

Expand Down Expand Up @@ -64,23 +64,32 @@ void Spacer::layout0()
qreal b = w * .5;
qreal h = _gap;

if (spacerType() == SpacerType::DOWN) {
path.lineTo(w, 0.0);
path.moveTo(b, 0.0);
path.lineTo(b, h);
path.lineTo(0.0, h-b);
path.moveTo(b, h);
path.lineTo(w, h-b);
}
else if (spacerType() == SpacerType::UP) {
path.moveTo(b, 0.0);
path.lineTo(0.0, b);
path.moveTo(b, 0.0);
path.lineTo(w, b);
path.moveTo(b, 0.0);
path.lineTo(b, h);
path.moveTo(0.0, h);
path.lineTo(w, h);
switch (spacerType()) {
case SpacerType::DOWN:
path.lineTo(w, 0.0);
path.moveTo(b, 0.0);
path.lineTo(b, h);
path.lineTo(0.0, h-b);
path.moveTo(b, h);
path.lineTo(w, h-b);
break;
case SpacerType::UP:
path.moveTo(b, 0.0);
path.lineTo(0.0, b);
path.moveTo(b, 0.0);
path.lineTo(w, b);
path.moveTo(b, 0.0);
path.lineTo(b, h);
path.moveTo(0.0, h);
path.lineTo(w, h);
break;
case SpacerType::FIXED:
path.lineTo(w, 0.0);
path.moveTo(b, 0.0);
path.lineTo(b, h);
path.moveTo(0.0, h);
path.lineTo(w, h);
break;
}
qreal lw = _spatium * 0.4;
QRectF bb(0, 0, w, h);
Expand Down Expand Up @@ -115,10 +124,16 @@ void Spacer::spatiumChanged(qreal ov, qreal nv)
void Spacer::editDrag(const EditData& ed)
{
qreal s = ed.delta.y();
if (spacerType() == SpacerType::DOWN)
_gap += s;
else if (spacerType() == SpacerType::UP)
_gap -= s;

switch (spacerType()) {
case SpacerType::DOWN:
case SpacerType::FIXED:
_gap += s;
break;
case SpacerType::UP:
_gap -= s;
break;
}
if (_gap < spatium() * 2.0)
_gap = spatium() * 2;
layout0();
Expand All @@ -134,10 +149,15 @@ void Spacer::updateGrips(Grip* defaultGrip, QVector<QRectF>& grip) const
*defaultGrip = Grip::START;
qreal _spatium = spatium();
QPointF p;
if (spacerType() == SpacerType::DOWN)
p = QPointF(_spatium * .5, _gap);
else if (spacerType() == SpacerType::UP)
p = QPointF(_spatium * .5, 0.0);
switch (spacerType()) {
case SpacerType::DOWN:
case SpacerType::FIXED:
p = QPointF(_spatium * .5, _gap);
break;
case SpacerType::UP:
p = QPointF(_spatium * .5, 0.0);
break;
}
grip[0].translate(pagePos() + p);
}

Expand Down Expand Up @@ -178,8 +198,9 @@ void Spacer::read(XmlReader& e)

QVariant Spacer::getProperty(P_ID propertyId) const
{
switch(propertyId) {
case P_ID::SPACE: return gap();
switch (propertyId) {
case P_ID::SPACE:
return gap();
default:
return Element::getProperty(propertyId);
}
Expand All @@ -191,7 +212,7 @@ QVariant Spacer::getProperty(P_ID propertyId) const

bool Spacer::setProperty(P_ID propertyId, const QVariant& v)
{
switch(propertyId) {
switch (propertyId) {
case P_ID::SPACE:
setGap(v.toDouble());
break;
Expand All @@ -212,8 +233,9 @@ bool Spacer::setProperty(P_ID propertyId, const QVariant& v)

QVariant Spacer::propertyDefault(P_ID id) const
{
switch(id) {
case P_ID::SPACE: return QVariant(0.0);
switch (id) {
case P_ID::SPACE:
return QVariant(0.0);
default:
return Element::propertyDefault(id);
}
Expand Down
2 changes: 1 addition & 1 deletion libmscore/spacer.h
Expand Up @@ -24,7 +24,7 @@ namespace Ms {
//---------------------------------------------------------

enum class SpacerType : char {
UP, DOWN
UP, DOWN, FIXED
};

//-------------------------------------------------------------------
Expand Down
81 changes: 49 additions & 32 deletions libmscore/system.cpp
Expand Up @@ -398,8 +398,14 @@ void System::layout2()
dist = qMax(dist, d);

Spacer* sp = m->mstaff(si1)->_vspacerDown;
if (sp)
dist = qMax(dist, staff->height() + sp->gap());
if (sp) {
if (sp->spacerType() == SpacerType::FIXED) {
dist = staff->height() + sp->gap();
break;
}
else
dist = qMax(dist, staff->height() + sp->gap());
}
sp = m->mstaff(si2)->_vspacerUp;
if (sp)
dist = qMax(dist, sp->gap());
Expand Down Expand Up @@ -1024,46 +1030,57 @@ qreal System::minDistance(System* s2) const
qreal dist = score()->styleP(StyleIdx::minSystemDistance);
int lastStaff = _staves.size() - 1;

fixedDownDistance = false;

for (MeasureBase* mb1 : ml) {
if (mb1->isMeasure()) {
Measure* m = toMeasure(mb1);
Q_ASSERT(!m->mstaves().empty());
Spacer* sp = m->mstaves().back()->_vspacerDown;
if (sp)
dist = qMax(dist, sp->gap());
if (sp) {
if (sp->spacerType() == SpacerType::FIXED) {
dist = sp->gap();
fixedDownDistance = true;
break;
}
else
dist = qMax(dist, sp->gap());
}
}
}
for (MeasureBase* mb2 : s2->ml) {
if (mb2->isMeasure()) {
Measure* m = toMeasure(mb2);
Q_ASSERT(!m->mstaves().empty());
Spacer* sp = m->mstaves().front()->_vspacerUp;
if (sp)
dist = qMax(dist, sp->gap());
if (!fixedDownDistance) {
for (MeasureBase* mb2 : s2->ml) {
if (mb2->isMeasure()) {
Measure* m = toMeasure(mb2);
Q_ASSERT(!m->mstaves().empty());
Spacer* sp = m->mstaves().front()->_vspacerUp;
if (sp)
dist = qMax(dist, sp->gap());
}
}
}

for (MeasureBase* mb1 : ml) {
if (!mb1->isMeasure())
continue;
Measure* m1 = toMeasure(mb1);
qreal bx1 = m1->x();
qreal bx2 = m1->x() + m1->width();

for (MeasureBase* mb2 : s2->measures()) {
if (!mb2->isMeasure())
continue;
Measure* m2 = toMeasure(mb2);
qreal ax1 = mb2->x();
if (ax1 >= bx2)
break;
qreal ax2 = mb2->x() + mb2->width();
if (ax2 < bx1)
for (MeasureBase* mb1 : ml) {
if (!mb1->isMeasure())
continue;
Shape s1 = m1->staffShape(lastStaff).translated(m1->pos());
Shape s2 = m2->staffShape(0).translated(m2->pos());
qreal d = s1.minVerticalDistance(s2) + minVerticalDistance;
dist = qMax(dist, d - m1->mstaff(lastStaff)->lines->height());
Measure* m1 = toMeasure(mb1);
qreal bx1 = m1->x();
qreal bx2 = m1->x() + m1->width();

for (MeasureBase* mb2 : s2->measures()) {
if (!mb2->isMeasure())
continue;
Measure* m2 = toMeasure(mb2);
qreal ax1 = mb2->x();
if (ax1 >= bx2)
break;
qreal ax2 = mb2->x() + mb2->width();
if (ax2 < bx1)
continue;
Shape s1 = m1->staffShape(lastStaff).translated(m1->pos());
Shape s2 = m2->staffShape(0).translated(m2->pos());
qreal d = s1.minVerticalDistance(s2) + minVerticalDistance;
dist = qMax(dist, d - m1->mstaff(lastStaff)->lines->height());
}
}
}
return dist;
Expand Down

0 comments on commit 2b44d04

Please sign in to comment.