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 "draw/types/color.h"
26 : #include "draw/types/geometry.h"
27 :
28 : #include "modularity/ioc.h"
29 : #include "../rendering/paintoptions.h"
30 :
31 : #include "../infrastructure/ld_access.h"
32 : #include "../infrastructure/shape.h"
33 : #include "../infrastructure/skyline.h"
34 :
35 : #include "../types/fraction.h"
36 : #include "../types/symid.h"
37 : #include "../types/types.h"
38 :
39 : #include "engravingobject.h"
40 : #include "elementgroup.h"
41 :
42 : #include "../editing/editdata.h"
43 :
44 : namespace muse::draw {
45 : class Painter;
46 : }
47 :
48 : #define DECLARE_LAYOUTDATA_METHODS(Class) \
49 : const LayoutData* ldata() const { return static_cast<const Class::LayoutData*>(EngravingItem::ldata()); } \
50 : LayoutData* mutldata() { return static_cast<Class::LayoutData*>(EngravingItem::mutldata()); } \
51 : LayoutData* createLayoutData() const override { return new Class::LayoutData(); } \
52 :
53 : namespace mu::engraving::rendering {
54 : class IScoreRenderer;
55 : }
56 :
57 : namespace mu::engraving {
58 : class IEngravingConfiguration;
59 : class IEngravingContextConfiguration;
60 :
61 : class Transaction;
62 :
63 : template<typename T>
64 0 : inline void dump(const ld_field<T>& f, std::stringstream& ss)
65 : {
66 0 : if (f.has_value()) {
67 0 : dump(f.value(), ss);
68 : } else {
69 0 : ss << "no value";
70 : }
71 0 : }
72 :
73 : class Factory;
74 : class XmlReader;
75 :
76 : #ifndef ENGRAVING_NO_ACCESSIBILITY
77 : class AccessibleItem;
78 : typedef std::shared_ptr<AccessibleItem> AccessibleItemPtr;
79 : #endif
80 :
81 : enum class Pid : short;
82 : class StaffType;
83 :
84 : //---------------------------------------------------------
85 : // ElementFlag
86 : //---------------------------------------------------------
87 :
88 : enum class ElementFlag {
89 : NOTHING = 0x00000000,
90 : DROP_TARGET = 0x00000001,
91 : NOT_SELECTABLE = 0x00000002,
92 : MOVABLE = 0x00000004,
93 : COMPOSITION = 0x00000008, // true if element is part of another element
94 : ON_STAFF = 0x00000010,
95 : SELECTED = 0x00000020,
96 : GENERATED = 0x00000040,
97 : INVISIBLE = 0x00000080,
98 : NO_AUTOPLACE = 0x00000100,
99 : SYSTEM = 0x00000200,
100 : PLACE_ABOVE = 0x00000400,
101 : SIZE_SPATIUM_DEPENDENT = 0x00000800,
102 :
103 : // measure flags
104 : REPEAT_END = 0x00001000,
105 : REPEAT_START = 0x00002000,
106 : REPEAT_JUMP = 0x00004000,
107 : EXCLUDE_FROM_NUMBERING = 0x00008000,
108 : LINE_BREAK = 0x00010000,
109 : PAGE_BREAK = 0x00020000,
110 : SECTION_BREAK = 0x00040000,
111 : NO_BREAK = 0x00080000,
112 : HEADER = 0x00100000,
113 : TRAILER = 0x00200000, // also used in segment
114 : COURTESY_KEYSIG = 0x00400000,
115 : COURTESY_TIMESIG = 0x00800000,
116 : COURTESY_CLEF = 0x01000000,
117 :
118 : // segment flags
119 : ENABLED = 0x02000000, // used for segments
120 : EMPTY = 0x04000000,
121 : WRITTEN = 0x08000000,
122 : END_OF_MEASURE_CHANGE = 0x10000000,
123 : };
124 :
125 : typedef muse::Flags<ElementFlag> ElementFlags;
126 1412619 : DECLARE_OPERATORS_FOR_FLAGS(ElementFlags)
127 :
128 : enum class KerningType : unsigned char
129 : {
130 : KERNING,
131 : NON_KERNING,
132 : KERN_UNTIL_LEFT_EDGE,
133 : KERN_UNTIL_CENTER,
134 : KERN_UNTIL_RIGHT_EDGE,
135 : SAME_VOICE_LIMIT,
136 : ALLOW_COLLISION,
137 : };
138 :
139 : //-------------------------------------------------------------------
140 : // @@ EngravingItem
141 : /// \brief Base class of score layout elements
142 : ///
143 : /// The EngravingItem class is the virtual base class of all
144 : /// score layout elements.
145 : //-------------------------------------------------------------------
146 :
147 : class EngravingItem : public EngravingObject
148 : {
149 8 : M_PROPERTY2(bool, isPositionLinkedToMaster, setPositionLinkedToMaster, true)
150 43 : M_PROPERTY2(bool, isAppearanceLinkedToMaster, setAppearanceLinkedToMaster, true)
151 5174 : M_PROPERTY2(bool, excludeFromOtherParts, setExcludeFromOtherParts, false)
152 :
153 : public:
154 :
155 : virtual ~EngravingItem();
156 :
157 : EngravingItem& operator=(const EngravingItem&) = delete;
158 :
159 : virtual EngravingItem* clone() const = 0;
160 : virtual EngravingItem* linkedClone();
161 :
162 : void deleteLater();
163 :
164 : //! Item-typed variant of ownershipParent(); additionally null when the
165 : //! owner is not an item.
166 : EngravingItem* ownershipParentItem() const;
167 :
168 : //! The parent in the visual hierarchy, which positions are relative to.
169 : //! Defaults to the owner; overridden where placement differs from ownership
170 : //! (e.g. measures are placed on systems, but not owned by them).
171 : virtual EngravingItem* layoutParent() const;
172 :
173 : const std::shared_ptr<IEngravingConfiguration>& configuration() const;
174 : const muse::modularity::ContextPtr& iocContext() const;
175 : const std::shared_ptr<IEngravingContextConfiguration>& contextConfiguration() const;
176 : const std::shared_ptr<rendering::IScoreRenderer>& renderer() const;
177 :
178 : EngravingItem* findAncestor(ElementType t);
179 : const EngravingItem* findAncestor(ElementType t) const;
180 :
181 : Measure* findMeasure();
182 : const Measure* findMeasure() const;
183 : MeasureBase* findMeasureBase();
184 : const MeasureBase* findMeasureBase() const;
185 :
186 : //!Note muse::Returns basic representative for the current element.
187 : //! For example: notes->chord, chords->beam, etc.
188 0 : virtual EngravingItem* elementBase() const { return const_cast<EngravingItem*>(this); }
189 :
190 18278731 : virtual bool isEngravingItem() const override { return true; }
191 :
192 : double spatium() const;
193 : double defaultSpatium() const;
194 :
195 2556828 : inline void setFlag(ElementFlag f, bool v)
196 : {
197 2556828 : if (v) {
198 1022427 : m_flags |= f;
199 : } else {
200 1534401 : m_flags &= ~ElementFlags(f);
201 : }
202 2556828 : }
203 :
204 387440 : inline void setFlag(ElementFlag f, bool v) const
205 : {
206 387440 : if (v) {
207 42587 : m_flags |= f;
208 : } else {
209 344853 : m_flags &= ~ElementFlags(f);
210 : }
211 387440 : }
212 :
213 25544880 : inline bool flag(ElementFlag f) const { return m_flags & f; }
214 :
215 : bool selected() const;
216 : virtual void setSelected(bool f);
217 :
218 6284221 : bool visible() const { return !flag(ElementFlag::INVISIBLE); }
219 : virtual void setVisible(bool f);
220 :
221 : virtual bool isInteractionAvailable() const;
222 :
223 357626 : bool sizeIsSpatiumDependent() const override { return !flag(ElementFlag::SIZE_SPATIUM_DEPENDENT); }
224 48812 : void setSizeIsSpatiumDependent(bool v) { setFlag(ElementFlag::SIZE_SPATIUM_DEPENDENT, !v); }
225 : bool offsetIsSpatiumDependent() const override;
226 :
227 : virtual PointF defaultPos() const;
228 : virtual Sid defaultPosSid() const;
229 :
230 : PlacementV placement() const;
231 19371 : void setPlacement(PlacementV val) { setFlag(ElementFlag::PLACE_ABOVE, !bool(val)); }
232 121508 : bool placeAbove() const { return placement() == PlacementV::ABOVE; }
233 45532 : bool placeBelow() const { return placement() == PlacementV::BELOW; }
234 0 : virtual bool placeMultiple() const { return true; }
235 :
236 772690 : bool generated() const { return flag(ElementFlag::GENERATED); }
237 117249 : void setGenerated(bool val) { setFlag(ElementFlag::GENERATED, val); }
238 :
239 19108 : Spatium minDistance() const { return m_minDistance; }
240 15613 : void setMinDistance(Spatium v) { m_minDistance = v; }
241 :
242 : PointF systemPos() const;
243 : virtual PointF pagePos() const; ///< position in page coordinates
244 : virtual PointF canvasPos() const; ///< position in canvas coordinates
245 : double pageX() const;
246 : double canvasX() const;
247 :
248 0 : PointF mapFromCanvas(const PointF& p) const { return p - canvasPos(); }
249 : PointF mapToCanvas(const PointF& p) const { return p + canvasPos(); }
250 :
251 285705 : const PointF& offset() const { return m_offset; }
252 3333 : virtual void setOffset(const PointF& o) { m_offset = o; }
253 0 : void setOffset(double x, double y) { m_offset.setX(x), m_offset.setY(y); }
254 0 : PointF& roffset() { return m_offset; }
255 1415 : real_t& rxoffset() { return m_offset.rx(); }
256 27 : real_t& ryoffset() { return m_offset.ry(); }
257 :
258 : virtual Fraction tick() const;
259 : virtual Fraction rtick() const;
260 :
261 : Fraction beat() const;
262 :
263 82 : bool isNudged() const { return !m_offset.isNull(); }
264 :
265 : bool contains(const PointF& p) const;
266 : bool intersects(const RectF& r) const;
267 :
268 0 : virtual RectF hitBBox() const { return ldata()->bbox(); }
269 0 : virtual Shape hitShape() const { return shape(); }
270 0 : Shape canvasHitShape() const { return hitShape().translate(canvasPos()); }
271 : bool hitShapeContains(const PointF& p) const;
272 : bool hitShapeIntersects(const RectF& rr) const;
273 :
274 0 : virtual int subtype() const { return -1; } // for select gui
275 :
276 : // virtual ElementGroup getElementGroup() { return SingleElementGroup(this); }
277 0 : virtual std::unique_ptr<ElementGroup> getDragGroup(std::function<bool(const EngravingItem*)> /*isDragged*/)
278 : {
279 0 : return std::unique_ptr<ElementGroup>(new SingleElementGroup(this));
280 : }
281 :
282 : virtual void startDrag(EditData&);
283 : virtual RectF drag(EditData&);
284 : virtual void endDrag(EditData&);
285 : /** muse::Returns anchor lines displayed while dragging element in canvas coordinates. */
286 0 : virtual std::vector<LineF> dragAnchorLines() const { return std::vector<LineF>(); }
287 : /**
288 : * A generic \ref dragAnchorLines() implementation which can be used in
289 : * dragAnchorLines() overrides in descendants. It is not made its default
290 : * implementation in EngravingItem class since showing anchor lines is not
291 : * desirable for most element types.
292 : * TODO: maybe Annotation class could be extracted which would be a base
293 : * class of various annotation types and which would have this
294 : * dragAnchorLines() implementation by default.
295 : */
296 : std::vector<LineF> genericDragAnchorLines() const;
297 :
298 0 : virtual bool isEditable() const { return !flag(ElementFlag::GENERATED); }
299 0 : virtual bool needStartEditingAfterSelecting() const { return false; }
300 :
301 : virtual void startEdit(EditData&);
302 : virtual bool isEditAllowed(EditData&) const;
303 : virtual bool edit(EditData&);
304 : virtual void startDragGrip(EditData&);
305 : virtual void dragGrip(EditData&);
306 : virtual void endDragGrip(EditData&);
307 : virtual void endEdit(EditData&);
308 :
309 0 : virtual void editCut(EditData&) {}
310 0 : virtual void editCopy(EditData&) {}
311 :
312 : void updateGrips(EditData&) const;
313 : virtual bool nextGrip(EditData&) const;
314 : virtual bool prevGrip(EditData&) const;
315 : /** muse::Returns anchor lines displayed while dragging element's grip in canvas coordinates. */
316 0 : virtual std::vector<LineF> gripAnchorLines(Grip) const { return std::vector<LineF>(); }
317 :
318 0 : virtual int gripsCount() const { return 0; }
319 0 : virtual Grip initialEditModeGrip() const { return Grip::NO_GRIP; }
320 0 : virtual Grip defaultGrip() const { return Grip::NO_GRIP; }
321 : /** muse::Returns grips positions in page coordinates. */
322 0 : virtual std::vector<PointF> gripsPositions(const EditData& = EditData()) const { return std::vector<PointF>(); }
323 :
324 : bool hasGrips() const;
325 :
326 : track_idx_t track() const;
327 : virtual void setTrack(track_idx_t val);
328 :
329 : int z() const;
330 : virtual void setZ(int val);
331 :
332 : staff_idx_t staffIdx() const;
333 : void setStaffIdx(staff_idx_t val);
334 : virtual staff_idx_t effectiveStaffIdx() const; // for system objects migrating
335 : bool isTopSystemObject() const;
336 : virtual staff_idx_t vStaffIdx() const;
337 : voice_idx_t voice() const;
338 : void setVoice(voice_idx_t v);
339 : Staff* staff() const;
340 : bool hasStaff() const;
341 : const StaffType* staffType() const;
342 : bool onTabStaff() const;
343 : bool onJianpuStaff() const;
344 : Part* part() const;
345 : Part* originPart() const; // Delegates to an origin part for items in shared parts
346 :
347 : virtual void add(EngravingItem*);
348 : virtual void remove(EngravingItem*);
349 337064 : virtual void added() {}
350 16166 : virtual void removed() {}
351 : virtual void change(EngravingItem* o, EngravingItem* n);
352 :
353 : virtual void spatiumChanged(double /*oldValue*/, double /*newValue*/);
354 : virtual void localSpatiumChanged(double /*oldValue*/, double /*newValue*/);
355 :
356 : // debug functions
357 : virtual void dump() const;
358 : virtual TranslatableString subtypeUserName() const;
359 : virtual String translatedSubtypeUserName() const;
360 :
361 : virtual void setColor(const Color& c);
362 : virtual Color color() const;
363 : virtual Color curColor(const rendering::PaintOptions& opt) const;
364 : Color curColor(bool isVisible, const rendering::PaintOptions& opt) const;
365 : Color curColor(bool isVisible, Color normalColor, const rendering::PaintOptions& opt) const;
366 :
367 : void undoSetVisible(bool v);
368 : void undoAddElement(EngravingItem* element, bool addToLinkedStaves = true);
369 :
370 : static ElementType readType(XmlReader& node, PointF*, Fraction*);
371 : static EngravingItem* readMimeData(Score* score, const muse::ByteArray& data, PointF*, Fraction*);
372 :
373 : virtual muse::ByteArray mimeData(const PointF& dragOffset = PointF()) const;
374 : /**
375 : muse::Return true if this element accepts a drop at canvas relative \a pos
376 : of given element \a type and \a subtype.
377 :
378 : Reimplemented by elements that accept drops. Used to change cursor shape while
379 : dragging to indicate drop targets.
380 : */
381 2 : virtual bool acceptDrop(EditData&) const { return false; }
382 :
383 : /**
384 : Handle a dropped element at canvas relative \a pos of given element
385 : \a type and \a subtype. muse::Returns dropped element if any.
386 : The ownership of element in DropData is transferred to the called
387 : element (if not used, element has to be deleted).
388 : The returned element will be selected if not in note edit mode.
389 :
390 : Reimplemented by elements that accept drops.
391 : */
392 0 : virtual EngravingItem* drop(Transaction&, EditData&) { return 0; }
393 :
394 : mutable bool itemDiscovered = false; // helper flag for bsp
395 :
396 : void scanElements(std::function<void(EngravingItem*)> func) override;
397 : virtual bool collectForDrawing() const;
398 :
399 : virtual void reset() override; // reset all properties & position to default
400 :
401 : double magS() const;
402 :
403 : bool isPrintable() const;
404 : virtual bool isPlayable() const;
405 824080 : virtual double absoluteFromSpatium(const Spatium& sp) const { return sp.val() * spatium(); }
406 :
407 11679975 : bool systemFlag() const { return flag(ElementFlag::SYSTEM); }
408 29804 : void setSystemFlag(bool v) const { setFlag(ElementFlag::SYSTEM, v); }
409 :
410 : virtual bool isSystemObjectBelowBottomStaff() const;
411 :
412 247430 : bool header() const { return flag(ElementFlag::HEADER); }
413 81274 : void setHeader(bool v) { setFlag(ElementFlag::HEADER, v); }
414 :
415 351840 : bool trailer() const { return flag(ElementFlag::TRAILER); }
416 3949 : void setTrailer(bool val) { setFlag(ElementFlag::TRAILER, val); }
417 :
418 72 : bool selectable() const { return !flag(ElementFlag::NOT_SELECTABLE); }
419 231765 : void setSelectable(bool val) { setFlag(ElementFlag::NOT_SELECTABLE, !val); }
420 :
421 0 : bool dropTarget() const { return flag(ElementFlag::DROP_TARGET); }
422 6307 : void setDropTarget(bool v) const { setFlag(ElementFlag::DROP_TARGET, v); }
423 :
424 322196 : bool composition() const { return flag(ElementFlag::COMPOSITION); }
425 824 : void setComposition(bool v) const { setFlag(ElementFlag::COMPOSITION, v); }
426 :
427 0 : virtual bool isMovable() const { return flag(ElementFlag::MOVABLE); }
428 :
429 2511682 : bool enabled() const { return flag(ElementFlag::ENABLED); }
430 121622 : void setEnabled(bool val) { setFlag(ElementFlag::ENABLED, val); }
431 :
432 : bool autoplace() const;
433 2338 : virtual void setAutoplace(bool v) { setFlag(ElementFlag::NO_AUTOPLACE, !v); }
434 1263466 : bool addToSkyline() const { return !(m_flags & (ElementFlag::INVISIBLE | ElementFlag::NO_AUTOPLACE)) && !ldata()->isSkipDraw(); }
435 :
436 1394 : bool excludeVerticalAlign() const { return m_excludeVerticalAlign; }
437 0 : void setExcludeVerticalAlign(bool v) { m_excludeVerticalAlign = v; }
438 :
439 : PropertyValue getProperty(Pid) const override;
440 : bool setProperty(Pid, const PropertyValue&) override;
441 : void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
442 : using EngravingObject::undoChangeProperty;
443 : PropertyValue propertyDefault(Pid) const override;
444 :
445 : bool custom(Pid) const;
446 : virtual bool isUserModified() const;
447 :
448 : void drawSymbol(SymId id, muse::draw::Painter* p, const PointF& o = PointF(), double scale = 1.0) const;
449 : void drawSymbols(const SymIdList&, muse::draw::Painter* p, const PointF& o = PointF(), double scale = 1.0) const;
450 : void drawSymbols(const SymIdList&, muse::draw::Painter* p, const PointF& o, const SizeF& scale) const;
451 : double symHeight(SymId id) const;
452 : double symWidth(SymId id) const;
453 : double symWidth(const SymIdList&) const;
454 : RectF symBbox(SymId id) const;
455 : RectF symBbox(const SymIdList&) const;
456 : virtual Shape symShapeWithCutouts(SymId id) const;
457 :
458 : PointF symSmuflAnchor(SymId symId, SmuflAnchorId anchorId) const;
459 :
460 : double symAdvance(SymId id) const;
461 : bool symIsValid(SymId id) const;
462 :
463 : bool concertPitch() const;
464 : virtual EngravingItem* nextElement(); // selects the next score element, (notes, rests etc. as well as articulation etc.)
465 : virtual EngravingItem* prevElement(); // selects the next score element, (notes, rests etc. as well as articulation etc.)
466 : virtual EngravingItem* nextSegmentElement(); //< Used for navigation
467 : virtual EngravingItem* prevSegmentElement(); //< next-element and prev-element command
468 :
469 : #ifndef ENGRAVING_NO_ACCESSIBILITY
470 : virtual void setupAccessible();
471 : AccessibleItemPtr accessible() const;
472 : void initAccessibleIfNeed();
473 : #endif
474 :
475 : bool accessibleEnabled() const;
476 : void setAccessibleEnabled(bool enabled);
477 :
478 : //! Parent in the accessibility hierarchy: the layout parent when placed; the head of
479 : //! the tree the unattached objects form when attached to nothing; null in between,
480 : //! i.e. while attached to something that does not place it.
481 : virtual EngravingItem* accessibleParentItem() const;
482 : //! Children in the accessibility hierarchy: the items that name this one as their
483 : //! accessibleParentItem(). Those are the children it owns, unless ownership and
484 : //! placement diverge, in which case the item that places them lists them instead.
485 : virtual EngravingItemList accessibleChildren() const;
486 :
487 : virtual String accessibleInfo() const;
488 0 : virtual String screenReaderInfo() const { return accessibleInfo(); }
489 : // if the screen-reader needs a special string (see note for example)
490 : // used to return info that will be appended to accessibleInfo
491 0 : virtual String accessibleExtraInfo() const { return String(); }
492 : virtual String formatBarsAndBeats() const;
493 :
494 : virtual void triggerLayout() const;
495 : virtual void triggerLayoutAll() const;
496 : virtual void triggerLayoutToEnd() const;
497 :
498 : double styleP(Sid idx) const;
499 :
500 : virtual void setParenthesesMode(const ParenthesesMode& v, bool addToLinked = true, bool generated = false);
501 : ParenthesesMode parenthesesMode() const;
502 80 : inline Parenthesis* paren(const DirectionH& dir) const { return dir == DirectionH::LEFT ? m_leftParenthesis : m_rightParenthesis; }
503 3546323 : Parenthesis* leftParen() const { return m_leftParenthesis; }
504 3546323 : Parenthesis* rightParen() const { return m_rightParenthesis; }
505 : void setLeftParen(Parenthesis* paren) { m_leftParenthesis = paren; }
506 : void setRightParen(Parenthesis* paren) { m_rightParenthesis = paren; }
507 :
508 : struct BarBeat
509 : {
510 : int bar = 0;
511 : int displayedBar = 0;
512 : double beat = 0.0;
513 : };
514 : BarBeat barbeat() const;
515 :
516 : virtual EngravingItem* findLinkedInScore(const Score* score) const;
517 : EngravingItem* findLinkedInStaff(const Staff* staff) const;
518 :
519 : struct LayoutData {
520 810724 : virtual ~LayoutData() = default;
521 :
522 656578 : virtual void reset()
523 : {
524 656578 : m_shape.reset();
525 656578 : m_mask.reset();
526 : //! NOTE Temporary removed, have problems, need investigation
527 : //m_pos.reset();
528 656578 : }
529 :
530 713621 : virtual bool isValid() const { return m_shape.has_value() && m_shape.value().bbox().isValid(); }
531 :
532 1327080 : bool isSkipDraw() const { return m_isSkipDraw; }
533 226496 : void setIsSkipDraw(bool val) { m_isSkipDraw = val; }
534 :
535 5490498 : double mag() const { return m_mag; }
536 731039 : void setMag(double val) { m_mag = val; }
537 :
538 122538 : bool isSetPos() const { return m_pos.has_value(); }
539 12612723 : const PointF& pos(LD_ACCESS mode = LD_ACCESS::CHECK) const
540 : {
541 : //! NOTE Temporarily to mute a lot of messages
542 12612723 : mode = (LD_ACCESS::CHECK == mode) ? LD_ACCESS::MAYBE_NOTINITED : mode;
543 12612723 : return m_pos.value(mode);
544 : }
545 :
546 218443 : void setPos(const PointF& p) { doSetPos(p.x(), p.y()); }
547 325268 : void setPos(double x, double y) { doSetPos(x, y); }
548 1363957 : void setPosX(double x) { doSetPos(x, pos(LD_ACCESS::MAYBE_NOTINITED).y()); }
549 561862 : void setPosY(double y) { doSetPos(pos(LD_ACCESS::MAYBE_NOTINITED).x(), y); }
550 87690 : void move(const PointF& p) { doSetPos(pos(LD_ACCESS::MAYBE_NOTINITED).x() + p.x(), pos(LD_ACCESS::MAYBE_NOTINITED).y() + p.y()); }
551 175361 : void moveX(double x) { doSetPos(pos(LD_ACCESS::MAYBE_NOTINITED).x() + x, pos(LD_ACCESS::MAYBE_NOTINITED).y()); }
552 50566 : void moveY(double y) { doSetPos(pos(LD_ACCESS::MAYBE_NOTINITED).x(), pos(LD_ACCESS::MAYBE_NOTINITED).y() + y); }
553 :
554 90840 : bool isSetBbox() const { return m_shape.has_value(); }
555 57 : void clearBbox() { m_shape.reset(); }
556 : const RectF& bbox(LD_ACCESS mode = LD_ACCESS::CHECK) const;
557 :
558 263500 : bool isSetShape() const { return m_shape.has_value(); }
559 : void clearShape() { m_shape.reset(); }
560 : Shape shape(LD_ACCESS mode = LD_ACCESS::CHECK) const;
561 :
562 1191573 : void setShape(const Shape& sh) { m_shape.set_value(sh); }
563 :
564 : void setBbox(const RectF& r);
565 :
566 366258 : void setBbox(double x, double y, double w, double h) { setBbox(RectF(x, y, w, h)); }
567 0 : void addBbox(const RectF& r)
568 : {
569 0 : DO_ASSERT(!std::isnan(r.x()) && !std::isinf(r.x()));
570 0 : DO_ASSERT(!std::isnan(r.y()) && !std::isinf(r.y()));
571 0 : DO_ASSERT(!std::isnan(r.width()) && !std::isinf(r.width()));
572 0 : DO_ASSERT(!std::isnan(r.height()) && !std::isinf(r.height()));
573 :
574 : //DO_ASSERT(!isShapeComposite());
575 0 : mutShape().addBBox(r);
576 0 : }
577 :
578 58373 : void setHeight(double v)
579 : {
580 58373 : RectF r = bbox();
581 58373 : r.setHeight(v);
582 58373 : setBbox(r);
583 58373 : }
584 :
585 866162 : void setWidth(double v)
586 : {
587 : #ifndef NDEBUG
588 866162 : setWidthDebugHook(v);
589 : #endif
590 866162 : RectF r = bbox();
591 866162 : r.setWidth(v);
592 866162 : setBbox(r);
593 866162 : }
594 :
595 15255 : void setMask(const Shape& m) { m_mask.set_value(m); }
596 50 : const Shape& mask() const { return m_mask.value(); }
597 :
598 : void connectItemSnappedBefore(EngravingItem* itemBefore);
599 : void disconnectItemSnappedBefore();
600 : void connectItemSnappedAfter(EngravingItem* itemAfter);
601 : void disconnectItemSnappedAfter();
602 2949 : void disconnectSnappedItems() { disconnectItemSnappedBefore(); disconnectItemSnappedAfter(); }
603 361684 : EngravingItem* itemSnappedBefore() const { return m_itemSnappedBefore; }
604 361847 : EngravingItem* itemSnappedAfter() const { return m_itemSnappedAfter; }
605 : void scanConnectedItemsInSnappingChain(const System* system, const std::function<void(EngravingItem*)>& func) const;
606 :
607 : void dump(std::stringstream& ss) const;
608 :
609 : protected:
610 :
611 0 : virtual void supDump(std::stringstream& ss) const { UNUSED(ss); }
612 :
613 : #ifndef NDEBUG
614 : void doSetPosDebugHook(double x, double y);
615 : void setWidthDebugHook(double w);
616 : #endif
617 :
618 2783147 : inline void doSetPos(double x, double y)
619 : {
620 : #ifndef NDEBUG
621 2783147 : doSetPosDebugHook(x, y);
622 : #endif
623 2783147 : m_pos.mut_value().setX(x),
624 2783147 : m_pos.mut_value().setY(y);
625 2783147 : }
626 :
627 0 : Shape& mutShape() { return m_shape.mut_value(); }
628 : bool isShapeComposite() const { return m_shape.has_value() && m_shape.value().isComposite(); }
629 :
630 : friend class EngravingItem;
631 :
632 : const EngravingItem* m_item = nullptr;
633 : bool m_isSkipDraw = false;
634 : double m_mag = 1.0; // standard magnification (derived value)
635 : ld_field<PointF> m_pos = "pos"; // Reference position, relative to _parent, set by autoplace
636 : ld_field<Shape> m_shape = "shape";
637 : ld_field<Shape> m_mask = "mask";
638 :
639 : EngravingItem* m_itemSnappedBefore = nullptr;
640 : EngravingItem* m_itemSnappedAfter = nullptr;
641 :
642 : // STAVE SHARING
643 : EngravingItem* m_sharedItem = nullptr;
644 : std::vector<EngravingItem*> m_originItems;
645 : };
646 :
647 : const LayoutData* ldata() const;
648 : LayoutData* mutldata();
649 :
650 : virtual double mag() const;
651 3026605 : Shape shape(LD_ACCESS mode = LD_ACCESS::CHECK) const { return ldata()->shape(mode); }
652 0 : virtual double baseLine() const { return -height(); }
653 :
654 20685 : RectF pageBoundingRect(LD_ACCESS mode = LD_ACCESS::CHECK) const { return ldata()->bbox(mode).translated(pagePos()); }
655 27159 : RectF canvasBoundingRect(LD_ACCESS mode = LD_ACCESS::CHECK) const { return ldata()->bbox(mode).translated(canvasPos()); }
656 :
657 : virtual PointF staffOffset() const;
658 56006 : double staffOffsetY() const { return staffOffset().y(); }
659 :
660 : virtual bool isPropertyLinkedToMaster(Pid id) const;
661 : virtual bool isUnlinkedFromMaster() const;
662 : void unlinkPropertyFromMaster(Pid id);
663 : void relinkPropertiesToMaster(PropertyGroup propGroup);
664 : void relinkPropertyToMaster(Pid propertyId);
665 : PropertyPropagation propertyPropagation(const EngravingItem* destinationItem, Pid propertyId) const;
666 0 : virtual bool canBeExcludedFromOtherParts() const { return false; }
667 : virtual void manageExclusionFromParts(bool exclude);
668 :
669 : EngravingItem* sharedItem() const;
670 : const std::vector<EngravingItem*>& originItems() const;
671 : static void connectSharedItem(EngravingItem* sharedItem, EngravingItem* originItem);
672 : static void disconnectSharedItem(EngravingItem* sharedItem, EngravingItem* originItem);
673 : static void disconnectAllOriginItems(EngravingItem* sharedItem);
674 : static void disconnectSharedTree(EngravingItem* item);
675 :
676 : virtual bool isBefore(const EngravingItem* item) const;
677 :
678 : /** The staff this item would be centered against if it were centered between staves, or
679 : * nullptr if there is none. `system` limits the search to the staves visible on that
680 : * system; if null, the system this item is laid out on is used.
681 : */
682 : const Staff* staffToCenterAgainst(bool above, const System* system = nullptr) const;
683 :
684 : //! --- Old Interface ---
685 8289 : void setbbox(const RectF& r) { mutldata()->setBbox(r); }
686 98660 : double height() const { return ldata()->bbox().height(); }
687 56729 : void setHeight(double v) { mutldata()->setHeight(v); }
688 :
689 1462664 : double width(LD_ACCESS mode = LD_ACCESS::CHECK) const { return ldata()->bbox(mode).width(); }
690 866162 : void setWidth(double v) { mutldata()->setWidth(v); }
691 :
692 4808283 : virtual const PointF pos() const { return ldata()->pos() + m_offset; }
693 2519349 : virtual double x() const { return ldata()->pos().x() + m_offset.x(); }
694 1159928 : virtual double y() const { return ldata()->pos().y() + m_offset.y(); }
695 250981 : virtual void setPos(double x, double y) { mutldata()->setPos(x, y); }
696 59900 : virtual void setPos(const PointF& p) { mutldata()->setPos(p.x(), p.y()); }
697 :
698 2574 : virtual void move(const PointF& s) { mutldata()->move(s); }
699 :
700 0 : virtual bool allowTimeAnchor() const { return false; }
701 :
702 80204 : virtual bool hasVoiceAssignmentProperties() const { return false; }
703 : bool appliesToAllVoicesInInstrument() const;
704 : void setInitialTrackAndVoiceAssignment(track_idx_t track, bool curVoiceOnlyOverride);
705 : void checkVoiceAssignmentCompatibleWithTrack();
706 : virtual bool elementAppliesToTrack(const track_idx_t refTrack) const;
707 : void setPlacementBasedOnVoiceAssignment(DirectionV styledDirection);
708 : //! ---------------------
709 :
710 : protected:
711 211241 : EngravingItem(const ElementType& type, EngravingObject* parent = nullptr, ElementFlags = ElementFlag::NOTHING);
712 : EngravingItem(const EngravingItem&, bool link = false);
713 :
714 : #ifndef ENGRAVING_NO_ACCESSIBILITY
715 : virtual AccessibleItemPtr createAccessible();
716 : void notifyAboutNameChanged();
717 : #endif
718 :
719 : virtual LayoutData* createLayoutData() const;
720 : virtual const LayoutData* ldataInternal() const;
721 : virtual LayoutData* mutldataInternal();
722 :
723 : mutable int m_z = 0;
724 : Color m_color; // element color attribute
725 :
726 : track_idx_t m_track = muse::nidx; // staffIdx * VOICES + voice
727 :
728 : static bool elementAppliesToTrack(const track_idx_t elementTrack, const track_idx_t refTrack, const VoiceAssignment voiceAssignment,
729 : const Part* part);
730 :
731 : private:
732 :
733 : friend class Factory;
734 :
735 : #ifndef ENGRAVING_NO_ACCESSIBILITY
736 : void doInitAccessible();
737 : AccessibleItemPtr m_accessible;
738 : #endif
739 :
740 : bool m_accessibleEnabled = false;
741 :
742 : PointF m_offset; // offset from reference position, set by autoplace or user
743 :
744 : Spatium m_minDistance; // autoplace min distance
745 : mutable ElementFlags m_flags;
746 :
747 : bool m_excludeVerticalAlign = false;
748 :
749 : mutable LayoutData* m_layoutData = nullptr;
750 :
751 : Parenthesis* m_leftParenthesis = nullptr;
752 : Parenthesis* m_rightParenthesis = nullptr;
753 : void setHasLeftParenthesis(bool v, bool addToLinked = true, bool generated = false);
754 : void setHasRightParenthesis(bool v, bool addToLinked = true, bool generated = false);
755 : };
756 :
757 : using ElementPtr = std::shared_ptr<EngravingItem>;
758 :
759 : //---------------------------------------------------------
760 : // ElementList
761 : //---------------------------------------------------------
762 :
763 : class ElementList : public std::vector<EngravingItem*>
764 : {
765 : OBJECT_ALLOCATOR(engraving, ElementList)
766 : public:
767 161325 : ElementList() {}
768 : bool remove(EngravingItem*);
769 : void replace(EngravingItem* old, EngravingItem* n);
770 : };
771 :
772 : extern bool elementLessThan(const EngravingItem* const, const EngravingItem* const);
773 : } // mu::engraving
774 :
775 : #ifndef NO_QT_SUPPORT
776 0 : Q_DECLARE_METATYPE(mu::engraving::ElementPtr)
777 0 : Q_DECLARE_METATYPE(mu::engraving::ElementType)
778 : #endif
|