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 : #include "rehearsalmark.h"
24 :
25 : #include "measure.h"
26 : #include "score.h"
27 : #include "system.h"
28 :
29 : using namespace mu;
30 :
31 : namespace mu::engraving {
32 : //---------------------------------------------------------
33 : // rehearsalMarkStyle
34 : //---------------------------------------------------------
35 :
36 : static const ElementStyle rehearsalMarkStyle {
37 : { Sid::rehearsalMarkPlacement, Pid::PLACEMENT },
38 : { Sid::rehearsalMarkMinDistance, Pid::MIN_DISTANCE },
39 : };
40 :
41 : static const ElementStyle mainRehearsalMarkStyle {
42 : { Sid::rehearsalMarkFrameType, Pid::FRAME_TYPE },
43 : { Sid::rehearsalMarkFontSize, Pid::FONT_SIZE },
44 : { Sid::rehearsalMarkAlign, Pid::ALIGN },
45 : };
46 :
47 : static const ElementStyle additionalRehearsalMarkStyle {
48 : { Sid::tempoFrameType, Pid::FRAME_TYPE },
49 : { Sid::tempoFontSize, Pid::FONT_SIZE },
50 : { Sid::tempoAlign, Pid::ALIGN },
51 : };
52 :
53 : //---------------------------------------------------------
54 : // RehearsalMark
55 : //---------------------------------------------------------
56 :
57 91 : RehearsalMark::RehearsalMark(DummyParentOr<Segment> parent)
58 91 : : TextBase(ElementType::REHEARSAL_MARK, parent, TextStyleType::REHEARSAL_MARK, ElementFlag::ON_STAFF)
59 : {
60 91 : initElementStyle(&rehearsalMarkStyle);
61 91 : setSystemFlag(true);
62 91 : }
63 :
64 : //---------------------------------------------------------
65 : // isEditAllowed
66 : //---------------------------------------------------------
67 :
68 0 : bool RehearsalMark::isEditAllowed(EditData& ed) const
69 : {
70 0 : bool ctrlPressed = ed.modifiers & ControlModifier;
71 0 : bool shiftPressed = ed.modifiers & ShiftModifier;
72 0 : bool altPressed = ed.modifiers & AltModifier;
73 0 : if (altPressed && !ctrlPressed && !shiftPressed && (ed.key == Key_Left || ed.key == Key_Right)) {
74 0 : return false;
75 : }
76 :
77 0 : return TextBase::isEditAllowed(ed);
78 : }
79 :
80 0 : RectF RehearsalMark::drag(EditData& ed)
81 : {
82 : // Not TextBase::drag because we don't allow reanchoring on drag
83 0 : return EngravingItem::drag(ed);
84 : }
85 :
86 : //---------------------------------------------------------
87 : // setType
88 : //---------------------------------------------------------
89 :
90 7 : void RehearsalMark::setType(RehearsalMark::Type type)
91 : {
92 7 : if (type == m_type) {
93 0 : return;
94 : }
95 7 : m_type = type;
96 7 : applyTypeStyle();
97 : }
98 :
99 9 : void RehearsalMark::applyTypeStyle()
100 : {
101 9 : const auto& elemStyleMap = (m_type == Type::Main ? mainRehearsalMarkStyle : additionalRehearsalMarkStyle);
102 36 : for (const auto& elem : elemStyleMap) {
103 27 : if (propertyFlags(elem.pid) == PropertyFlags::STYLED) {
104 27 : setProperty(elem.pid, style().styleV(elem.sid));
105 : }
106 : }
107 9 : }
108 :
109 2 : void RehearsalMark::styleChanged()
110 : {
111 2 : TextBase::styleChanged();
112 2 : applyTypeStyle();
113 2 : }
114 :
115 : //---------------------------------------------------------
116 : // propertyDefault
117 : //---------------------------------------------------------
118 :
119 609 : engraving::PropertyValue RehearsalMark::propertyDefault(Pid id) const
120 : {
121 609 : switch (id) {
122 50 : case Pid::TEXT_STYLE:
123 50 : return TextStyleType::REHEARSAL_MARK;
124 7 : case Pid::PLACEMENT:
125 7 : return style().styleV(Sid::rehearsalMarkPlacement);
126 552 : default:
127 552 : return TextBase::propertyDefault(id);
128 : }
129 : }
130 : } // namespace mu::engraving
|