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 "log.h"
24 :
25 : #include "iengravingconfiguration.h" // IWYU pragma: keep
26 :
27 : #include "types/typesconv.h"
28 :
29 : #include "layoutbreak.h"
30 : #include "measurebase.h"
31 : #include "score.h"
32 :
33 : using namespace mu;
34 : using namespace muse::draw;
35 : using namespace mu::engraving;
36 :
37 : namespace mu::engraving {
38 : //---------------------------------------------------------
39 : // sectionBreakStyle
40 : //---------------------------------------------------------
41 :
42 : static const ElementStyle sectionBreakStyle {
43 : { Sid::sectionPause, Pid::PAUSE }
44 : };
45 :
46 : //---------------------------------------------------------
47 : // LayoutBreak
48 : //---------------------------------------------------------
49 :
50 942 : LayoutBreak::LayoutBreak(DummyParentOr<MeasureBase> parent)
51 942 : : EngravingItem(ElementType::LAYOUT_BREAK, parent, ElementFlag::SYSTEM)
52 : {
53 942 : m_pause = 0.;
54 942 : m_startWithLongNames = false;
55 942 : m_startWithMeasureOne = false;
56 942 : m_firstSystemIndentation = false;
57 942 : m_showCourtesy = false;
58 942 : m_layoutBreakType = LayoutBreakType::PAGE;
59 :
60 942 : initElementStyle(§ionBreakStyle);
61 :
62 942 : resetProperty(Pid::PAUSE);
63 942 : resetProperty(Pid::START_WITH_LONG_NAMES);
64 942 : resetProperty(Pid::START_WITH_MEASURE_ONE);
65 942 : resetProperty(Pid::FIRST_SYSTEM_INDENTATION);
66 942 : resetProperty(Pid::SHOW_COURTESY);
67 942 : }
68 :
69 0 : LayoutBreak::LayoutBreak(const LayoutBreak& lb)
70 0 : : EngravingItem(lb)
71 : {
72 0 : m_layoutBreakType = lb.m_layoutBreakType;
73 0 : m_pause = lb.m_pause;
74 0 : m_startWithLongNames = lb.m_startWithLongNames;
75 0 : m_startWithMeasureOne = lb.m_startWithMeasureOne;
76 0 : m_firstSystemIndentation = lb.m_firstSystemIndentation;
77 0 : m_showCourtesy = lb.m_showCourtesy;
78 0 : }
79 :
80 0 : void LayoutBreak::setOwnershipParent(DummyParentOr<MeasureBase> parent)
81 : {
82 0 : EngravingItem::setOwnershipParent(parent);
83 0 : }
84 :
85 0 : char16_t LayoutBreak::iconCode() const
86 : {
87 0 : switch (m_layoutBreakType) {
88 0 : case LayoutBreakType::LINE:
89 0 : return 0xF483;
90 0 : case LayoutBreakType::PAGE:
91 0 : return 0xF484;
92 0 : case LayoutBreakType::SECTION:
93 0 : return 0xF485;
94 0 : case LayoutBreakType::NOBREAK:
95 0 : return 0xF486;
96 0 : default:
97 0 : return 0x000;
98 : }
99 : }
100 :
101 : //---------------------------------------------------------
102 : // setLayoutBreakType
103 : //---------------------------------------------------------
104 :
105 942 : void LayoutBreak::setLayoutBreakType(LayoutBreakType val)
106 : {
107 942 : m_layoutBreakType = val;
108 942 : }
109 :
110 : //---------------------------------------------------------
111 : // acceptDrop
112 : //---------------------------------------------------------
113 :
114 0 : bool LayoutBreak::acceptDrop(EditData& data) const
115 : {
116 0 : return data.dropElement->isLayoutBreak()
117 0 : && toLayoutBreak(data.dropElement)->layoutBreakType() != layoutBreakType();
118 : }
119 :
120 : //---------------------------------------------------------
121 : // drop
122 : //---------------------------------------------------------
123 :
124 0 : EngravingItem* LayoutBreak::drop(Transaction&, EditData& data)
125 : {
126 0 : EngravingItem* e = data.dropElement;
127 0 : score()->undoChangeElement(this, e);
128 0 : return e;
129 : }
130 :
131 : //---------------------------------------------------------
132 : // getProperty
133 : //---------------------------------------------------------
134 :
135 7446 : PropertyValue LayoutBreak::getProperty(Pid propertyId) const
136 : {
137 7446 : switch (propertyId) {
138 531 : case Pid::LAYOUT_BREAK:
139 531 : return m_layoutBreakType;
140 0 : case Pid::PAUSE:
141 0 : return m_pause;
142 531 : case Pid::START_WITH_LONG_NAMES:
143 531 : return m_startWithLongNames;
144 531 : case Pid::START_WITH_MEASURE_ONE:
145 531 : return m_startWithMeasureOne;
146 531 : case Pid::FIRST_SYSTEM_INDENTATION:
147 531 : return m_firstSystemIndentation;
148 531 : case Pid::SHOW_COURTESY:
149 531 : return m_showCourtesy;
150 4791 : default:
151 4791 : return EngravingItem::getProperty(propertyId);
152 : }
153 : }
154 :
155 : //---------------------------------------------------------
156 : // setProperty
157 : //---------------------------------------------------------
158 :
159 6427 : bool LayoutBreak::setProperty(Pid propertyId, const PropertyValue& v)
160 : {
161 6427 : switch (propertyId) {
162 714 : case Pid::LAYOUT_BREAK:
163 714 : setLayoutBreakType(v.value<LayoutBreakType>());
164 714 : break;
165 1945 : case Pid::PAUSE:
166 1945 : setPause(v.toDouble());
167 1945 : break;
168 942 : case Pid::START_WITH_LONG_NAMES:
169 942 : setStartWithLongNames(v.toBool());
170 942 : break;
171 942 : case Pid::START_WITH_MEASURE_ONE:
172 942 : setStartWithMeasureOne(v.toBool());
173 942 : break;
174 942 : case Pid::FIRST_SYSTEM_INDENTATION:
175 942 : setFirstSystemIndentation(v.toBool());
176 942 : break;
177 942 : case Pid::SHOW_COURTESY:
178 942 : setShowCourtesy(v.toBool());
179 942 : break;
180 0 : default:
181 0 : if (!EngravingItem::setProperty(propertyId, v)) {
182 0 : return false;
183 : }
184 0 : break;
185 : }
186 :
187 6427 : if (propertyId == Pid::START_WITH_MEASURE_ONE) {
188 942 : triggerLayoutToEnd();
189 : } else {
190 5485 : triggerLayout();
191 5485 : if (ownershipParent() && measure()->next()) {
192 773 : measure()->next()->triggerLayout();
193 : }
194 : }
195 :
196 6427 : setGenerated(false);
197 6427 : return true;
198 : }
199 :
200 : //---------------------------------------------------------
201 : // propertyDefault
202 : //---------------------------------------------------------
203 :
204 12156 : PropertyValue LayoutBreak::propertyDefault(Pid id) const
205 : {
206 12156 : switch (id) {
207 531 : case Pid::LAYOUT_BREAK:
208 531 : return PropertyValue(); // LAYOUT_BREAK_LINE;
209 942 : case Pid::PAUSE:
210 942 : return style().styleD(Sid::sectionPause);
211 1473 : case Pid::START_WITH_LONG_NAMES:
212 1473 : return true;
213 1473 : case Pid::START_WITH_MEASURE_ONE:
214 1473 : return true;
215 1473 : case Pid::FIRST_SYSTEM_INDENTATION:
216 1473 : return true;
217 1473 : case Pid::SHOW_COURTESY:
218 1473 : return false;
219 4791 : default:
220 4791 : return EngravingItem::propertyDefault(id);
221 : }
222 : }
223 :
224 : //---------------------------------------------------------
225 : // subtypeUserName
226 : //---------------------------------------------------------
227 :
228 0 : muse::TranslatableString LayoutBreak::subtypeUserName() const
229 : {
230 0 : return TConv::userName(layoutBreakType());
231 : }
232 :
233 : //---------------------------------------------------------
234 : // accessibleInfo
235 : //---------------------------------------------------------
236 :
237 0 : String LayoutBreak::accessibleInfo() const
238 : {
239 0 : return translatedSubtypeUserName();
240 : }
241 :
242 0 : Font LayoutBreak::font() const
243 : {
244 0 : Font font(configuration()->iconsFontFamily(), Font::Type::Icon);
245 0 : font.setPointSizeF(UI_ICONS_DEFAULT_FONT_SIZE * magS());
246 0 : return font;
247 0 : }
248 : }
|