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 "playtechannotation.h"
24 :
25 : #include "segment.h"
26 :
27 : #include "types/typesconv.h"
28 :
29 : #include "log.h"
30 :
31 : using namespace mu;
32 : using namespace mu::engraving;
33 :
34 : static const ElementStyle annotationStyle {
35 : { Sid::staffTextPlacement, Pid::PLACEMENT },
36 : { Sid::staffTextMinDistance, Pid::MIN_DISTANCE },
37 : };
38 :
39 63 : PlayTechAnnotation::PlayTechAnnotation(DummyParentOr<Segment> parent, PlayingTechniqueType techniqueType, TextStyleType tid)
40 0 : : StaffTextBase(ElementType::PLAYTECH_ANNOTATION, parent, tid, ElementFlag::MOVABLE | ElementFlag::ON_STAFF),
41 63 : m_techniqueType(techniqueType)
42 : {
43 63 : initElementStyle(&annotationStyle);
44 63 : }
45 :
46 56 : PlayingTechniqueType PlayTechAnnotation::techniqueType() const
47 : {
48 56 : return m_techniqueType;
49 : }
50 :
51 35 : void PlayTechAnnotation::setTechniqueType(const PlayingTechniqueType techniqueType)
52 : {
53 35 : m_techniqueType = techniqueType;
54 35 : resetProperty(Pid::TEXT_STYLE);
55 35 : }
56 :
57 1 : PlayTechAnnotation* PlayTechAnnotation::clone() const
58 : {
59 1 : return new PlayTechAnnotation(*this);
60 : }
61 :
62 1 : TranslatableString PlayTechAnnotation::subtypeUserName() const
63 : {
64 1 : return TConv::userName(m_techniqueType);
65 : }
66 :
67 128 : bool PlayTechAnnotation::isHandbellsSymbol() const
68 : {
69 128 : return static_cast<int>(m_techniqueType) >= static_cast<int>(PlayingTechniqueType::HandbellsSwing)
70 128 : && static_cast<int>(m_techniqueType) <= static_cast<int>(PlayingTechniqueType::HandbellsR);
71 : }
72 :
73 143 : PropertyValue PlayTechAnnotation::getProperty(Pid id) const
74 : {
75 143 : switch (id) {
76 6 : case Pid::PLAY_TECH_TYPE:
77 6 : return m_techniqueType;
78 6 : case Pid::PLAY:
79 6 : return m_playPlayTechAnnotation;
80 131 : default:
81 131 : return StaffTextBase::getProperty(id);
82 : }
83 : }
84 :
85 1813 : bool PlayTechAnnotation::setProperty(Pid propertyId, const PropertyValue& val)
86 : {
87 1813 : switch (propertyId) {
88 35 : case Pid::PLAY_TECH_TYPE:
89 35 : setTechniqueType(PlayingTechniqueType(val.toInt()));
90 35 : break;
91 0 : case Pid::PLAY:
92 0 : setPlayPlayTechAnnotation(val.toBool());
93 0 : break;
94 1778 : default:
95 1778 : if (!StaffTextBase::setProperty(propertyId, val)) {
96 11 : return false;
97 : }
98 1767 : break;
99 : }
100 :
101 1802 : triggerLayout();
102 1802 : return true;
103 : }
104 :
105 140 : PropertyValue PlayTechAnnotation::propertyDefault(Pid id) const
106 : {
107 140 : switch (id) {
108 41 : case Pid::TEXT_STYLE:
109 41 : return isHandbellsSymbol() ? TextStyleType::ARTICULATION : TextStyleType::STAFF;
110 6 : case Pid::PLAY_TECH_TYPE:
111 6 : return PlayingTechniqueType::Natural;
112 6 : case Pid::PLAY:
113 6 : return true;
114 87 : default:
115 87 : return StaffTextBase::propertyDefault(id);
116 : }
117 : }
|