Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include "measurebase.h"
26 : #include "property.h"
27 :
28 : namespace mu::engraving {
29 : class Transaction;
30 :
31 : //---------------------------------------------------------
32 : // Box
33 : // virtual base class for frames "boxes"
34 : //---------------------------------------------------------
35 :
36 : class Box : public MeasureBase
37 : {
38 0 : OBJECT_ALLOCATOR(engraving, Box)
39 :
40 : public:
41 : Box(const ElementType& type, Score* parent);
42 :
43 0 : virtual bool isEditable() const override { return true; }
44 :
45 : virtual bool isEditAllowed(EditData&) const override;
46 : virtual bool edit(EditData&) override;
47 : virtual void startDragGrip(EditData&) override;
48 : virtual void dragGrip(EditData&) override;
49 :
50 : virtual bool acceptDrop(EditData&) const override;
51 : virtual EngravingItem* drop(Transaction& tx, EditData&) override;
52 : virtual void add(EngravingItem* e) override;
53 : virtual double absoluteFromSpatium(const Spatium& val) const override;
54 :
55 : RectF contentRect() const;
56 544 : Spatium boxWidth() const { return m_boxWidth; }
57 112 : void setBoxWidth(Spatium val) { m_boxWidth = val; }
58 2187 : Spatium boxHeight() const { return m_boxHeight; }
59 815 : void setBoxHeight(Spatium val) { m_boxHeight = val; }
60 23556 : double leftMargin() const { return m_leftMargin; }
61 11732 : double rightMargin() const { return m_rightMargin; }
62 11863 : double topMargin() const { return m_topMargin; }
63 11637 : double bottomMargin() const { return m_bottomMargin; }
64 130 : void setLeftMargin(double val) { m_leftMargin = val; }
65 130 : void setRightMargin(double val) { m_rightMargin = val; }
66 131 : void setTopMargin(double val) { m_topMargin = val; }
67 130 : void setBottomMargin(double val) { m_bottomMargin = val; }
68 1197 : Spatium topGap() const { return m_topGap; }
69 152 : void setTopGap(Spatium val) { m_topGap = val; }
70 5024 : Spatium bottomGap() const { return m_bottomGap; }
71 213 : void setBottomGap(Spatium val) { m_bottomGap = val; }
72 2768 : bool isAutoSizeEnabled() const { return m_isAutoSizeEnabled; }
73 407 : void setAutoSizeEnabled(const bool val) { m_isAutoSizeEnabled = val; }
74 : void copyValues(Box* origin);
75 : bool isTitleFrame() const;
76 :
77 : PropertyValue getProperty(Pid propertyId) const override;
78 : bool setProperty(Pid propertyId, const PropertyValue&) override;
79 : PropertyValue propertyDefault(Pid) const override;
80 :
81 : String accessibleExtraInfo() const override;
82 :
83 : // TODO: add a grip for moving the entire box
84 0 : bool needStartEditingAfterSelecting() const override { return true; }
85 0 : int gripsCount() const override { return 1; }
86 0 : Grip initialEditModeGrip() const override { return Grip::START; }
87 0 : Grip defaultGrip() const override { return Grip::START; }
88 0 : std::vector<PointF> gripsPositions(const EditData&) const override { return { PointF() }; } // overridden in descendants
89 :
90 0 : bool canBeExcludedFromOtherParts() const override { return true; }
91 : void manageExclusionFromParts(bool exclude) override;
92 :
93 : private:
94 : Spatium m_boxWidth; // only valid for HBox
95 : Spatium m_boxHeight; // only valid for VBox
96 : Spatium m_topGap; // distance from previous system (left border for hbox)
97 : // initialized with Sid::systemFrameDistance
98 : Spatium m_bottomGap; // distance to next system (right border for hbox)
99 : // initialized with Sid::frameSystemDistance
100 : double m_leftMargin = 0.0;
101 : double m_rightMargin = 0.0; // inner margins in metric mm
102 : double m_topMargin = 0.0;
103 : double m_bottomMargin = 0.0;
104 : bool m_isAutoSizeEnabled = true;
105 : };
106 :
107 : //---------------------------------------------------------
108 : // HBox
109 : // horizontal frame
110 : //---------------------------------------------------------
111 :
112 : class HBox final : public Box
113 : {
114 167 : OBJECT_ALLOCATOR(engraving, HBox)
115 2376 : DECLARE_CLASSOF(ElementType::HBOX)
116 :
117 : public:
118 : HBox(Score* parent);
119 :
120 0 : HBox* clone() const override { return new HBox(*this); }
121 :
122 : RectF drag(EditData&) override;
123 :
124 : bool isMovable() const override;
125 : void computeMinWidth() override;
126 :
127 224 : bool createSystemHeader() const { return m_createSystemHeader; }
128 0 : void setCreateSystemHeader(bool val) { m_createSystemHeader = val; }
129 :
130 : PropertyValue getProperty(Pid propertyId) const override;
131 : bool setProperty(Pid propertyId, const PropertyValue&) override;
132 : PropertyValue propertyDefault(Pid) const override;
133 :
134 : std::vector<PointF> gripsPositions(const EditData&) const override;
135 :
136 : private:
137 : bool m_createSystemHeader = true;
138 : };
139 :
140 : //---------------------------------------------------------
141 : // VBox
142 : // vertical frame
143 : //---------------------------------------------------------
144 :
145 : class VBox : public Box
146 : {
147 2341 : OBJECT_ALLOCATOR(engraving, VBox)
148 2331 : DECLARE_CLASSOF(ElementType::VBOX)
149 :
150 : public:
151 : VBox(Score* parent);
152 :
153 0 : VBox* clone() const override { return new VBox(*this); }
154 :
155 : void add(EngravingItem* e) override;
156 :
157 : double minHeight() const;
158 : double maxHeight() const;
159 :
160 : PropertyValue getProperty(Pid propertyId) const override;
161 : PropertyValue propertyDefault(Pid) const override;
162 : bool setProperty(Pid propertyId, const PropertyValue&) override;
163 :
164 : void startDragGrip(EditData&) override;
165 :
166 : bool acceptDrop(EditData&) const override;
167 :
168 : std::vector<PointF> gripsPositions(const EditData&) const override;
169 :
170 109 : Spatium paddingToNotationAbove() const { return m_paddingToNotationAbove; }
171 4415 : Spatium paddingToNotationBelow() const { return m_paddingToNotationBelow; }
172 :
173 : protected:
174 : VBox(const ElementType& type, Score* parent);
175 :
176 : private:
177 : Spatium m_paddingToNotationAbove;
178 : Spatium m_paddingToNotationBelow;
179 : };
180 :
181 : //---------------------------------------------------------
182 : // FBox
183 : // frame containing fret diagrams
184 : //---------------------------------------------------------
185 :
186 : class FBox : public VBox
187 : {
188 10 : OBJECT_ALLOCATOR(engraving, FBox)
189 1961 : DECLARE_CLASSOF(ElementType::FBOX)
190 :
191 : public:
192 : FBox(Score* parent);
193 0 : FBox* clone() const override { return new FBox(*this); }
194 :
195 : void init();
196 :
197 : void add(EngravingItem*) override;
198 : void addAtIdx(FretDiagram* fretDiagram, size_t idx);
199 :
200 58 : double textScale() const { return m_textScale; }
201 58 : double diagramScale() const { return m_diagramScale; }
202 12 : Spatium columnGap() const { return m_columnGap; }
203 12 : Spatium rowGap() const { return m_rowGap; }
204 12 : int chordsPerRow() const { return m_chordsPerRow; }
205 12 : AlignH contentHorizontalAlignment() const { return m_contentAlignmentH; }
206 :
207 : PropertyValue getProperty(Pid propertyId) const override;
208 : bool setProperty(Pid propertyId, const PropertyValue& val) override;
209 : PropertyValue propertyDefault(Pid propertyId) const override;
210 :
211 : int gripsCount() const override;
212 : Grip initialEditModeGrip() const override;
213 : Grip defaultGrip() const override;
214 : std::vector<PointF> gripsPositions(const EditData&) const override;
215 :
216 0 : bool needStartEditingAfterSelecting() const override { return false; }
217 :
218 : void undoReorderElements(const StringList& newOrder);
219 : void reorderElements(const StringList& newOrder);
220 : StringList diagramsOrder() const;
221 :
222 12 : bool needsRebuild() const { return m_needsRebuild; }
223 4 : void setNeedsRebuild(bool v) { m_needsRebuild = v; }
224 :
225 : private:
226 :
227 : void updateInvisibleDiagrams(const StringList& currentDiagrams);
228 : size_t computeInsertionIdx(const String& nameOfDiagramBeforeThis);
229 :
230 : double m_textScale = 0.0;
231 : double m_diagramScale = 0.0;
232 : Spatium m_columnGap;
233 : Spatium m_rowGap;
234 : int m_chordsPerRow = 0;
235 :
236 : bool m_needsRebuild = false;
237 :
238 : AlignH m_contentAlignmentH = AlignH::HCENTER;
239 :
240 : StringList m_diagramsOrderInScore;
241 : };
242 :
243 : //---------------------------------------------------------
244 : // TBox
245 : // Text frame.
246 : //---------------------------------------------------------
247 :
248 : class Text;
249 : class TBox : public VBox
250 : {
251 203 : OBJECT_ALLOCATOR(engraving, TBox)
252 1961 : DECLARE_CLASSOF(ElementType::TBOX)
253 :
254 : public:
255 : TBox(Score* parent);
256 : TBox(const TBox&);
257 : ~TBox() override;
258 :
259 683 : Text* text() const { return m_text; }
260 :
261 : void scanElements(std::function<void(EngravingItem*)> func) override;
262 :
263 0 : TBox* clone() const override { return new TBox(*this); }
264 :
265 : EngravingItem* drop(Transaction& tx, EditData&) override;
266 : void add(EngravingItem* e) override;
267 : void remove(EngravingItem* el) override;
268 :
269 : PropertyValue propertyDefault(Pid) const override;
270 :
271 : String accessibleExtraInfo() const override;
272 :
273 : int gripsCount() const override;
274 : Grip initialEditModeGrip() const override;
275 : Grip defaultGrip() const override;
276 :
277 0 : bool needStartEditingAfterSelecting() const override { return false; }
278 :
279 : private:
280 : Text* m_text = nullptr;
281 : };
282 : }
|