1 //============================================================================= 2 // MuseScore 3 // Music Composition & Notation 4 // 5 // Copyright (C) 2002-2016 Werner Schweer 6 // 7 // This program is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License version 2 9 // as published by the Free Software Foundation and appearing in 10 // the file LICENCE.GPL 11 //============================================================================= 12 13 #ifndef __BARLINE_H__ 14 #define __BARLINE_H__ 15 16 #include "element.h" 17 #include "mscore.h" 18 19 namespace Ms { 20 21 class MuseScoreView; 22 class Segment; 23 24 static const int MIN_BARLINE_FROMTO_DIST = 2; 25 static const int MIN_BARLINE_SPAN_FROMTO = -2; 26 27 // bar line span for 1-line staves is special: goes from 2sp above the line to 2sp below the line; 28 static const int BARLINE_SPAN_1LINESTAFF_FROM = -4; 29 static const int BARLINE_SPAN_1LINESTAFF_TO = 4; 30 31 // data for some preset bar line span types 32 static const int BARLINE_SPAN_TICK1_FROM = -1; 33 static const int BARLINE_SPAN_TICK1_TO = -7; 34 static const int BARLINE_SPAN_TICK2_FROM = -2; 35 static const int BARLINE_SPAN_TICK2_TO = -6; 36 static const int BARLINE_SPAN_SHORT1_FROM = 2; 37 static const int BARLINE_SPAN_SHORT1_TO = -2; 38 static const int BARLINE_SPAN_SHORT2_FROM = 1; 39 static const int BARLINE_SPAN_SHORT2_TO = -1; 40 41 //--------------------------------------------------------- 42 // BarLineTableItem 43 //--------------------------------------------------------- 44 45 struct BarLineTableItem { 46 BarLineType type; 47 const char* userName; // user name, translatable 48 const char* name; 49 }; 50 51 //--------------------------------------------------------- 52 // @@ BarLine 53 // 54 // @P barLineType enum (BarLineType.NORMAL, .DOUBLE, .START_REPEAT, .END_REPEAT, .BROKEN, .END, .END_START_REPEAT, .DOTTED) 55 //--------------------------------------------------------- 56 57 class BarLine final : public Element { 58 int _spanStaff { 0 }; // span barline to next staff if true, values > 1 are used for importing from 2.x 59 int _spanFrom { 0 }; // line number on start and end staves 60 int _spanTo { 0 }; 61 BarLineType _barLineType { BarLineType::NORMAL }; 62 mutable qreal y1; 63 mutable qreal y2; 64 ElementList _el; ///< fermata or other articulations 65 66 void getY() const; 67 void drawDots(QPainter* painter, qreal x) const; 68 void drawTips(QPainter* painter, bool reversed, qreal x) const; 69 bool isTop() const; 70 bool isBottom() const; 71 void drawEditMode(QPainter*, EditData&); 72 73 public: 74 BarLine(Score* s = 0); 75 virtual ~BarLine(); 76 BarLine(const BarLine&); 77 BarLine &operator=(const BarLine&) = delete; 78 clone()79 BarLine* clone() const override { return new BarLine(*this); } type()80 ElementType type() const override { return ElementType::BAR_LINE; } 81 Fraction playTick() const override; 82 void write(XmlWriter& xml) const override; 83 void read(XmlReader&) override; 84 void draw(QPainter*) const override; 85 QPointF canvasPos() const override; ///< position in canvas coordinates 86 QPointF pagePos() const override; ///< position in page coordinates 87 void layout() override; 88 void layout2(); 89 void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override; 90 void setTrack(int t) override; 91 void setScore(Score* s) override; 92 void add(Element*) override; 93 void remove(Element*) override; 94 bool acceptDrop(EditData&) const override; 95 Element* drop(EditData&) override; isEditable()96 bool isEditable() const override { return true; } 97 segment()98 Segment* segment() const { return toSegment(parent()); } measure()99 Measure* measure() const { return toMeasure(parent()->parent()); } 100 setSpanStaff(int val)101 void setSpanStaff(int val) { _spanStaff = val; } setSpanFrom(int val)102 void setSpanFrom(int val) { _spanFrom = val; } setSpanTo(int val)103 void setSpanTo(int val) { _spanTo = val; } spanStaff()104 int spanStaff() const { return _spanStaff; } spanFrom()105 int spanFrom() const { return _spanFrom; } spanTo()106 int spanTo() const { return _spanTo; } 107 108 void startEdit(EditData& ed) override; 109 void endEdit(EditData&) override; 110 void editDrag(EditData&) override; 111 void endEditDrag(EditData&) override; 112 Shape shape() const override; 113 el()114 ElementList* el() { return &_el; } el()115 const ElementList* el() const { return &_el; } 116 117 static QString userTypeName(BarLineType); 118 static const BarLineTableItem* barLineTableItem(unsigned); 119 120 QString barLineTypeName() const; 121 static QString barLineTypeName(BarLineType t); 122 void setBarLineType(const QString& s); setBarLineType(BarLineType i)123 void setBarLineType(BarLineType i) { _barLineType = i; } barLineType()124 BarLineType barLineType() const { return _barLineType; } 125 static BarLineType barLineType(const QString&); 126 subtype()127 int subtype() const override { return int(_barLineType); } subtypeName()128 QString subtypeName() const override { return qApp->translate("barline", barLineTypeName().toUtf8()); } 129 130 QVariant getProperty(Pid propertyId) const override; 131 bool setProperty(Pid propertyId, const QVariant&) override; 132 QVariant propertyDefault(Pid propertyId) const override; 133 Pid propertyId(const QStringRef& xmlName) const override; 134 void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps); 135 using ScoreElement::undoChangeProperty; 136 137 static qreal layoutWidth(Score*, BarLineType); 138 QRectF layoutRect() const; 139 140 Element* nextSegmentElement() override; 141 Element* prevSegmentElement() override; 142 143 QString accessibleInfo() const override; 144 QString accessibleExtraInfo() const override; 145 normalModeEditBehavior()146 EditBehavior normalModeEditBehavior() const override { return EditBehavior::Edit; } gripsCount()147 int gripsCount() const override { return 2; } initialEditModeGrip()148 Grip initialEditModeGrip() const override { return Grip::END; } defaultGrip()149 Grip defaultGrip() const override { return Grip::START; } 150 std::vector<QPointF> gripsPositions(const EditData&) const override; 151 152 static const std::vector<BarLineTableItem> barLineTable; 153 }; 154 } // namespace Ms 155 156 #endif 157 158