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 "mmrestrange.h"
24 :
25 : #include "style/style.h"
26 :
27 : #include "measure.h"
28 :
29 : #include "log.h"
30 :
31 : using namespace mu;
32 : using namespace mu::engraving;
33 :
34 : namespace mu::engraving {
35 : //---------------------------------------------------------
36 : // mmRestRangeStyle
37 : //---------------------------------------------------------
38 :
39 : static const ElementStyle mmRestRangeStyle {
40 : { Sid::mmRestRangeBracketType, Pid::MMREST_RANGE_BRACKET_TYPE },
41 : { Sid::mmRestRangeVPlacement, Pid::PLACEMENT },
42 : { Sid::mmRestRangeMinDistance, Pid::MIN_DISTANCE },
43 : { Sid::mmRestRangeTextStyle, Pid::TEXT_STYLE }
44 : };
45 :
46 0 : MMRestRange::MMRestRange(DummyParentOr<Measure> parent)
47 0 : : MeasureNumberBase(ElementType::MMREST_RANGE, parent, TextStyleType::MMREST_RANGE)
48 : {
49 0 : initElementStyle(&mmRestRangeStyle);
50 0 : }
51 :
52 : //---------------------------------------------------------
53 : // MMRestRange
54 : /// Copy constructor
55 : //---------------------------------------------------------
56 :
57 0 : MMRestRange::MMRestRange(const MMRestRange& other)
58 0 : : MeasureNumberBase(other)
59 : {
60 0 : initElementStyle(&mmRestRangeStyle);
61 0 : }
62 :
63 0 : PropertyValue MMRestRange::getProperty(Pid id) const
64 : {
65 0 : switch (id) {
66 0 : case Pid::MMREST_RANGE_BRACKET_TYPE:
67 0 : return int(bracketType());
68 0 : default:
69 0 : return MeasureNumberBase::getProperty(id);
70 : }
71 : }
72 :
73 0 : bool MMRestRange::setProperty(Pid id, const PropertyValue& val)
74 : {
75 0 : switch (id) {
76 0 : case Pid::MMREST_RANGE_BRACKET_TYPE:
77 0 : setBracketType(MMRestRangeBracketType(val.toInt()));
78 0 : mutldata()->layoutInvalid = true;
79 0 : triggerLayout();
80 0 : return true;
81 0 : default:
82 0 : return MeasureNumberBase::setProperty(id, val);
83 : }
84 : }
85 :
86 : //---------------------------------------------------------
87 : // setXmlText
88 : /// This is reimplemented from TextBase::setXmlText to take care of the brackets
89 : //---------------------------------------------------------
90 :
91 0 : void MMRestRange::setXmlText(const String& s)
92 : {
93 0 : switch (bracketType()) {
94 0 : case MMRestRangeBracketType::BRACKETS:
95 0 : TextBase::setXmlText(u"[" + s + u"]");
96 0 : break;
97 0 : case MMRestRangeBracketType::PARENTHESES:
98 0 : TextBase::setXmlText(u"(" + s + u")");
99 0 : break;
100 0 : case MMRestRangeBracketType::NONE:
101 : default:
102 0 : TextBase::setXmlText(s);
103 0 : break;
104 : }
105 0 : }
106 : } // namespace MS
|