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) 2026 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 "modelwithstavecenteringoptions.h"
24 :
25 : using namespace mu::propertiespanel;
26 : using namespace mu::engraving;
27 :
28 0 : ModelWithStaveCenteringOptions::ModelWithStaveCenteringOptions(QObject* parent,
29 : const muse::modularity::ContextPtr& iocCtx,
30 : IElementRepositoryService* repository,
31 0 : ElementType elementType)
32 0 : : PropertiesPanelAbstractModel(parent, iocCtx, repository, elementType)
33 : {
34 0 : }
35 :
36 0 : void ModelWithStaveCenteringOptions::createProperties()
37 : {
38 0 : m_centerBetweenStaves = buildPropertyItem(Pid::CENTER_BETWEEN_STAVES);
39 0 : updateStaveCenteringFlags();
40 0 : }
41 :
42 0 : void ModelWithStaveCenteringOptions::loadProperties()
43 : {
44 0 : loadPropertyItem(m_centerBetweenStaves);
45 0 : updateStaveCenteringFlags();
46 0 : }
47 :
48 0 : void ModelWithStaveCenteringOptions::onNotationChanged(const PropertyIdSet&, const StyleIdSet&)
49 : {
50 0 : loadProperties();
51 0 : }
52 :
53 0 : bool ModelWithStaveCenteringOptions::centeringSideIsRelevant(const EngravingItem* item, bool above) const
54 : {
55 0 : return item->placeAbove() == above;
56 : }
57 :
58 0 : void ModelWithStaveCenteringOptions::updateStaveCenteringFlags()
59 : {
60 0 : bool isApplicable = true;
61 0 : bool isAvailable = true;
62 :
63 0 : for (EngravingItem* item : m_elementList) {
64 0 : const bool otherStaffAbove = item->staffToCenterAgainst(true) != nullptr;
65 0 : const bool otherStaffBelow = item->staffToCenterAgainst(false) != nullptr;
66 0 : if (!otherStaffAbove && !otherStaffBelow) {
67 0 : isApplicable = false;
68 0 : isAvailable = false;
69 0 : break;
70 : }
71 :
72 0 : const bool otherStaffOnRelevantSide = (otherStaffAbove && centeringSideIsRelevant(item, true))
73 0 : || (otherStaffBelow && centeringSideIsRelevant(item, false));
74 0 : if (!otherStaffOnRelevantSide) {
75 0 : isAvailable = false;
76 : }
77 : }
78 :
79 0 : setIsStaveCenteringApplicable(isApplicable);
80 0 : setIsStaveCenteringAvailable(isAvailable);
81 0 : }
82 :
83 0 : PropertyItem* ModelWithStaveCenteringOptions::centerBetweenStaves() const
84 : {
85 0 : return m_centerBetweenStaves;
86 : }
87 :
88 0 : bool ModelWithStaveCenteringOptions::isStaveCenteringApplicable() const
89 : {
90 0 : return m_isStaveCenteringApplicable;
91 : }
92 :
93 0 : bool ModelWithStaveCenteringOptions::isStaveCenteringAvailable() const
94 : {
95 0 : return m_isStaveCenteringAvailable;
96 : }
97 :
98 0 : void ModelWithStaveCenteringOptions::setIsStaveCenteringApplicable(bool v)
99 : {
100 0 : if (v == m_isStaveCenteringApplicable) {
101 0 : return;
102 : }
103 :
104 0 : m_isStaveCenteringApplicable = v;
105 0 : emit isStaveCenteringApplicableChanged(m_isStaveCenteringApplicable);
106 : }
107 :
108 0 : void ModelWithStaveCenteringOptions::setIsStaveCenteringAvailable(bool v)
109 : {
110 0 : if (v == m_isStaveCenteringAvailable) {
111 0 : return;
112 : }
113 :
114 0 : m_isStaveCenteringAvailable = v;
115 0 : emit isStaveCenteringAvailableChanged(m_isStaveCenteringAvailable);
116 : }
|