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 "engravingitem.h"
26 : #include "score.h"
27 :
28 : namespace mu::engraving {
29 : class Factory;
30 :
31 : class EditTimeTickAnchors
32 : {
33 : public:
34 : static void updateAnchors(const EngravingItem* item);
35 : static void updateAnchors(Measure* measure, staff_idx_t staffIdx, const std::set<Fraction>& additionalAnchorRelTicks = {});
36 : static TimeTickAnchor* createTimeTickAnchor(Measure* measure, Fraction relTick, staff_idx_t staffIdx);
37 : static void updateLayout(Measure* measure);
38 : };
39 :
40 : class MoveElementAnchors
41 : {
42 : public:
43 : static void moveElementAnchors(EngravingItem* element, KeyboardKey key, KeyboardModifier mod);
44 : static void moveSegment(EngravingItem* element, Segment* newSeg, Fraction tickDiff);
45 : static void checkMeasureBoundariesAndMoveIfNeed(EngravingItem* element);
46 :
47 : static void moveElementAnchorsOnDrag(EngravingItem* element, EditData& ed);
48 :
49 : static Segment* findNewAnchorSegmentForLine(LineSegment* lineSegment, const EditData& ed, const Segment* curSeg);
50 :
51 : private:
52 : static bool canAnchorToEndOfPrevious(const EngravingItem* element);
53 : static void moveSegment(EngravingItem* element, bool forward);
54 : static Segment* getNewSegment(EngravingItem* element, Segment* curSeg, bool forward);
55 : static Segment* findNewAnchorableSegment(const Segment* curSeg, bool forward);
56 : static Segment* findNewAnchorableSegmentFromDrag(EngravingItem* element, Segment* curSeg);
57 :
58 : static void doMoveSegment(EngravingItem* element, Segment* newSeg, Fraction tickDiff);
59 : static void doMoveSegment(FiguredBass* element, Segment* newSeg, Fraction tickDiff);
60 : static void doMoveHarmonyOrFretDiagramSegment(EngravingItem* element, Segment* newSeg, Fraction tickDiff);
61 :
62 : static void moveSnappedItems(EngravingItem* element, Segment* newSeg, Fraction tickDiff);
63 : static void rebaseOffsetOnMoveSegment(EngravingItem* element, const PointF& curOffset, Segment* newSeg, Segment* oldSeg);
64 : };
65 :
66 : class TimeTickAnchor : public EngravingItem
67 : {
68 : TimeTickAnchor(DummyParentOr<Segment> parent);
69 : friend class Factory;
70 :
71 : public:
72 662 : Segment* segment() const { return toSegment(ownershipParentItem()); }
73 :
74 0 : TimeTickAnchor* clone() const override { return new TimeTickAnchor(*this); }
75 :
76 : enum class DrawRegion : unsigned char {
77 : OUT_OF_RANGE,
78 : EXTENDED_REGION,
79 : MAIN_REGION
80 : };
81 :
82 : DrawRegion drawRegion() const;
83 :
84 : voice_idx_t voiceIdx() const;
85 :
86 : struct LayoutData : public EngravingItem::LayoutData {
87 0 : bool darker() const { return m_darker; }
88 498 : void setDarker(bool v) { m_darker = v; }
89 :
90 : private:
91 : bool m_darker = false;
92 : };
93 1208 : DECLARE_LAYOUTDATA_METHODS(TimeTickAnchor)
94 : };
95 : }
|