MuseScore  3.4
Music composition and notation
box.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 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 __BOX_H__
14 #define __BOX_H__
15 
21 #include "measurebase.h"
22 #include "property.h"
23 
24 namespace Ms {
25 
26 class MuseScoreView;
27 
28 //---------------------------------------------------------
29 // @@ Box
31 //---------------------------------------------------------
32 
33 class Box : public MeasureBase {
34  Spatium _boxWidth { Spatium(0) }; // only valid for HBox
35  Spatium _boxHeight { Spatium(0) }; // only valid for VBox
36  qreal _topGap { 0.0 }; // distance from previous system (left border for hbox)
37  // initialized with Sid::systemFrameDistance
38  qreal _bottomGap { 0.0 }; // distance to next system (right border for hbox)
39  // initialized with Sid::frameSystemDistance
40  qreal _leftMargin { 0.0 };
41  qreal _rightMargin { 0.0 }; // inner margins in metric mm
42  qreal _topMargin { 0.0 };
43  qreal _bottomMargin { 0.0 };
44  bool editMode { false };
45 
46  public:
47  Box(Score*);
48  virtual void draw(QPainter*) const override;
49  virtual bool isEditable() const override { return true; }
50 
51  virtual void startEdit(EditData&) override;
52  virtual bool edit(EditData&) override;
53  virtual void startEditDrag(EditData&) override;
54  virtual void editDrag(EditData&) override;
55  virtual void endEdit(EditData&) override;
56 
57  virtual void layout() override;
58  virtual void write(XmlWriter&) const override;
59  virtual void write(XmlWriter& xml, int, bool, bool) const override { write(xml); }
60  virtual void writeProperties(XmlWriter&) const override;
61  virtual bool readProperties(XmlReader&) override;
62  virtual void read(XmlReader&) override;
63  virtual bool acceptDrop(EditData&) const override;
64  virtual Element* drop(EditData&) override;
65  virtual void add(Element* e) override;
66 
67  Spatium boxWidth() const { return _boxWidth; }
68  void setBoxWidth(Spatium val) { _boxWidth = val; }
69  Spatium boxHeight() const { return _boxHeight; }
70  void setBoxHeight(Spatium val) { _boxHeight = val; }
71  qreal leftMargin() const { return _leftMargin; }
72  qreal rightMargin() const { return _rightMargin; }
73  qreal topMargin() const { return _topMargin; }
74  qreal bottomMargin() const { return _bottomMargin; }
75  void setLeftMargin(qreal val) { _leftMargin = val; }
76  void setRightMargin(qreal val) { _rightMargin = val; }
77  void setTopMargin(qreal val) { _topMargin = val; }
78  void setBottomMargin(qreal val) { _bottomMargin = val; }
79  qreal topGap() const { return _topGap; }
80  void setTopGap(qreal val) { _topGap = val; }
81  qreal bottomGap() const { return _bottomGap; }
82  void setBottomGap(qreal val) { _bottomGap = val; }
83  void copyValues(Box* origin);
84 
85  virtual QVariant getProperty(Pid propertyId) const override;
86  virtual bool setProperty(Pid propertyId, const QVariant&) override;
87  virtual QVariant propertyDefault(Pid) const override;
88  virtual QString accessibleExtraInfo() const override;
89 
90  // TODO: add a grip for moving the entire box
92  int gripsCount() const override { return 1; }
93  Grip initialEditModeGrip() const override { return Grip::START; }
94  Grip defaultGrip() const override { return Grip::START; }
95  std::vector<QPointF> gripsPositions(const EditData&) const override { return { QPointF() }; } // overriden in descendants
96  };
97 
98 //---------------------------------------------------------
99 // @@ HBox
101 //---------------------------------------------------------
102 
103 class HBox final : public Box {
104  bool _createSystemHeader { true };
105 
106  public:
107  HBox(Score* score);
108  virtual ~HBox() {}
109  virtual HBox* clone() const override { return new HBox(*this); }
110  virtual ElementType type() const override { return ElementType::HBOX; }
111 
112  virtual void layout() override;
113  virtual void writeProperties(XmlWriter&) const override;
114  virtual bool readProperties(XmlReader&) override;
115 
116  virtual QRectF drag(EditData&) override;
117  virtual void endEditDrag(EditData&) override;
118  void layout2();
119  virtual bool isMovable() const override;
120  virtual void computeMinWidth();
121 
122  bool createSystemHeader() const { return _createSystemHeader; }
123  void setCreateSystemHeader(bool val) { _createSystemHeader = val; }
124 
125  virtual QVariant getProperty(Pid propertyId) const override;
126  virtual bool setProperty(Pid propertyId, const QVariant&) override;
127  virtual QVariant propertyDefault(Pid) const override;
128 
129  std::vector<QPointF> gripsPositions(const EditData&) const override;
130  };
131 
132 //---------------------------------------------------------
133 // @@ VBox
135 //---------------------------------------------------------
136 
137 class VBox : public Box {
138  public:
139  VBox(Score* score);
140  virtual ~VBox() {}
141  virtual VBox* clone() const override { return new VBox(*this); }
142  virtual ElementType type() const override { return ElementType::VBOX; }
143 
144  virtual void layout() override;
145 
146  std::vector<QPointF> gripsPositions(const EditData&) const override;
147  };
148 
149 //---------------------------------------------------------
150 // @@ FBox
152 //---------------------------------------------------------
153 
154 class FBox : public VBox {
155  public:
156  FBox(Score* score) : VBox(score) {}
157  virtual ~FBox() {}
158  virtual FBox* clone() const override { return new FBox(*this); }
159  virtual ElementType type() const override { return ElementType::FBOX; }
160 
161  virtual void layout() override;
162  virtual void add(Element*) override;
163  };
164 
165 
166 } // namespace Ms
167 #endif
168 
virtual HBox * clone() const override
Definition: box.h:109
horizontal frame
Definition: box.h:103
virtual void draw(QPainter *) const override
Definition: box.cpp:76
qreal leftMargin() const
Definition: box.h:71
virtual base class for frames "boxes"
Definition: box.h:33
virtual QRectF drag(EditData &)
Return update Rect relative to canvas.
Definition: element.cpp:1908
qreal rightMargin() const
Definition: box.h:72
virtual VBox * clone() const override
Definition: box.h:141
Box(Score *)
Definition: box.cpp:45
virtual void write(XmlWriter &) const override
Definition: box.cpp:191
Pid
Definition: property.h:62
Virtual base class for Measure, HBox and VBox.
Definition: measurebase.h:61
qreal topGap() const
Definition: box.h:79
Spatium boxHeight() const
Definition: box.h:69
Spatium boxWidth() const
Definition: box.h:67
Definition: xml.h:67
Definition of MeasureBase class.
virtual void writeProperties(XmlWriter &) const override
Definition: box.cpp:202
virtual void read(XmlReader &) override
Definition: box.cpp:218
qreal topMargin() const
Definition: box.h:73
FBox(Score *score)
Definition: box.h:156
virtual bool isMovable() const
Definition: element.h:417
void setCreateSystemHeader(bool val)
Definition: box.h:123
virtual ElementType type() const override
Definition: box.h:110
void setLeftMargin(qreal val)
Definition: box.h:75
Base class of score layout elements.
Definition: element.h:158
void copyValues(Box *origin)
Definition: box.cpp:421
virtual QString accessibleExtraInfo() const override
Definition: box.cpp:771
qreal bottomMargin() const
Definition: box.h:74
Spatium _boxWidth
Definition: box.h:34
bool createSystemHeader() const
Definition: box.h:122
bool editMode
Definition: box.h:44
virtual void write(XmlWriter &xml, int, bool, bool) const override
Definition: box.h:59
Definition: score.h:391
qreal _topMargin
Definition: box.h:42
virtual ~VBox()
Definition: box.h:140
virtual void endEditDrag(EditData &)
Definition: element.cpp:2065
Score * score() const
Definition: scoreElement.h:189
virtual void layout() override
Definition: box.cpp:54
Spatium _boxHeight
Definition: box.h:35
frame containing fret diagrams
Definition: box.h:154
void setBoxHeight(Spatium val)
Definition: box.h:70
Grip initialEditModeGrip() const override
Definition: box.h:93
virtual bool edit(EditData &) override
Definition: box.cpp:114
virtual Pid propertyId(const QStringRef &xmlName) const override
Definition: element.cpp:1326
qreal _bottomMargin
Definition: box.h:43
Grip
Definition: element.h:43
virtual QVariant propertyDefault(Pid) const override
Definition: box.cpp:395
virtual bool readProperties(XmlReader &) override
Definition: box.cpp:233
virtual Element * drop(EditData &) override
Handle a dropped element at canvas relative pos of given element type and subtype.
Definition: box.cpp:521
Definition: aeolus.cpp:26
void setBottomMargin(qreal val)
Definition: box.h:78
Definition: spatium.h:25
virtual QVariant getProperty(Pid propertyId) const override
Definition: box.cpp:328
virtual ElementType type() const override
Definition: box.h:159
virtual FBox * clone() const override
Definition: box.h:158
Grip defaultGrip() const override
Definition: box.h:94
virtual bool setProperty(Pid propertyId, const QVariant &) override
Definition: box.cpp:356
qreal _bottomGap
Definition: box.h:38
Definition: xml.h:218
virtual bool isEditable() const override
Definition: box.h:49
qreal _leftMargin
Definition: box.h:40
int gripsCount() const override
Definition: box.h:92
virtual bool acceptDrop(EditData &) const override
Return true if this element accepts a drop at canvas relative pos of given element type and subtype...
Definition: box.cpp:484
void setTopGap(qreal val)
Definition: box.h:80
virtual ElementType type() const override
Definition: box.h:142
virtual void computeMinWidth()
Definition: measurebase.h:173
qreal _rightMargin
Definition: box.h:41
void setBottomGap(qreal val)
Definition: box.h:82
EditBehavior normalModeEditBehavior() const override
Definition: box.h:91
virtual void editDrag(EditData &) override
Definition: box.cpp:136
Definition: element.h:111
void setRightMargin(qreal val)
Definition: box.h:76
qreal _topGap
Definition: box.h:36
void setBoxWidth(Spatium val)
Definition: box.h:68
virtual void endEdit(EditData &) override
Definition: box.cpp:165
virtual ~HBox()
Definition: box.h:108
virtual ~FBox()
Definition: box.h:157
ElementType
Definition: types.h:34
vertical frame
Definition: box.h:137
void setTopMargin(qreal val)
Definition: box.h:77
EditBehavior
Definition: element.h:173
virtual void add(Element *e) override
Add new Element el to Box.
Definition: box.cpp:317
virtual void startEdit(EditData &) override
Definition: box.cpp:104
virtual void startEditDrag(EditData &) override
Definition: box.cpp:123
qreal bottomGap() const
Definition: box.h:81
std::vector< QPointF > gripsPositions(const EditData &) const override
Definition: box.h:95