Skip to content

Commit

Permalink
Layout reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Apr 13, 2016
1 parent a65f06b commit 9f933d8
Show file tree
Hide file tree
Showing 110 changed files with 4,595 additions and 6,160 deletions.
1 change: 1 addition & 0 deletions libmscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ add_library (
synthesizerstate.cpp mcursor.cpp groups.cpp mscoreview.cpp
noteline.cpp spannermap.cpp
bagpembell.cpp ambitus.cpp keylist.cpp scoreElement.cpp
shape.cpp
)

set_target_properties (
Expand Down
3 changes: 1 addition & 2 deletions libmscore/accidental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ void Accidental::layout()

QRectF r;
// don't show accidentals for tab or slash notation
if ((staff() && staff()->isTabStaff())
|| (note() && note()->fixed())) {
if ((staff() && staff()->isTabStaff()) || (note() && note()->fixed())) {
setbbox(r);
return;
}
Expand Down
15 changes: 0 additions & 15 deletions libmscore/ambitus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,21 +438,6 @@ void Ambitus::draw(QPainter* p) const
}
}

//---------------------------------------------------------
// space
//---------------------------------------------------------

Space Ambitus::space() const
{
qreal _spatium = spatium();
// reduce left space if there accidentals
qreal leftSpace = _spatium *
((_topAccid.accidentalType() != AccidentalType::NONE
|| _bottomAccid.accidentalType() != AccidentalType::NONE)
? 0.5 : 0.75);
return Space(leftSpace - bbox().x(), width() + bbox().x() + _spatium * 0.5);
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion libmscore/ambitus.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Ambitus : public Element {
virtual void read(XmlReader&) override;
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
virtual void setTrack(int val) override;
virtual Space space() const override;
virtual void write(Xml&) const override;
virtual QString accessibleInfo() override;
virtual QString screenReaderInfo() override;
Expand Down
4 changes: 2 additions & 2 deletions libmscore/arpeggio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ void Arpeggio::symbolLine(SymId end, SymId fill)
ScoreFont* f = score()->scoreFont();

symbols.clear();
symbols.append(end);
symbols.push_back(end);
qreal w1 = f->advance(end, mag);
qreal w2 = f->advance(fill, mag);
int n = lrint((w - w1) / w2);
for (int i = 0; i < n; ++i)
symbols.prepend(fill);
symbols.push_back(fill);
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/arpeggio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Arpeggio : public Element {
qreal _userLen2;
qreal _height;
int _span; // spanning staves
QList<SymId> symbols;
std::vector<SymId> symbols;
bool _playArpeggio;

void symbolLine(SymId start, SymId fill);
Expand Down
4 changes: 4 additions & 0 deletions libmscore/articulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ void Articulation::setArticulationType(ArticulationType idx)
anchorStyle = PropertyStyle::STYLED;
_timeStretch = articulationList[int(articulationType())].timeStretch;

// TODO: layout() can be empty?
SymId sym = _up ? articulationList[int(_articulationType)].upSym : articulationList[int(_articulationType)].downSym;
QRectF b(symBbox(sym));
setbbox(b.translated(-0.5 * b.width(), 0.0));
}

//---------------------------------------------------------
Expand Down
140 changes: 73 additions & 67 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ void BarLine::getY(qreal* y1, qreal* y2) const
qDebug("BarLine: bad _span %d", _span);
staffIdx2 = score()->nstaves() - 1;
}
Measure* measure;
Measure* measure = 0;
System* system;
SysStaff* sysStaff0 = nullptr; // top staff for barline in system
SysStaff* sysStaff0 = 0; // top staff for barline in system
bool systemBarLine;
if (parent()->type() == Element::Type::SEGMENT) {
Segment* segment = static_cast<Segment*>(parent());
Expand Down Expand Up @@ -242,35 +242,38 @@ void BarLine::getY(qreal* y1, qreal* y2) const
int nstaves = score()->nstaves();
Staff* staff1 = score()->staff(staffIdx1);
Staff* staff2 = score()->staff(staffIdx2);
SysStaff* sysStaff1 = system->staff(staffIdx1);
SysStaff* sysStaff2 = system->staff(staffIdx2);
SysStaff* sysStaff1a = nullptr; // first staff that is shown, even if it has invisible measures
Measure* nm = measure->nextMeasure();
if (nm && nm->system() != measure->system())
nm = nullptr;
while (span > 0) {
bool show1 = sysStaff1->show() && staff1->show();
// if start staff not shown, reduce span and move one staff down
if (!(show1 && (measure->visible(staffIdx1) || (nm && nm->visible(staffIdx1))))) {
span--;
if (show1 && !sysStaff1a)
sysStaff1a = sysStaff1; // use for its y offset
if (staffIdx1 >= nstaves-1) // running out of staves?
break;
sysStaff1 = system->staff(++staffIdx1);
staff1 = score()->staff(staffIdx1);
}
// if end staff not shown, reduce span and move one staff up
else if (!(sysStaff2->show() && staff2->show() && (measure->visible(staffIdx2) || (nm && nm->visible(staffIdx2))))) {
span--;
if (staffIdx2 == 0)
SysStaff* sysStaff1 = 0;
SysStaff* sysStaff1a = 0; // first staff that is shown, even if it has invisible measures
if (system) {
sysStaff1 = system->staff(staffIdx1);
SysStaff* sysStaff2 = system->staff(staffIdx2);
Measure* nm = measure->nextMeasure();
if (nm && nm->system() != measure->system())
nm = nullptr;
while (span > 0) {
bool show1 = sysStaff1->show() && staff1->show();
// if start staff not shown, reduce span and move one staff down
if (!(show1 && (measure->visible(staffIdx1) || (nm && nm->visible(staffIdx1))))) {
span--;
if (show1 && !sysStaff1a)
sysStaff1a = sysStaff1; // use for its y offset
if (staffIdx1 >= nstaves-1) // running out of staves?
break;
sysStaff1 = system->staff(++staffIdx1);
staff1 = score()->staff(staffIdx1);
}
// if end staff not shown, reduce span and move one staff up
else if (!(sysStaff2->show() && staff2->show() && (measure->visible(staffIdx2) || (nm && nm->visible(staffIdx2))))) {
span--;
if (staffIdx2 == 0)
break;
sysStaff2 = system->staff(--staffIdx2);
staff2 = score()->staff(staffIdx2);
}
// if both staves shown, exit loop
else
break;
sysStaff2 = system->staff(--staffIdx2);
staff2 = score()->staff(staffIdx2);
}
// if both staves shown, exit loop
else
break;
}
// if no longer any span, set 0 length and exit
if (span <= 0) {
Expand Down Expand Up @@ -568,9 +571,9 @@ void BarLine::read(XmlReader& e)
_barLineType = ct; // set type directly, without triggering setBarLineType() checks
}
if (parent() && parent()->type() == Element::Type::SEGMENT) {
Measure* m = static_cast<Segment*>(parent())->measure();
if (barLineType() != m->endBarLineType())
_customSubtype = true;
// Measure* m = static_cast<Segment*>(parent())->measure();
// if (barLineType() != m->endBarLineType())
// _customSubtype = true;
}
}
else if (tag == "customSubtype")
Expand Down Expand Up @@ -603,15 +606,6 @@ void BarLine::read(XmlReader& e)
}
}

//---------------------------------------------------------
// space
//---------------------------------------------------------

Space BarLine::space() const
{
return Space(0.0, width());
}

//---------------------------------------------------------
// acceptDrop
//---------------------------------------------------------
Expand Down Expand Up @@ -702,7 +696,7 @@ Element* BarLine::drop(const DropData& data)
return 0;
}
}
score()->undoChangeBarLine(m, bl->barLineType());
//TODO score()->undoChangeBarLine(m, bl->barLineType());
delete e;
return 0;
}
Expand Down Expand Up @@ -842,33 +836,34 @@ void BarLine::endEdit()
if (_span > staff()->barLineSpan()) {
int idx2 = idx1 + _span;
// set span 0 to all additional staves
for (int idx = idx1 + 1; idx < idx2; ++idx)
for (int idx = idx1 + 1; idx < idx2; ++idx) {
// Mensurstrich special case:
// if line spans to top line of a stave AND current staff is
// the last spanned staff BUT NOT the last score staff
// keep its bar lines
// otherwise remove them
if (_spanTo > 0 || !(idx == idx2-1 && idx != score()->nstaves()-1) )
score()->undoChangeBarLineSpan(score()->staff(idx), 0, 0,
(score()->staff(idx)->lines()-1)*2);
//TODO if (_spanTo > 0 || !(idx == idx2-1 && idx != score()->nstaves()-1) )
// score()->undoChangeBarLineSpan(score()->staff(idx), 0, 0,
// (score()->staff(idx)->lines()-1)*2);
}
}
// if now bar lines span fewer staves
else {
int idx1 = staffIdx() + _span;
int idx2 = staffIdx() + staff()->barLineSpan();
// set standard span for each no-longer-spanned staff
for (int idx = idx1; idx < idx2; ++idx) {
Staff* staff = score()->staff(idx);
int lines = staff->lines();
int spanFrom = lines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0;
int spanTo = lines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (lines - 1) * 2;
score()->undoChangeBarLineSpan(staff, 1, spanFrom, spanTo);
// Staff* staff = score()->staff(idx);
// int lines = staff->lines();
// int spanFrom = lines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0;
// int spanTo = lines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (lines - 1) * 2;
//TODO score()->undoChangeBarLineSpan(staff, 1, spanFrom, spanTo);
}
}
}

// update span for the staff the edited bar line belongs to
score()->undoChangeBarLineSpan(staff(), _span, _spanFrom, _spanTo);
//TODO score()->undoChangeBarLineSpan(staff(), _span, _spanFrom, _spanTo);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1063,8 +1058,8 @@ void BarLine::layout()
qreal y1, y2;
getY(&y1, &y2);

// if bar line does not belong to a system, has a staff and staff is set to hide bar lines, set null bbox
if (parent() && parent()->type() != Element::Type::SYSTEM && staff() && !staff()->staffType()->showBarlines())
// if bar line has a staff and staff is set to hide bar lines, set null bbox
if (staff() && !staff()->staffType()->showBarlines())
setbbox(QRectF());

// bar lines not hidden
Expand Down Expand Up @@ -1109,7 +1104,7 @@ void BarLine::layout()
}

// in any case, lay out attached elements
foreach (Element* e, _el) {
for (Element* e : _el) {
e->layout();
if (e->type() == Element::Type::ARTICULATION) {
Articulation* a = static_cast<Articulation*>(e);
Expand All @@ -1132,7 +1127,7 @@ void BarLine::layout()
// shape
//---------------------------------------------------------

QPainterPath BarLine::shape() const
QPainterPath BarLine::outline() const
{
QPainterPath p;
qreal d = spatium() * .3;
Expand Down Expand Up @@ -1175,14 +1170,21 @@ QString BarLine::barLineTypeName(BarLineType t)
//---------------------------------------------------------

void BarLine::setBarLineType(const QString& s)
{
_barLineType = barLineType(s);
}

//---------------------------------------------------------
// barLineType
//---------------------------------------------------------

BarLineType BarLine::barLineType(const QString& s)
{
for (unsigned i = 0; i < sizeof(barLineNames)/sizeof(*barLineNames); ++i) {
if (barLineNames[i] == s) {
_barLineType = BarLineType(i);
return;
}
if (barLineNames[i] == s)
return BarLineType(i);
}
_barLineType = BarLineType::NORMAL;
return BarLineType::NORMAL; // silent default
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1214,8 +1216,8 @@ void BarLine::add(Element* e)
case Element::Type::ARTICULATION:
_el.push_back(e);
setGenerated(false);
if (parent() && parent()->parent())
static_cast<Measure*>(parent()->parent())->setEndBarLineGenerated(false);
// if (parent() && parent()->parent())
// static_cast<Measure*>(parent()->parent())->setEndBarLineGenerated(false);
break;
default:
qDebug("BarLine::add() not impl. %s", e->name());
Expand Down Expand Up @@ -1288,7 +1290,7 @@ void BarLine::updateCustomType()
break;
case Segment::Type::EndBarLine:
// if end-measure bar line, reference type is the measure endBarLinetype
refType = seg->measure()->endBarLineType();
//TODO refType = seg->measure()->endBarLineType();
break;
default: // keep lint happy!
break;
Expand Down Expand Up @@ -1317,6 +1319,7 @@ void BarLine::updateCustomType()

void BarLine::updateGenerated(bool canBeTrue)
{
#if 0 // TODO
if (!canBeTrue)
setGenerated(false);
else {
Expand Down Expand Up @@ -1344,6 +1347,7 @@ void BarLine::updateGenerated(bool canBeTrue)
&& !isNudged()
);
}
#endif
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1399,12 +1403,14 @@ bool BarLine::setProperty(P_ID id, const QVariant& v)

QVariant BarLine::propertyDefault(P_ID propertyId) const
{
switch(propertyId) {
switch (propertyId) {
case P_ID::SUBTYPE:
// default subtype is the subtype of the measure, if any
if (parent() && parent()->type() == Element::Type::SEGMENT && static_cast<Segment*>(parent())->measure() )
return int(static_cast<Segment*>(parent())->measure()->endBarLineType());

//TODO? if (parent() && parent()->type() == Element::Type::SEGMENT && static_cast<Segment*>(parent())->measure() )
// return int(static_cast<Segment*>(parent())->measure()->endBarLineType());
return int(BarLineType::NORMAL);

case P_ID::BARLINE_SPAN:
// if there is a staff, default span is staff span
if (staff())
Expand Down
5 changes: 2 additions & 3 deletions libmscore/barline.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ class BarLine : public Element {
virtual void write(Xml& xml) const override;
virtual void read(XmlReader&) override;
virtual void draw(QPainter*) const override;
virtual Space space() const override;
virtual QPointF pagePos() const override; ///< position in canvas coordinates
virtual QPointF canvasPos() const override; ///< position in canvas coordinates
virtual void layout() override;
virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
virtual void add(Element*) override;
virtual void remove(Element*) override;
virtual QPainterPath shape() const override;
virtual QPainterPath outline() const override;

virtual bool acceptDrop(const DropData&) const override;
virtual Element* drop(const DropData&) override;
Expand All @@ -114,7 +113,6 @@ class BarLine : public Element {
int spanFrom() const { return _spanFrom; }
int spanTo() const { return _spanTo; }

virtual bool isEditable() const override { return parent()->type() == Element::Type::SEGMENT; }
virtual void startEdit(MuseScoreView*, const QPointF&) override;
virtual void endEdit() override;
virtual void editDrag(const EditData&) override;
Expand All @@ -136,6 +134,7 @@ class BarLine : public Element {
void setBarLineType(const QString& s);
void setBarLineType(BarLineType i) { _barLineType = i; updateCustomType(); }
BarLineType barLineType() const { return _barLineType; }
static BarLineType barLineType(const QString&);

virtual int subtype() const override { return int(_barLineType); }
virtual QString subtypeName() const override { return qApp->translate("barline", barLineTypeName().toUtf8()); }
Expand Down
Loading

0 comments on commit 9f933d8

Please sign in to comment.