MuseScore  3.4
Music composition and notation
barline.h
Go to the documentation of this file.
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 
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;
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 
79  virtual BarLine* clone() const override { return new BarLine(*this); }
80  virtual ElementType type() const override { return ElementType::BAR_LINE; }
81  virtual void write(XmlWriter& xml) const override;
82  virtual void read(XmlReader&) override;
83  virtual void draw(QPainter*) const override;
84  virtual QPointF canvasPos() const override;
85  virtual QPointF pagePos() const override;
86  virtual void layout() override;
87  void layout2();
88  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
89  virtual void setTrack(int t) override;
90  virtual void setScore(Score* s) override;
91  virtual void add(Element*) override;
92  virtual void remove(Element*) override;
93  virtual bool acceptDrop(EditData&) const override;
94  virtual Element* drop(EditData&) override;
95  virtual bool isEditable() const override { return true; }
96 
97  Segment* segment() const { return toSegment(parent()); }
98  Measure* measure() const { return toMeasure(parent()->parent()); }
99 
100  void setSpanStaff(int val) { _spanStaff = val; }
101  void setSpanFrom(int val) { _spanFrom = val; }
102  void setSpanTo(int val) { _spanTo = val; }
103  int spanStaff() const { return _spanStaff; }
104  int spanFrom() const { return _spanFrom; }
105  int spanTo() const { return _spanTo; }
106 
107  virtual void startEdit(EditData& ed) override;
108  virtual void endEdit(EditData&) override;
109  virtual void editDrag(EditData&) override;
110  virtual void endEditDrag(EditData&) override;
111  virtual Shape shape() const override;
112 
113  ElementList* el() { return &_el; }
114  const ElementList* el() const { return &_el; }
115 
116  static QString userTypeName(BarLineType);
117  static const BarLineTableItem* barLineTableItem(unsigned);
118 
119  QString barLineTypeName() const;
120  static QString barLineTypeName(BarLineType t);
121  void setBarLineType(const QString& s);
122  void setBarLineType(BarLineType i) { _barLineType = i; }
123  BarLineType barLineType() const { return _barLineType; }
124  static BarLineType barLineType(const QString&);
125 
126  virtual int subtype() const override { return int(_barLineType); }
127  virtual QString subtypeName() const override { return qApp->translate("barline", barLineTypeName().toUtf8()); }
128 
129  virtual QVariant getProperty(Pid propertyId) const override;
130  virtual bool setProperty(Pid propertyId, const QVariant&) override;
131  virtual QVariant propertyDefault(Pid propertyId) const override;
132  virtual Pid propertyId(const QStringRef& xmlName) const override;
133  virtual void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps);
135 
136  static qreal layoutWidth(Score*, BarLineType);
137  QRectF layoutRect() const;
138 
139  virtual Element* nextSegmentElement() override;
140  virtual Element* prevSegmentElement() override;
141 
142  virtual QString accessibleInfo() const override;
143  virtual QString accessibleExtraInfo() const override;
144 
145  EditBehavior normalModeEditBehavior() const override { return EditBehavior::Edit; }
146  int gripsCount() const override { return 2; }
147  Grip initialEditModeGrip() const override { return Grip::END; }
148  Grip defaultGrip() const override { return Grip::START; }
149  std::vector<QPointF> gripsPositions(const EditData&) const override;
150 
151  static const std::vector<BarLineTableItem> barLineTable;
152  };
153 } // namespace Ms
154 
155 #endif
156 
const char * userName
Definition: barline.h:47
void setSpanFrom(int val)
Definition: barline.h:101
ElementList * el()
Definition: barline.h:113
Pid
Definition: property.h:62
Definition: xml.h:67
virtual void undoChangeProperty(Pid id, const QVariant &, PropertyFlags ps)
Definition: scoreElement.cpp:291
virtual BarLine * clone() const override
Definition: barline.h:79
int spanTo() const
Definition: barline.h:105
const ElementList * el() const
Definition: barline.h:114
one measure in a system
Definition: measure.h:65
ElementList _el
fermata or other articulations
Definition: barline.h:64
Segment * segment() const
Definition: barline.h:97
Grip initialEditModeGrip() const override
Definition: barline.h:147
Base class of score layout elements.
Definition: element.h:158
const char * name
Definition: barline.h:48
Definition: element.h:517
qreal y1
Definition: barline.h:62
int spanStaff() const
Definition: barline.h:103
Definition: score.h:391
Measure * measure() const
Definition: barline.h:98
PropertyFlags
Definition: property.h:54
int spanFrom() const
Definition: barline.h:104
virtual QString subtypeName() const override
Definition: barline.h:127
Grip defaultGrip() const override
Definition: barline.h:148
Grip
Definition: element.h:43
void setSpanTo(int val)
Definition: barline.h:102
Definition: segment.h:50
virtual int subtype() const override
Definition: barline.h:126
Definition: aeolus.cpp:26
void setBarLineType(BarLineType i)
Definition: barline.h:122
BarLineType type
Definition: barline.h:46
void setSpanStaff(int val)
Definition: barline.h:100
int gripsCount() const override
Definition: barline.h:146
Definition: xml.h:218
EditBehavior normalModeEditBehavior() const override
Definition: barline.h:145
Definition: element.h:111
Definition: shape.h:42
virtual ElementType type() const override
Definition: barline.h:80
ElementType
Definition: types.h:34
Definition: barline.h:45
Definition: barline.h:57
qreal y2
Definition: barline.h:63
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
EditBehavior
Definition: element.h:173
static const std::vector< BarLineTableItem > barLineTable
Definition: barline.h:151
BarLineType
Definition: mscore.h:199
BarLineType barLineType() const
Definition: barline.h:123
virtual bool isEditable() const override
Definition: barline.h:95