diff --git a/libmscore/barline.cpp b/libmscore/barline.cpp index 3069ed89d3..f30b2f9c87 100644 --- a/libmscore/barline.cpp +++ b/libmscore/barline.cpp @@ -33,7 +33,9 @@ qreal BarLine::yoff2 = 0.0; bool BarLine::ctrlDrag = false; bool BarLine::shiftDrag = false; -int BarLine::_origSpan, BarLine::_origSpanFrom, BarLine::_origSpanTo; +int BarLine::_origSpan; +int BarLine::_origSpanFrom; +int BarLine::_origSpanTo; //--------------------------------------------------------- // BarLineTable @@ -130,44 +132,13 @@ BarLine::BarLine(Score* s) setHeight(DEFAULT_BARLINE_TO/2 * spatium()); // for use in palettes } -//--------------------------------------------------------- -// setSpan -//--------------------------------------------------------- - -void BarLine::setSpan(int val) - { - _span = val; - updateCustomSpan(); - } - -//--------------------------------------------------------- -// setSpanFrom -//--------------------------------------------------------- - -void BarLine::setSpanFrom(int val) - { - _spanFrom = val; - updateCustomSpan(); - } - -//--------------------------------------------------------- -// setSpanTo -//--------------------------------------------------------- - -void BarLine::setSpanTo(int val) - { - _spanTo = val; - updateCustomSpan(); - } - //--------------------------------------------------------- // mag //--------------------------------------------------------- qreal BarLine::mag() const { - qreal m = staff() ? staff()->mag() : 1.0; - return m; + return staff() ? staff()->mag() : 1.0; } //--------------------------------------------------------- @@ -202,24 +173,6 @@ QPointF BarLine::pagePos() const return QPointF(pageX(), yp); } -//--------------------------------------------------------- -// canvasPos -//--------------------------------------------------------- - -QPointF BarLine::canvasPos() const - { - QPointF p(pagePos()); - Element* e = parent(); - while (e) { - if (e->type() == Element::Type::PAGE) { - p += e->pos(); - break; - } - e = e->parent(); - } - return p; - } - //--------------------------------------------------------- // getY //--------------------------------------------------------- @@ -537,20 +490,18 @@ void BarLine::write(Xml& xml) const { xml.stag("BarLine"); xml.tag("subtype", barLineTypeName()); - if (_customSubtype) - xml.tag("customSubtype", _customSubtype); + // if any span value is different from staff's, output all values - if ( (staff() && ( _span != staff()->barLineSpan() - || _spanFrom != staff()->barLineFrom() - || _spanTo != staff()->barLineTo() - ) - ) - || !staff()) // (palette bar lines have no staff: output all values) + // (palette bar lines have no staff: output all values) + + if (!staff() + || custom(P_ID::BARLINE_SPAN) + || custom(P_ID::BARLINE_SPAN_FROM) + || custom(P_ID::BARLINE_SPAN_TO)) xml.tag(QString("span from=\"%1\" to=\"%2\"").arg(_spanFrom).arg(_spanTo), _span); - // if no custom value, output _span only (as in previous code) else xml.tag("span", _span); - foreach(const Element* e, _el) + for (const Element* e : _el) e->write(xml); Element::writeProperties(xml); xml.etag(); @@ -562,58 +513,22 @@ void BarLine::write(Xml& xml) const void BarLine::read(XmlReader& e) { - // if bar line belongs to a staff, span values default to staff values - if (staff()) { - _span = staff()->barLineSpan(); - _spanFrom = staff()->barLineFrom(); - _spanTo = staff()->barLineTo(); - } + resetProperty(P_ID::BARLINE_SPAN); + resetProperty(P_ID::BARLINE_SPAN_FROM); + resetProperty(P_ID::BARLINE_SPAN_TO); + while (e.readNextStartElement()) { const QStringRef& tag(e.name()); - if (tag == "subtype") { - bool ok; - const QString& val(e.readElementText()); - int i = val.toInt(&ok); - if (!ok) - setBarLineType(val); - else { - BarLineType ct = BarLineType::NORMAL; - switch (i) { - default: - case 0: ct = BarLineType::NORMAL; break; - case 1: ct = BarLineType::DOUBLE; break; - case 2: ct = BarLineType::START_REPEAT; break; - case 3: ct = BarLineType::END_REPEAT; break; - case 4: ct = BarLineType::BROKEN; break; - case 5: ct = BarLineType::END; break; - case 6: ct = BarLineType::END_START_REPEAT; break; - case 7: ct = BarLineType::DOTTED; break; - } - _barLineType = ct; // set type directly, without triggering setBarLineType() checks - } -// Measure* m = segment()->measure(); -// if (barLineType() != m->endBarLineType()) -// _customSubtype = true; - } + if (tag == "subtype") + setBarLineType(e.readElementText()); else if (tag == "customSubtype") - _customSubtype = e.readInt(); + /* _customSubtype =*/ e.readInt(); else if (tag == "span") { _spanFrom = e.intAttribute("from", _spanFrom); _spanTo = e.intAttribute("to", _spanTo); _span = e.readInt(); - if (_spanTo == UNKNOWN_BARLINE_TO) - _spanTo = staff() ? (staff()->lines() - 1) * 2 : 8; - - // WARNING: following statements assume staff and staff bar line spans are correctly set - // ws: _spanTo can be UNKNOWN_BARLINE_TO - - if (staff() && (_span != staff()->barLineSpan() - || _spanFrom != staff()->barLineFrom() - || ((staff()->barLineTo() != UNKNOWN_BARLINE_TO) && (_spanTo != staff()->barLineTo()))) - ) { - _customSpan = true; - } + resetProperty(P_ID::BARLINE_SPAN_TO); } else if (tag == "Articulation") { Articulation* a = new Articulation(score()); @@ -788,9 +703,6 @@ void BarLine::endEdit() ctrlDrag = false; return; } - // if bar line has custom span, assume any span edit is local to this bar line - if (_customSpan == true) - ctrlDrag = true; // for mid-measure barlines, edit is local bool midMeasure = false; if (segment()->isBarLine()) { @@ -799,8 +711,6 @@ void BarLine::endEdit() } if (ctrlDrag) { // if single bar line edit - ctrlDrag = false; - _customSpan = true; // mark bar line as custom spanning int newSpan = _span; // copy edited span values int newSpanFrom = _spanFrom; int newSpanTo = _spanTo; @@ -1015,8 +925,7 @@ void BarLine::endEditDrag() if (newSpanTo > maxTo) newSpanTo = maxTo; } -// shiftDrag = false; // NO: a last call to this function is made when exiting editing: - } // it would find shiftDrag = false and reset extrema to coarse resolution + } else { // if coarse dragging newSpanFrom = Staff1lines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM: 0; @@ -1163,15 +1072,6 @@ QPainterPath BarLine::outline() const return p; } -//--------------------------------------------------------- -// tick -//--------------------------------------------------------- - -int BarLine::tick() const - { - return segment()->tick(); - } - //--------------------------------------------------------- // scanElements //--------------------------------------------------------- @@ -1222,93 +1122,6 @@ void BarLine::remove(Element* e) } } -//--------------------------------------------------------- -// updateCustomSpan -//--------------------------------------------------------- - -void BarLine::updateCustomSpan() - { - // span is custom if barline belongs to a staff and any of the staff span params is different from barline's - // if no staff or same span params as staff, span is not custom - Staff* stf = staff(); - if (!stf) - _customSpan = false; - else - _customSpan = stf->barLineSpan() != _span || stf->barLineFrom() != _spanFrom || stf->barLineTo() != _spanTo; - updateGenerated(!_customSpan); - } - -//--------------------------------------------------------- -// updateCustomType -// -// Turns off _customSubtype flag if bar line type is the same of the context it is in -// (usually the endBarLineType of the measure); turns it on otherwise. -//--------------------------------------------------------- - -void BarLine::updateCustomType() - { - BarLineType refType = BarLineType::NORMAL; - if (segment()) { - switch (segment()->segmentType()) { - case Segment::Type::StartRepeatBarLine: - // if a start-repeat segment, ref. type is START_REPEAT - // if measure has relevant repeat flag or none if measure hasn't - refType = segment()->measure()->repeatStart() ? BarLineType::START_REPEAT : BarLineType(-1); - break; - case Segment::Type::BarLine: - // if a non-end-measure bar line, type is always custom - refType = BarLineType(-1); // use an invalid type - break; - case Segment::Type::EndBarLine: - // if end-measure bar line, reference type is the measure endBarLinetype -//TODO refType = seg->measure()->endBarLineType(); - break; - default: // keep lint happy! - break; - } - } - _customSubtype = (_barLineType != refType); - updateGenerated(!_customSubtype); // if _customSubType, _generated is surely false - } - -//--------------------------------------------------------- -// updateGenerated -// -// Sets the _generated status flag by checking all the bar line properties are at default values. -// -// canBeTrue: optional parameter; if set to false, the _generated flag is unconditionally set to false -// without checking the individual properties; to be used when a non-default condition is already known -// to speed up the function. -//--------------------------------------------------------- - -void BarLine::updateGenerated(bool canBeTrue) - { -#if 0 // TODO - if (!canBeTrue) - setGenerated(false); - else { - bool generatedType = !_customSubtype; // if customSubType, assume not generated - if (segment()) { - // if bar line belongs to an EndBarLine segment, - // combine with measure endBarLineGenerated flag - if (segment()->isEndBarLine()) - generatedType &= segment()->measure()->endBarLineGenerated(); - else - // if any other segment (namely, StartBarLine and BarLine), bar line is not generated - generatedType = false; - } - // set to generated only if all properties are non-customized - setGenerated( - color() == MScore::defaultColor - && _visible == true - && generatedType == true - && _customSpan == false - && !isNudged() - ); - } -#endif - } - //--------------------------------------------------------- // getProperty //--------------------------------------------------------- @@ -1352,6 +1165,7 @@ bool BarLine::setProperty(P_ID id, const QVariant& v) default: return Element::setProperty(id, v); } + setGenerated(false); score()->setLayoutAll(true); return true; } @@ -1369,23 +1183,20 @@ QVariant BarLine::propertyDefault(P_ID propertyId) const return int(BarLineType::NORMAL); case P_ID::BARLINE_SPAN: - // if there is a staff, default span is staff span if (staff()) return staff()->barLineSpan(); - // if no staff, default span is 1 return 1; + case P_ID::BARLINE_SPAN_FROM: - // if there is a staff, default From span is staff From span if (staff()) return staff()->barLineFrom(); - // if no staff, default From is from top return 0; + case P_ID::BARLINE_SPAN_TO: - // if there is a staff, default To span is staff To span if (staff()) return staff()->barLineTo(); - // if no staff, assume a standard 5-line setup return DEFAULT_BARLINE_TO; + default: break; } @@ -1442,7 +1253,7 @@ QString BarLine::accessibleExtraInfo() const } Measure* m = seg->measure(); - if (m) { // always true? + if (m) { // always true? //jumps for (const Element* e : m->el()) { if (!score()->selectionFilter().canSelect(e)) continue; diff --git a/libmscore/barline.h b/libmscore/barline.h index dbf575f2f2..fe1ef7c63d 100644 --- a/libmscore/barline.h +++ b/libmscore/barline.h @@ -22,13 +22,13 @@ namespace Ms { class MuseScoreView; class Segment; -static const int DEFAULT_BARLINE_TO = 4 * 2; -static const int MIN_BARLINE_FROMTO_DIST = 2; -static const int MIN_BARLINE_SPAN_FROMTO = -2; +static const int DEFAULT_BARLINE_TO = 4 * 2; +static const int MIN_BARLINE_FROMTO_DIST = 2; +static const int MIN_BARLINE_SPAN_FROMTO = -2; // bar line span for 1-line staves is special: goes from 2sp above the line to 2sp below the line; -static const int BARLINE_SPAN_1LINESTAFF_FROM = -4; -static const int BARLINE_SPAN_1LINESTAFF_TO = 4; +static const int BARLINE_SPAN_1LINESTAFF_FROM = -4; +static const int BARLINE_SPAN_1LINESTAFF_TO = 4; // data for some preset bar line span types static const int BARLINE_SPAN_TICK1_FROM = -1; @@ -43,7 +43,7 @@ static const int BARLINE_SPAN_SHORT2_TO = 7; // used while reading a score for a default spanTo (to last staff line) toward a staff not yet read; // fixed once all staves are read -static const int UNKNOWN_BARLINE_TO = -6; +static const int UNKNOWN_BARLINE_TO = -6; //--------------------------------------------------------- // BarLineTableItem @@ -63,10 +63,8 @@ class BarLine : public Element { Q_OBJECT BarLineType _barLineType { BarLineType::NORMAL }; - bool _customSpan { false }; - bool _customSubtype { false }; - int _span { 1 }; // number of staves spanned by the barline - int _spanFrom { 0 }; // line number on start and end staves + int _span { 1 }; // number of staves spanned by the barline + int _spanFrom { 0 }; // line number on start and end staves int _spanTo { DEFAULT_BARLINE_TO }; // static variables used while dragging @@ -79,9 +77,6 @@ class BarLine : public Element { ElementList _el; ///< fermata or other articulations void drawDots(QPainter* painter, qreal x) const; - void updateCustomSpan(); - void updateCustomType(); - void updateGenerated(bool canBeTrue = true); public: BarLine(Score*); @@ -93,7 +88,6 @@ class BarLine : public Element { virtual void read(XmlReader&) override; virtual void draw(QPainter*) 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; @@ -103,15 +97,11 @@ class BarLine : public Element { virtual bool acceptDrop(const DropData&) const override; virtual Element* drop(const DropData&) override; - Segment* segment() const { return (Segment*)parent(); } + Segment* segment() const { return (Segment*)parent(); } - void setCustomSpan(bool val) { _customSpan = val; } - void setCustomSubtype(bool val) { _customSubtype = val; } - void setSpan(int val); - void setSpanFrom(int val); - void setSpanTo(int val); - bool customSpan() const { return _customSpan; } - bool customSubtype() const { return _customSubtype;} + void setSpan(int val) { _span = val; } + void setSpanFrom(int val) { _spanFrom = val; } + void setSpanTo(int val) { _spanTo = val; } int span() const { return _span; } int spanFrom() const { return _spanFrom; } int spanTo() const { return _spanTo; } @@ -123,8 +113,6 @@ class BarLine : public Element { virtual void updateGrips(Grip*, QVector&) const override; virtual int grips() const override { return 2; } - int tick() const; - ElementList* el() { return &_el; } const ElementList* el() const { return &_el; } @@ -134,7 +122,7 @@ class BarLine : public Element { QString barLineTypeName() const; static QString barLineTypeName(BarLineType t); void setBarLineType(const QString& s); - void setBarLineType(BarLineType i) { _barLineType = i; updateCustomType(); } + void setBarLineType(BarLineType i) { _barLineType = i; } BarLineType barLineType() const { return _barLineType; } static BarLineType barLineType(const QString&); diff --git a/libmscore/edit.cpp b/libmscore/edit.cpp index fb4a2b2a63..18052b8cf4 100644 --- a/libmscore/edit.cpp +++ b/libmscore/edit.cpp @@ -1848,7 +1848,7 @@ void Score::deleteItem(Element* el) Measure* m = seg->measure(); Segment::Type segType = seg->segmentType(); - if (segType == Segment::Type::BarLine) + if (segType & (Segment::Type::BarLine | Segment::Type::BeginBarLine)) undoRemoveElement(el); else if (segType == Segment::Type::EndBarLine) { m->undoResetProperty(P_ID::REPEAT_END); diff --git a/libmscore/element.cpp b/libmscore/element.cpp index ded849ee84..9fbadbe188 100644 --- a/libmscore/element.cpp +++ b/libmscore/element.cpp @@ -1565,6 +1565,25 @@ void Element::undoChangeProperty(P_ID id, const QVariant& v) score()->undoChangeProperty(this, id, v); } +//--------------------------------------------------------- +// resetProperty +//--------------------------------------------------------- + +void Element::resetProperty(P_ID id) + { + setProperty(id, propertyDefault(id)); + } + +//--------------------------------------------------------- +// custom +// check if property is != default +//--------------------------------------------------------- + +bool Element::custom(P_ID id) const + { + return propertyDefault(id) == getProperty(id); + } + //--------------------------------------------------------- // undoResetProperty //--------------------------------------------------------- @@ -2028,4 +2047,20 @@ bool Element::isUserModified() const return !visible() || !userOff().isNull() || (color() != MScore::defaultColor); } +//--------------------------------------------------------- +// tick +// utility, searches for segment / segment parent +//--------------------------------------------------------- + +int Element::tick() const + { + const Element* e = this; + while (e) { + if (e->type() == Element::Type::SEGMENT) + return static_cast(e)->tick(); + e = e->parent(); + } + return -1; + } + } diff --git a/libmscore/element.h b/libmscore/element.h index 10a80997a6..fdb8125bd6 100644 --- a/libmscore/element.h +++ b/libmscore/element.h @@ -42,7 +42,6 @@ class Element; class BarLine; class Articulation; class Marker; -class Chord; class Clef; class KeySig; class TimeSig; @@ -65,6 +64,8 @@ class Jump; class StaffText; class Ottava; class Note; +class Chord; +class Rest; class LayoutBreak; enum class SymId; @@ -379,7 +380,6 @@ class Element : public QObject, public ScoreElement { void scriptSetUserOff(const QPointF& o); bool isNudged() const { return !(_readPos.isNull() && _userOff.isNull()); } - const QPointF& readPos() const { return _readPos; } void setReadPos(const QPointF& p) { _readPos = p; } virtual void adjustReadPos(); @@ -404,15 +404,6 @@ class Element : public QObject, public ScoreElement { virtual Element::Type type() const = 0; virtual int subtype() const { return -1; } // for select gui - bool isRest() const { return type() == Element::Type::REST; } - bool isChord() const { return type() == Element::Type::CHORD; } - bool isMeasure() const { return type() == Element::Type::MEASURE; } - bool isChordRest() const { return type() == Element::Type::REST || type() == Element::Type::CHORD || type() == Element::Type::REPEAT_MEASURE; } - - bool isDurationElement() const { return isChordRest() || (type() == Element::Type::TUPLET); } - bool isSLine() const; - bool isSLineSegment() const; - virtual void draw(QPainter*) const {} virtual void writeProperties(Xml& xml) const; @@ -508,7 +499,7 @@ class Element : public QObject, public ScoreElement { virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true); - virtual void reset(); + virtual void reset(); // reset all properties & position to default virtual qreal mag() const { return _mag; } void setMag(qreal val) { _mag = val; } @@ -521,6 +512,8 @@ class Element : public QObject, public ScoreElement { qreal point(const Spatium sp) const { return sp.val() * spatium(); } + int tick() const; // utility, searches for segment / segment parent + // // check element for consistency; return false if element // is not valid @@ -563,7 +556,10 @@ class Element : public QObject, public ScoreElement { virtual bool setProperty(P_ID, const QVariant&) override; virtual QVariant propertyDefault(P_ID) const override; void undoChangeProperty(P_ID, const QVariant&); + void resetProperty(P_ID); void undoResetProperty(P_ID); + bool custom(P_ID) const; + virtual bool isUserModified() const; virtual void styleChanged() {} @@ -599,34 +595,37 @@ class Element : public QObject, public ScoreElement { return QString(); // and passed only to the screen-reader } - - virtual bool isUserModified() const; - //--------------------------------------------------- // checked type conversions & tests // // Example for ChordRest: // // bool isChordRest() - // ChordRest* chordRest() - // const ChordRest* chordRest() const // ChordRest* castChordRest() // const ChordRest* castChordRest() const + // ChordRest* toChordRest() + // const ChordRest* toChordRest() const //--------------------------------------------------- ChordRest* chordRest() { Q_ASSERT(this == 0 || type() == Element::Type::CHORD || type() == Element::Type::REST); return (ChordRest*)this; } + bool isChordRest() const { return type() == Element::Type::REST || type() == Element::Type::CHORD || type() == Element::Type::REPEAT_MEASURE; } + bool isDurationElement() const { return isChordRest() || (type() == Element::Type::TUPLET); } + bool isSLine() const; + bool isSLineSegment() const; #define CONVERT(a,b,c) \ - const a* b() const { Q_ASSERT(this == 0 || type() == Element::Type::c); return (const a*)this; } \ - a* b() { Q_ASSERT(this == 0 || type() == Element::Type::c); return (a*)this; } \ - a* cast##a() { return (this == 0 || type() == Element::Type::c) ? (a*)this : 0; } \ - const a* cast##a() const { return (this == 0 || type() == Element::Type::c) ? (const a*)this : 0; } \ - bool is##a() { return type() == Element::Type::c; } + const a* b() const { Q_ASSERT(this == 0 || type() == Element::Type::c); return (const a*)this; } \ + a* b() { Q_ASSERT(this == 0 || type() == Element::Type::c); return (a*)this; } \ + a* to##a() { return (this == 0 || type() == Element::Type::c) ? (a*)this : 0; } \ + const a* to##a() const { return (this == 0 || type() == Element::Type::c) ? (const a*)this : 0; } \ + bool is##a() const { return type() == Element::Type::c; } CONVERT(Note, note, NOTE); + CONVERT(Rest, rest, REST); +// CONVERT(Chord, chord, CHORD); CONVERT(BarLine, barLine, BAR_LINE); CONVERT(Articulation, articulation, ARTICULATION); CONVERT(Marker, marker, MARKER); @@ -652,6 +651,7 @@ class Element : public QObject, public ScoreElement { CONVERT(StaffText, staffText, STAFF_TEXT); CONVERT(Ottava, ottava, OTTAVA); CONVERT(LayoutBreak, layoutBreak, LAYOUT_BREAK); +// CONVERT(Segment, segment, SEGMENT); #undef CONVERT }; diff --git a/libmscore/layout.cpp b/libmscore/layout.cpp index 56c957288a..274a0a4d86 100644 --- a/libmscore/layout.cpp +++ b/libmscore/layout.cpp @@ -152,7 +152,7 @@ void Score::layoutChords1(Segment* segment, int staffIdx) bool downGrace = false; for (int track = startTrack; track < endTrack; ++track) { - Chord* chord = segment->element(track)->castChord(); + Chord* chord = segment->element(track)->toChord(); if (chord) { bool hasGraceBefore = false; for (Chord* c : chord->graceNotes()) { @@ -507,7 +507,7 @@ void Score::layoutChords1(Segment* segment, int staffIdx) // apply chord offsets for (int track = startTrack; track < endTrack; ++track) { - Chord* chord = segment->element(track)->castChord(); + Chord* chord = segment->element(track)->toChord(); if (chord) { if (chord->up()) { if (upOffset != 0.0) { @@ -1225,7 +1225,7 @@ void Score::layoutSpanner() for (int i = 0; i < n; ++i) segment->annotations().at(i)->layout(); } - Chord* c = segment->element(track)->castChord(); + Chord* c = segment->element(track)->toChord(); if (c) { c->layoutStem(); for (Note* n : c->notes()) { @@ -2685,7 +2685,7 @@ void Score::getNextMeasure(LayoutContext& lc) int tick = s->tick(); // find longest pause for (int i = 0, n = ntracks(); i < n; ++i) { - Breath* b = s->element(i)->castBreath(); + Breath* b = s->element(i)->toBreath(); if (b) length = qMax(length, b->pause()); } @@ -2701,7 +2701,7 @@ void Score::getNextMeasure(LayoutContext& lc) } else if (!parentScore() && s->isChordRest()) { for (Element* e : s->annotations()) { - TempoText* tt = e->castTempoText(); + TempoText* tt = e->toTempoText(); if (tt) setTempo(tt->segment(), tt->tempo()); e->layout(); diff --git a/libmscore/measure.cpp b/libmscore/measure.cpp index e96b21455a..7f0fc99c4d 100644 --- a/libmscore/measure.cpp +++ b/libmscore/measure.cpp @@ -2315,12 +2315,11 @@ void Measure::setStartRepeatBarLine() Staff* staff = score()->staff(staffIdx); BarLine* bl = s ? static_cast(s->element(track)) : 0; int span, spanFrom, spanTo; - // if there is a bar line and has custom span, take span from it - if (bl && bl->customSpan()) { + // if there is a bar line, take span from it + if (bl) { span = bl->span(); spanFrom = bl->spanFrom(); spanTo = bl->spanTo(); - customSpan = bl->customSpan(); } else { span = staff->barLineSpan(); @@ -2336,7 +2335,6 @@ void Measure::setStartRepeatBarLine() spanFrom = staffLines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0; spanTo = staffLines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (staffLines-1) * 2; } - customSpan = false; } // make sure we do not span more staves than actually exist if (staffIdx + span > numStaves) @@ -2394,7 +2392,6 @@ qreal Measure::createEndBarLines(bool isLastMeasureInSystem) { int nstaves = score()->nstaves(); Segment* seg = undoGetSegment(Segment::Type::EndBarLine, endTick()); - BarLine* bl = 0; int span = 0; // span counter int aspan = 0; // actual span @@ -2418,26 +2415,23 @@ qreal Measure::createEndBarLines(bool isLastMeasureInSystem) // and forget about any previous bar line if (span == 0) { - if (cbl && cbl->customSpan()) { // if there is a bar line and has custom span, - span = cbl->span(); // get span values from it - spanFrom = cbl->spanFrom(); - spanTo = cbl->spanTo(); - // if bar span values == staff span values, set bar as not custom - if (span == staff->barLineSpan() && spanFrom == staff->barLineFrom() - && spanTo == staff->barLineTo()) - cbl->setCustomSpan(false); + if (cbl) { // if there is a bar line and has custom span, + span = cbl->span(); // get span values from it + spanFrom = cbl->spanFrom(); + spanTo = cbl->spanTo(); } else { // otherwise, get from staff span = staff->barLineSpan(); // if some span OR last staff (span==0) of a Mensurstrich case, get From/To from staff if (span || mensur) { - spanFrom = staff->barLineFrom(); - spanTo = staff->barLineTo(); - mensur = false; + spanFrom = staff->barLineFrom(); + spanTo = staff->barLineTo(); + mensur = false; } // but if staff is set to no span, a multi-staff spanning bar line // has been shortened to span less staves and following staves left without bars; // set bar line span values to default + else if (staff->show()) { span = 1; spanFrom = staffLines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0; diff --git a/libmscore/property.h b/libmscore/property.h index 526ab008e6..759b142273 100644 --- a/libmscore/property.h +++ b/libmscore/property.h @@ -17,6 +17,7 @@ namespace Ms { class XmlReader; + //--------------------------------------------------------- // PropertyStyle //--------------------------------------------------------- @@ -25,6 +26,15 @@ enum class PropertyStyle : char { NOSTYLE, UNSTYLED, STYLED }; +//--------------------------------------------------------- +// Property +//--------------------------------------------------------- + +class Property { + PropertyStyle _style; + QVariant _value; + }; + //------------------------------------------------------------------------ // Element Properties //------------------------------------------------------------------------ diff --git a/libmscore/score.cpp b/libmscore/score.cpp index b122c4473f..c985c964b3 100644 --- a/libmscore/score.cpp +++ b/libmscore/score.cpp @@ -538,7 +538,7 @@ void Score::fixTicks() } } qreal stretch = 0.0; - for (int i = 0; i < s->elist().size(); ++i) { + for (unsigned i = 0; i < s->elist().size(); ++i) { Element* e = s->elist().at(i); if (!e) continue; @@ -793,7 +793,7 @@ Note* prevNote(Note* n) Segment* seg = chord->segment(); const std::vector nl = chord->notes(); auto i = std::find(nl.begin(), nl.end(), n); - if (i != nl.begin()); + if (i != nl.begin()) return *(i-1); int staff = n->staffIdx(); int startTrack = staff * VOICES + n->voice() - 1; @@ -1700,7 +1700,7 @@ void Score::removeElement(Element* element) setLayoutAll(true); else if (et == Element::Type::MEASURE - || (et == Element::Type::HBOX && parent->type() != Element::Type::VBOX) + || (et == Element::Type::HBOX && !parent->isVBox()) || et == Element::Type::VBOX || et == Element::Type::TBOX || et == Element::Type::FBOX @@ -1717,7 +1717,7 @@ void Score::removeElement(Element* element) if (parent) parent->remove(element); - switch(et) { + switch (et) { case Element::Type::BEAM: { Beam* b = static_cast(element); @@ -1735,7 +1735,6 @@ void Score::removeElement(Element* element) case Element::Type::PEDAL: case Element::Type::TEXTLINE: case Element::Type::HAIRPIN: -// case Element::Type::LYRICSLINE: { Spanner* spanner = static_cast(element); if (et == Element::Type::TEXTLINE && spanner->anchor() == Spanner::Anchor::NOTE) @@ -2660,8 +2659,8 @@ void Score::adjustBracketsDel(int sidx, int eidx) if ((sidx >= staffIdx) && (eidx <= (staffIdx + span))) undoChangeBracketSpan(staff, i, span - (eidx-sidx)); } - int span = staff->barLineSpan(); #if 0 // TODO + int span = staff->barLineSpan(); if ((sidx >= staffIdx) && (eidx <= (staffIdx + span))) { int newSpan = span - (eidx-sidx) + 1; int lastSpannedStaffIdx = staffIdx + newSpan - 1; @@ -2687,8 +2686,8 @@ void Score::adjustBracketsIns(int sidx, int eidx) if ((sidx >= staffIdx) && (eidx < (staffIdx + span))) undoChangeBracketSpan(staff, i, span + (eidx-sidx)); } +#if 0 // TODO int span = staff->barLineSpan(); -#if 0 if ((sidx >= staffIdx) && (eidx < (staffIdx + span))) { int idx = staffIdx + span - 1; if (idx >= _staves.size()) diff --git a/mscore/debugger/debugger.cpp b/mscore/debugger/debugger.cpp index 2fa767522e..a6edc9e46f 100644 --- a/mscore/debugger/debugger.cpp +++ b/mscore/debugger/debugger.cpp @@ -1549,8 +1549,8 @@ void BarLineView::setElement(Element* e) bl.span->setValue(barline->span()); bl.spanFrom->setValue(barline->spanFrom()); bl.spanTo->setValue(barline->spanTo()); - bl.customSubtype->setChecked(barline->customSubtype()); - bl.customSpan->setChecked(barline->customSpan()); +// bl.customSubtype->setChecked(barline->customSubtype()); +// bl.customSpan->setChecked(barline->customSpan()); } //--------------------------------------------------------- diff --git a/mscore/inspector/inspector.cpp b/mscore/inspector/inspector.cpp index 2b0da927b1..3a74f8a47b 100644 --- a/mscore/inspector/inspector.cpp +++ b/mscore/inspector/inspector.cpp @@ -217,10 +217,10 @@ void Inspector::setElements(const QList& l) ie = new InspectorSlur(this); break; case Element::Type::BAR_LINE: - if (_element->isEditable()) +// if (_element->isEditable()) ie = new InspectorBarLine(this); - else - ie = new InspectorEmpty(this); +// else +// ie = new InspectorEmpty(this); break; case Element::Type::JUMP: ie = new InspectorJump(this); @@ -925,6 +925,17 @@ QSize InspectorEmpty::sizeHint() const return QSize(255 * guiScaling, 170 * guiScaling); } +static const BarLineType types[8] = { + BarLineType::NORMAL, + BarLineType::BROKEN, + BarLineType::DOTTED, + BarLineType::DOUBLE, + BarLineType::END, + BarLineType::START_REPEAT, // repeat types cannot be set for a single bar line + BarLineType::END_REPEAT, // of a multi-staff scores + BarLineType::END_START_REPEAT, + }; + //--------------------------------------------------------- // InspectorBarLine //--------------------------------------------------------- @@ -932,32 +943,10 @@ QSize InspectorEmpty::sizeHint() const InspectorBarLine::InspectorBarLine(QWidget* parent) : InspectorBase(parent) { - static const char* builtinSpanNames[BARLINE_BUILTIN_SPANS+1] = { - QT_TRANSLATE_NOOP("inspector", "Staff default"), - QT_TRANSLATE_NOOP("inspector", "Tick 1"), - QT_TRANSLATE_NOOP("inspector", "Tick 2"), - QT_TRANSLATE_NOOP("inspector", "Short 1"), - QT_TRANSLATE_NOOP("inspector", "Short 2"), - QT_TRANSLATE_NOOP("inspector", "[Custom]") - }; - - BarLineType types[8] = { - BarLineType::NORMAL, - BarLineType::BROKEN, - BarLineType::DOTTED, - BarLineType::DOUBLE, - BarLineType::END, - BarLineType::START_REPEAT, // repeat types cannot be set for a single bar line - BarLineType::END_REPEAT, // of a multi-staff scores - BarLineType::END_START_REPEAT, - }; - e.setupUi(addWidget()); s.setupUi(addWidget()); b.setupUi(addWidget()); - for (const char* name : builtinSpanNames) - b.spanType->addItem(qApp->translate("inspector", name)); for (BarLineType t : types) b.type->addItem(BarLine::userTypeName(t), int(t)); @@ -967,18 +956,21 @@ InspectorBarLine::InspectorBarLine(QWidget* parent) { P_ID::USER_OFF, 0, 0, e.offsetX, e.resetX }, { P_ID::USER_OFF, 1, 0, e.offsetY, e.resetY }, { P_ID::LEADING_SPACE, 0, 1, s.leadingSpace, s.resetLeadingSpace }, - { P_ID::SUBTYPE, 0, 0, b.type, b.resetType }, + { P_ID::BARLINE_TYPE, 0, 0, b.type, b.resetType }, { P_ID::BARLINE_SPAN, 0, 0, b.span, b.resetSpan }, { P_ID::BARLINE_SPAN_FROM, 0, 0, b.spanFrom, b.resetSpanFrom }, { P_ID::BARLINE_SPAN_TO, 0, 0, b.spanTo, b.resetSpanTo }, }; mapSignals(); // when any of the span parameters is changed, span data need to be managed - connect(b.span, SIGNAL(valueChanged(int)), SLOT(manageSpanData())); - connect(b.spanFrom, SIGNAL(valueChanged(int)), SLOT(manageSpanData())); - connect(b.spanTo, SIGNAL(valueChanged(int)), SLOT(manageSpanData())); - connect(b.spanType, SIGNAL(activated(int)), SLOT(spanTypeChanged(int))); - connect(b.resetSpanType,SIGNAL(clicked()), SLOT(resetSpanType())); + connect(b.span, SIGNAL(valueChanged(int)), SLOT(manageSpanData())); + connect(b.spanFrom, SIGNAL(valueChanged(int)), SLOT(manageSpanData())); + connect(b.spanTo, SIGNAL(valueChanged(int)), SLOT(manageSpanData())); + connect(b.presetDefault, SIGNAL(clicked()), SLOT(presetDefaultClicked())); + connect(b.presetTick1, SIGNAL(clicked()), SLOT(presetTick1Clicked())); + connect(b.presetTick2, SIGNAL(clicked()), SLOT(presetTick2Clicked())); + connect(b.presetShort1, SIGNAL(clicked()), SLOT(presetShort1Clicked())); + connect(b.presetShort2, SIGNAL(clicked()), SLOT(presetShort2Clicked())); } //--------------------------------------------------------- @@ -996,14 +988,14 @@ void InspectorBarLine::setElement() // enable / disable individual type combo items according to score and selected bar line status bool bMultiStaff = bl->score()->nstaves() > 1; BarLineType blt = bl->barLineType(); - bool bIsRepeat = (blt == BarLineType::START_REPEAT - || blt == BarLineType::END_REPEAT - || blt == BarLineType::END_START_REPEAT); + bool isRepeat = (blt == BarLineType::START_REPEAT + || blt == BarLineType::END_REPEAT + || blt == BarLineType::END_START_REPEAT); - // scan type combo items const QStandardItemModel* model = qobject_cast(b.type->model()); - for (int i = 0; i < b.type->count(); i++) { - BarLineType type = (BarLineType)(b.type->itemData(i).toInt()); + for (unsigned i = 0; i < sizeof(types)/sizeof(*types); ++i) { + BarLineType type = types[i]; + QStandardItem* item = model->item(i); // if combo item is repeat type, should be disabled for multi-staff scores if (type == BarLineType::START_REPEAT @@ -1013,87 +1005,105 @@ void InspectorBarLine::setElement() item->setFlags(bMultiStaff ? item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) : item->flags() | (Qt::ItemFlags)(Qt::ItemIsSelectable|Qt::ItemIsEnabled) ); -/* visually disable by greying out (currently unnecessary, but kept for future reference) - item->setData(bMultiStaff ? - b.type->palette().color(QPalette::Disabled, QPalette::Text) - : QVariant(), // clear item data in order to use default color - Qt::TextColorRole); */ } // if combo item is NOT repeat type, should be disabled if selected bar line is a repeat else { - item->setFlags(bIsRepeat ? + item->setFlags(isRepeat ? item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) : item->flags() | (Qt::ItemFlags)(Qt::ItemIsSelectable|Qt::ItemIsEnabled) ); } } - // make custom span type unselectable (it is informative only) - model = qobject_cast(b.spanType->model()); - QStandardItem* item = model->item(5); - item->setFlags(item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled)); - manageSpanData(); blockSpanDataSignals(false); } //--------------------------------------------------------- -// spanTypeChanged +// presetDefaultClicked //--------------------------------------------------------- -void InspectorBarLine::spanTypeChanged(int idx) +void InspectorBarLine::presetDefaultClicked() { - BarLine* bl = static_cast(inspector->element()); - Score* score = bl->score(); + BarLine* bl = static_cast(inspector->element()); + Score* score = bl->score(); score->startCmd(); - int spanStaves, spanFrom = 0, spanTo = 0; - // the amount to adjust To value of short types, if staff num. of lines != 5 - int shortDelta = bl->staff() ? (bl->staff()->lines() - 5)*2 : 0; - spanStaves = 1; // in most cases, num. of spanned staves is 1 - switch (idx) { - case 0: // staff default selected - if(bl->staff()) { // if there is a staff - Staff* st = bl->staff(); // use its span values as selected values - spanStaves = st->barLineSpan(); - spanFrom = st->barLineFrom(); - spanTo = st->barLineTo(); - } - else { // if no staff, use default values - spanFrom = 0; - spanTo = DEFAULT_BARLINE_TO; - } - break; - case 1: - spanFrom = BARLINE_SPAN_TICK1_FROM; - spanTo = BARLINE_SPAN_TICK1_TO; - break; - case 2: - spanFrom = BARLINE_SPAN_TICK2_FROM; - spanTo = BARLINE_SPAN_TICK2_TO; - break; - case 3: - spanFrom = BARLINE_SPAN_SHORT1_FROM; - spanTo = BARLINE_SPAN_SHORT1_TO + shortDelta; - break; - case 4: - spanFrom = BARLINE_SPAN_SHORT2_FROM; - spanTo = BARLINE_SPAN_SHORT2_TO + shortDelta; - break; - case 5: // custom type has no effect - spanStaves = bl->span(); // use values from bar line itself - spanFrom = bl->spanFrom(); - spanTo = bl->spanTo(); - break; - } + bl->undoResetProperty(P_ID::BARLINE_SPAN); + bl->undoResetProperty(P_ID::BARLINE_SPAN_FROM); + bl->undoResetProperty(P_ID::BARLINE_SPAN_TO); - // if combo values different from bar line's, set them - if(bl->span() != spanStaves || bl->spanFrom() != spanFrom || bl->spanTo() != spanTo) { - blockSpanDataSignals(true); - score->undoChangeSingleBarLineSpan(bl, spanStaves, spanFrom, spanTo); - // if value reverted to staff default, update combo box - if(!bl->customSpan()) - b.spanType->setCurrentIndex(0); - blockSpanDataSignals(false); - } + score->endCmd(); + mscore->endCmd(); + } + +//--------------------------------------------------------- +// presetTick1Clicked +//--------------------------------------------------------- + +void InspectorBarLine::presetTick1Clicked() + { + BarLine* bl = static_cast(inspector->element()); + Score* score = bl->score(); + score->startCmd(); + + bl->undoChangeProperty(P_ID::BARLINE_SPAN, 1); + bl->undoChangeProperty(P_ID::BARLINE_SPAN_FROM, BARLINE_SPAN_TICK1_FROM); + bl->undoChangeProperty(P_ID::BARLINE_SPAN_TO, BARLINE_SPAN_TICK1_TO); + + score->endCmd(); + mscore->endCmd(); + } + +//--------------------------------------------------------- +// presetTick2Clicked +//--------------------------------------------------------- + +void InspectorBarLine::presetTick2Clicked() + { + BarLine* bl = static_cast(inspector->element()); + Score* score = bl->score(); + score->startCmd(); + + bl->undoChangeProperty(P_ID::BARLINE_SPAN, 1); + bl->undoChangeProperty(P_ID::BARLINE_SPAN_FROM, BARLINE_SPAN_TICK2_FROM); + bl->undoChangeProperty(P_ID::BARLINE_SPAN_TO, BARLINE_SPAN_TICK2_TO); + + score->endCmd(); + mscore->endCmd(); + } + +//--------------------------------------------------------- +// presetShort1Clicked +//--------------------------------------------------------- + +void InspectorBarLine::presetShort1Clicked() + { + BarLine* bl = static_cast(inspector->element()); + Score* score = bl->score(); + score->startCmd(); + + bl->undoChangeProperty(P_ID::BARLINE_SPAN, 1); + bl->undoChangeProperty(P_ID::BARLINE_SPAN_FROM, BARLINE_SPAN_SHORT1_FROM); + int shortDelta = bl->staff() ? (bl->staff()->lines() - 5) * 2 : 0; + bl->undoChangeProperty(P_ID::BARLINE_SPAN_TO, BARLINE_SPAN_SHORT1_TO + shortDelta); + + score->endCmd(); + mscore->endCmd(); + } + +//--------------------------------------------------------- +// presetShort2Clicked +//--------------------------------------------------------- + +void InspectorBarLine::presetShort2Clicked() + { + BarLine* bl = static_cast(inspector->element()); + Score* score = bl->score(); + score->startCmd(); + + bl->undoChangeProperty(P_ID::BARLINE_SPAN, 1); + bl->undoChangeProperty(P_ID::BARLINE_SPAN_FROM, BARLINE_SPAN_SHORT2_FROM); + int shortDelta = bl->staff() ? (bl->staff()->lines() - 5) * 2 : 0; + bl->undoChangeProperty(P_ID::BARLINE_SPAN_TO, BARLINE_SPAN_SHORT2_TO + shortDelta); score->endCmd(); mscore->endCmd(); @@ -1117,6 +1127,7 @@ void InspectorBarLine::manageSpanData() // From: min = minimum possible according to number of staff lines // max = if same as To, at least 1sp (2 units) above To; if not, max possible according to num.of lines + int min = staffFromLines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : MIN_BARLINE_SPAN_FROMTO; int max = bl->span() < 2 ? bl->spanTo() - MIN_BARLINE_FROMTO_DIST : (staffFromLines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (staffFromLines-1) * 2 + 2); @@ -1129,6 +1140,7 @@ void InspectorBarLine::manageSpanData() min = bl->span() < 2 ? bl->spanFrom() + MIN_BARLINE_FROMTO_DIST : (staffToLines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : MIN_BARLINE_SPAN_FROMTO); max = staffToLines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (staffToLines-1) * 2 + 2; + b.spanTo->setMinimum(min); b.spanTo->setMaximum(max); b.spanTo->setWrapping(false); @@ -1137,30 +1149,6 @@ void InspectorBarLine::manageSpanData() max = bl->score()->nstaves() - bl->staffIdx(); b.span->setMaximum(max); b.span->setWrapping(false); - - // determine SPAN TYPE - int short1To = BARLINE_SPAN_SHORT1_TO + (staffFromLines - 5) * 2; - int short2To = BARLINE_SPAN_SHORT2_TO + (staffFromLines - 5) * 2; - if (!bl->customSpan()) - b.spanType->setCurrentIndex(0); // staff default - else if (bl->span() == 1 && bl->spanFrom() == BARLINE_SPAN_TICK1_FROM && bl->spanTo() == BARLINE_SPAN_TICK1_TO) - b.spanType->setCurrentIndex(1); - else if (bl->span() == 1 && bl->spanFrom() == BARLINE_SPAN_TICK2_FROM && bl->spanTo() == BARLINE_SPAN_TICK2_TO) - b.spanType->setCurrentIndex(2); - else if (bl->span() == 1 && bl->spanFrom() == BARLINE_SPAN_SHORT1_FROM && bl->spanTo() == short1To) - b.spanType->setCurrentIndex(3); - else if (bl->span() == 1 && bl->spanFrom() == BARLINE_SPAN_SHORT2_FROM && bl->spanTo() == short2To) - b.spanType->setCurrentIndex(4); - else - b.spanType->setCurrentIndex(5); // custom - } - -//--------------------------------------------------------- -// resetSpanType -//--------------------------------------------------------- - -void InspectorBarLine::resetSpanType() - { } //--------------------------------------------------------- @@ -1174,7 +1162,6 @@ void InspectorBarLine::blockSpanDataSignals(bool val) b.span->blockSignals(val); b.spanFrom->blockSignals(val); b.spanTo->blockSignals(val); - b.spanType->blockSignals(val); } } diff --git a/mscore/inspector/inspector.h b/mscore/inspector/inspector.h index 9eb96a379a..9ba6025893 100644 --- a/mscore/inspector/inspector.h +++ b/mscore/inspector/inspector.h @@ -328,9 +328,12 @@ class InspectorBarLine : public InspectorBase { void blockSpanDataSignals(bool val); private slots: - void spanTypeChanged(int idx); - void resetSpanType(); void manageSpanData(); + void presetDefaultClicked(); + void presetTick1Clicked(); + void presetTick2Clicked(); + void presetShort1Clicked(); + void presetShort2Clicked(); public: InspectorBarLine(QWidget* parent); diff --git a/mscore/inspector/inspector_barline.ui b/mscore/inspector/inspector_barline.ui index ab3b6e05a0..eb9eec5ac3 100644 --- a/mscore/inspector/inspector_barline.ui +++ b/mscore/inspector/inspector_barline.ui @@ -6,8 +6,8 @@ 0 0 - 283 - 169 + 462 + 205 @@ -153,6 +153,13 @@ + + + + Span to + + + @@ -176,10 +183,16 @@ - - + + + + Reset value + - Span to + Reset Span from value + + + ... @@ -196,19 +209,6 @@ - - - - Reset value - - - Reset Span from value - - - ... - - - @@ -225,35 +225,51 @@ - Span preset: + Span presets: Qt::PlainText - - spanType - - - - - Spantype - - - - - - - Reset value - - - Reset Span type value - - - ... - - + + + + + + Default + + + + + + + Tick 1 + + + + + + + Tick 2 + + + + + + + Short 1 + + + + + + + Short 2 + + + + @@ -268,8 +284,6 @@ resetSpanFrom spanTo resetSpanTo - spanType - resetSpanType