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 "letring.h"
24 :
25 : #include "dummyparent.h"
26 : #include "score.h"
27 : #include "system.h"
28 : #include "text.h"
29 :
30 : #include "log.h"
31 :
32 : using namespace mu;
33 : using namespace mu::engraving;
34 :
35 : namespace mu::engraving {
36 : static const ElementStyle letRingStyle {
37 : { Sid::letRingFontFace, Pid::BEGIN_FONT_FACE },
38 : { Sid::letRingFontFace, Pid::CONTINUE_FONT_FACE },
39 : { Sid::letRingFontFace, Pid::END_FONT_FACE },
40 : { Sid::letRingFontSize, Pid::BEGIN_FONT_SIZE },
41 : { Sid::letRingFontSize, Pid::CONTINUE_FONT_SIZE },
42 : { Sid::letRingFontSize, Pid::END_FONT_SIZE },
43 : { Sid::letRingFontStyle, Pid::BEGIN_FONT_STYLE },
44 : { Sid::letRingFontStyle, Pid::CONTINUE_FONT_STYLE },
45 : { Sid::letRingFontStyle, Pid::END_FONT_STYLE },
46 : { Sid::letRingTextAlign, Pid::BEGIN_TEXT_ALIGN },
47 : { Sid::letRingTextAlign, Pid::CONTINUE_TEXT_ALIGN },
48 : { Sid::letRingTextAlign, Pid::END_TEXT_ALIGN },
49 : { Sid::letRingPosition, Pid::BEGIN_TEXT_POSITION },
50 : { Sid::letRingPosition, Pid::CONTINUE_TEXT_POSITION },
51 : { Sid::letRingPosition, Pid::END_TEXT_POSITION },
52 : { Sid::letRingHookHeight, Pid::BEGIN_HOOK_HEIGHT },
53 : { Sid::letRingHookHeight, Pid::END_HOOK_HEIGHT },
54 : { Sid::letRingLineStyle, Pid::LINE_STYLE },
55 : { Sid::letRingDashLineLen, Pid::DASH_LINE_LEN },
56 : { Sid::letRingDashGapLen, Pid::DASH_GAP_LEN },
57 : { Sid::letRingFontSpatiumDependent, Pid::TEXT_SIZE_SPATIUM_DEPENDENT },
58 : { Sid::letRingEndHookType, Pid::END_HOOK_TYPE },
59 : { Sid::letRingLineWidth, Pid::LINE_WIDTH },
60 : { Sid::letRingPlacement, Pid::PLACEMENT },
61 : { Sid::letRingMusicalSymbolSize, Pid::BEGIN_TEXT_MUSIC_SYMBOLS_SIZE },
62 : { Sid::letRingMusicalSymbolSize, Pid::CONTINUE_TEXT_MUSIC_SYMBOLS_SIZE },
63 : { Sid::letRingMusicalSymbolSize, Pid::END_TEXT_MUSIC_SYMBOLS_SIZE },
64 : { Sid::dummyMusicalSymbolsScale, Pid::BEGIN_TEXT_MUSICAL_SYMBOLS_SCALE },
65 : { Sid::dummyMusicalSymbolsScale, Pid::CONTINUE_TEXT_MUSICAL_SYMBOLS_SCALE },
66 : { Sid::dummyMusicalSymbolsScale, Pid::END_TEXT_MUSICAL_SYMBOLS_SCALE },
67 : };
68 :
69 31 : LetRingSegment::LetRingSegment(LetRing* sp)
70 31 : : TextLineBaseSegment(ElementType::LET_RING_SEGMENT, sp, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
71 : {
72 31 : m_text->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
73 31 : m_endText->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
74 31 : }
75 :
76 : //---------------------------------------------------------
77 : // LetRing
78 : //---------------------------------------------------------
79 :
80 88 : LetRing::LetRing(DummyParent* parent)
81 88 : : ChordTextLineBase(ElementType::LET_RING, parent)
82 : {
83 88 : initElementStyle(&letRingStyle);
84 88 : resetProperty(Pid::LINE_VISIBLE);
85 :
86 88 : resetProperty(Pid::BEGIN_TEXT_PLACE);
87 88 : resetProperty(Pid::BEGIN_TEXT);
88 88 : resetProperty(Pid::CONTINUE_TEXT_PLACE);
89 88 : resetProperty(Pid::CONTINUE_TEXT);
90 88 : resetProperty(Pid::END_TEXT_PLACE);
91 88 : resetProperty(Pid::END_TEXT);
92 88 : }
93 :
94 : static const ElementStyle letRingSegmentStyle {
95 : { Sid::letRingMinDistance, Pid::MIN_DISTANCE },
96 : };
97 :
98 : //---------------------------------------------------------
99 : // createLineSegment
100 : //---------------------------------------------------------
101 :
102 31 : LineSegment* LetRing::createLineSegment()
103 : {
104 31 : LetRingSegment* lr = new LetRingSegment(this);
105 31 : lr->setTrack(track());
106 31 : lr->initElementStyle(&letRingSegmentStyle);
107 31 : return lr;
108 : }
109 :
110 : //---------------------------------------------------------
111 : // propertyDefault
112 : //---------------------------------------------------------
113 :
114 2276 : PropertyValue LetRing::propertyDefault(Pid propertyId) const
115 : {
116 2276 : switch (propertyId) {
117 2 : case Pid::LINE_WIDTH:
118 2 : return style().styleV(Sid::letRingLineWidth);
119 :
120 0 : case Pid::ALIGN:
121 0 : return Align(AlignH::LEFT, AlignV::BASELINE);
122 :
123 2 : case Pid::LINE_STYLE:
124 2 : return style().styleV(Sid::letRingLineStyle);
125 :
126 140 : case Pid::LINE_VISIBLE:
127 140 : return true;
128 :
129 156 : case Pid::BEGIN_TEXT_OFFSET:
130 : case Pid::CONTINUE_TEXT_OFFSET:
131 : case Pid::END_TEXT_OFFSET:
132 156 : return PropertyValue::fromValue(PointF(0, 0));
133 :
134 2 : case Pid::BEGIN_FONT_STYLE:
135 2 : return style().styleV(Sid::letRingFontStyle);
136 :
137 280 : case Pid::BEGIN_TEXT:
138 : case Pid::CONTINUE_TEXT:
139 280 : return style().styleV(Sid::letRingText);
140 140 : case Pid::END_TEXT:
141 140 : return "";
142 :
143 52 : case Pid::BEGIN_HOOK_TYPE:
144 52 : return HookType::NONE;
145 :
146 420 : case Pid::BEGIN_TEXT_PLACE:
147 : case Pid::CONTINUE_TEXT_PLACE:
148 : case Pid::END_TEXT_PLACE:
149 420 : return TextPlace::AUTO;
150 62 : case Pid::TEXT_STYLE:
151 62 : return TextStyleType::LET_RING;
152 :
153 416 : case Pid::BEGIN_FILLED_ARROW_HEIGHT: // No arrow endings for let ring
154 : case Pid::BEGIN_FILLED_ARROW_WIDTH:
155 : case Pid::END_FILLED_ARROW_HEIGHT:
156 : case Pid::END_FILLED_ARROW_WIDTH:
157 : case Pid::BEGIN_LINE_ARROW_HEIGHT:
158 : case Pid::BEGIN_LINE_ARROW_WIDTH:
159 : case Pid::END_LINE_ARROW_HEIGHT:
160 : case Pid::END_LINE_ARROW_WIDTH:
161 416 : return 0.0;
162 :
163 604 : default:
164 604 : return TextLineBase::propertyDefault(propertyId);
165 : }
166 : }
167 :
168 : //---------------------------------------------------------
169 : // getPropertyStyle
170 : //---------------------------------------------------------
171 :
172 2874 : Sid LetRing::getPropertyStyle(Pid id) const
173 : {
174 2874 : switch (id) {
175 95 : case Pid::PLACEMENT:
176 95 : return Sid::letRingPlacement;
177 95 : case Pid::BEGIN_FONT_FACE:
178 95 : return Sid::letRingFontFace;
179 285 : case Pid::BEGIN_FONT_SIZE:
180 : case Pid::CONTINUE_FONT_SIZE:
181 : case Pid::END_FONT_SIZE:
182 285 : return Sid::letRingFontSize;
183 283 : case Pid::BEGIN_FONT_STYLE:
184 : case Pid::CONTINUE_FONT_STYLE:
185 : case Pid::END_FONT_STYLE:
186 283 : return Sid::letRingFontStyle;
187 285 : case Pid::BEGIN_TEXT_ALIGN:
188 : case Pid::CONTINUE_TEXT_ALIGN:
189 : case Pid::END_TEXT_ALIGN:
190 285 : return Sid::letRingTextAlign;
191 190 : case Pid::BEGIN_HOOK_HEIGHT:
192 : case Pid::END_HOOK_HEIGHT:
193 190 : return Sid::letRingHookHeight;
194 0 : case Pid::BEGIN_TEXT:
195 0 : return Sid::letRingText;
196 1641 : default:
197 1641 : break;
198 : }
199 1641 : return TextLineBase::getPropertyStyle(id);
200 : }
201 :
202 31 : Sid LetRing::defaultPosSid() const
203 : {
204 31 : return placeAbove() ? Sid::letRingPosAbove : Sid::letRingPosBelow;
205 : }
206 : }
|