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 "sticking.h"
24 :
25 : #include "segment.h"
26 :
27 : #include "log.h"
28 :
29 : using namespace mu;
30 :
31 : namespace mu::engraving {
32 : //---------------------------------------------------------
33 : // stickingStyle
34 : //---------------------------------------------------------
35 :
36 : static const ElementStyle stickingStyle {
37 : { Sid::stickingPlacement, Pid::PLACEMENT },
38 : { Sid::stickingMinDistance, Pid::MIN_DISTANCE },
39 : };
40 :
41 : //---------------------------------------------------------
42 : // Sticking
43 : //---------------------------------------------------------
44 :
45 59 : Sticking::Sticking(DummyParentOr<Segment> parent)
46 59 : : TextBase(ElementType::STICKING, parent, TextStyleType::STICKING, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
47 : {
48 59 : initElementStyle(&stickingStyle);
49 59 : }
50 :
51 0 : bool Sticking::isEditAllowed(EditData& ed) const
52 : {
53 0 : if (isTextNavigationKey(ed.key, ed.modifiers)) {
54 0 : return false;
55 : }
56 :
57 0 : if (ed.key == Key_Left) {
58 0 : return cursor()->column() != 0 || cursor()->hasSelection();
59 : }
60 :
61 0 : if (ed.key == Key_Right) {
62 0 : bool cursorInLastColumn = cursor()->column() == cursor()->curLine().columns();
63 0 : return !cursorInLastColumn || cursor()->hasSelection();
64 : }
65 :
66 0 : return TextBase::isEditAllowed(ed);
67 : }
68 :
69 : //---------------------------------------------------------
70 : // propertyDefault
71 : //---------------------------------------------------------
72 :
73 701 : engraving::PropertyValue Sticking::propertyDefault(Pid id) const
74 : {
75 701 : switch (id) {
76 73 : case Pid::TEXT_STYLE:
77 73 : return TextStyleType::STICKING;
78 628 : default:
79 628 : return TextBase::propertyDefault(id);
80 : }
81 : }
82 : }
|