Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-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 : #include "navigationpanel.h"
23 :
24 : #include "accessibility/iaccessible.h"
25 : #include "navigationsection.h"
26 : #include "translation.h"
27 : #include "log.h"
28 :
29 : using namespace muse;
30 : using namespace muse::ui;
31 : using namespace muse::accessibility;
32 :
33 0 : NavigationPanel::NavigationPanel(QObject* parent)
34 0 : : AbstractNavigation(parent)
35 : {
36 0 : }
37 :
38 124 : NavigationPanel::NavigationPanel(const muse::modularity::ContextPtr& iocCtx, QObject* parent)
39 124 : : AbstractNavigation(iocCtx, parent)
40 : {
41 124 : }
42 :
43 248 : NavigationPanel::~NavigationPanel()
44 : {
45 124 : if (m_section) {
46 0 : m_section->removePanel(this);
47 : }
48 248 : }
49 :
50 0 : void NavigationPanel::componentComplete()
51 : {
52 0 : accessible()->setRole(MUAccessible::Panel);
53 :
54 0 : AbstractNavigation::componentComplete();
55 0 : }
56 :
57 0 : QString NavigationPanel::name() const
58 : {
59 0 : return AbstractNavigation::name();
60 : }
61 :
62 204 : const INavigation::Index& NavigationPanel::index() const
63 : {
64 204 : return AbstractNavigation::index();
65 : }
66 :
67 0 : void NavigationPanel::setIndex(const Index& index)
68 : {
69 0 : AbstractNavigation::setIndex(index);
70 0 : }
71 :
72 0 : async::Channel<INavigation::Index> NavigationPanel::indexChanged() const
73 : {
74 0 : return AbstractNavigation::indexChanged();
75 : }
76 :
77 196 : bool NavigationPanel::enabled() const
78 : {
79 196 : if (!AbstractNavigation::enabled()) {
80 0 : return false;
81 : }
82 :
83 196 : bool enbl = false;
84 196 : for (INavigationControl* c : m_controls) {
85 196 : if (c->enabled()) {
86 196 : enbl = true;
87 196 : break;
88 : }
89 : }
90 196 : return enbl;
91 : }
92 :
93 0 : async::Channel<bool> NavigationPanel::enabledChanged() const
94 : {
95 0 : return AbstractNavigation::enabledChanged();
96 : }
97 :
98 241 : bool NavigationPanel::active() const
99 : {
100 241 : return AbstractNavigation::active();
101 : }
102 :
103 210 : void NavigationPanel::setActive(bool arg)
104 : {
105 210 : AbstractNavigation::setActive(arg);
106 210 : if (m_accessible) {
107 210 : m_accessible->setState(IAccessible::State::Active, arg);
108 : }
109 210 : }
110 :
111 0 : async::Channel<bool> NavigationPanel::activeChanged() const
112 : {
113 0 : return AbstractNavigation::activeChanged();
114 : }
115 :
116 37 : void NavigationPanel::onEvent(EventPtr e)
117 : {
118 37 : AbstractNavigation::onEvent(e);
119 37 : }
120 :
121 0 : QWindow* NavigationPanel::window() const
122 : {
123 0 : return AbstractNavigation::window();
124 : }
125 :
126 0 : QQuickItem* muse::ui::NavigationPanel::visualItem() const
127 : {
128 0 : return AbstractNavigation::visualItem();
129 : }
130 :
131 4 : void NavigationPanel::setDirection(QmlDirection direction)
132 : {
133 4 : if (m_direction == direction) {
134 2 : return;
135 : }
136 :
137 2 : m_direction = direction;
138 2 : emit directionChanged();
139 : }
140 :
141 0 : NavigationPanel::QmlDirection NavigationPanel::direction_property() const
142 : {
143 0 : return m_direction;
144 : }
145 :
146 0 : QString NavigationPanel::directionInfo() const
147 : {
148 0 : switch (m_direction) {
149 0 : case Horizontal: return muse::qtrc("ui", "direction is horizontal");
150 0 : case Vertical: return muse::qtrc("ui", "direction is vertical");
151 0 : case Both: return muse::qtrc("ui", "direction is both");
152 : }
153 0 : return QString();
154 : }
155 :
156 11 : INavigationPanel::Direction NavigationPanel::direction() const
157 : {
158 11 : return static_cast<Direction>(m_direction);
159 : }
160 :
161 259 : const std::set<INavigationControl*>& NavigationPanel::controls() const
162 : {
163 259 : return m_controls;
164 : }
165 :
166 0 : async::Notification NavigationPanel::controlsListChanged() const
167 : {
168 0 : return m_controlsListChanged;
169 : }
170 :
171 2 : INavigationSection* NavigationPanel::section() const
172 : {
173 2 : return m_section;
174 : }
175 :
176 0 : NavigationSection* NavigationPanel::section_property() const
177 : {
178 0 : return m_section;
179 : }
180 :
181 128 : void NavigationPanel::setSection(INavigationSection* section)
182 : {
183 128 : setSection_property(dynamic_cast<NavigationSection*>(section));
184 128 : }
185 :
186 128 : void NavigationPanel::setSection_property(NavigationSection* section)
187 : {
188 129 : TRACEFUNC;
189 128 : if (m_section == section) {
190 0 : return;
191 : }
192 :
193 128 : if (m_section) {
194 4 : m_section->removePanel(this);
195 4 : m_section->disconnect(this);
196 : }
197 :
198 128 : m_section = section;
199 :
200 128 : if (m_section) {
201 124 : m_section->addPanel(this);
202 124 : connect(m_section, &NavigationSection::destroyed, this, &NavigationPanel::onSectionDestroyed);
203 : }
204 :
205 128 : emit sectionChanged(m_section);
206 128 : }
207 :
208 120 : void NavigationPanel::onSectionDestroyed()
209 : {
210 120 : m_section = nullptr;
211 120 : }
212 :
213 372 : void NavigationPanel::addControl(NavigationControl* control)
214 : {
215 373 : TRACEFUNC;
216 372 : IF_ASSERT_FAILED(control) {
217 0 : return;
218 : }
219 :
220 372 : m_controls.insert(control);
221 :
222 372 : if (m_controlsListChanged.isConnected()) {
223 0 : m_controlsListChanged.notify();
224 : }
225 372 : }
226 :
227 1 : void NavigationPanel::removeControl(NavigationControl* control)
228 : {
229 2 : TRACEFUNC;
230 1 : IF_ASSERT_FAILED(control) {
231 0 : return;
232 : }
233 :
234 1 : m_controls.erase(control);
235 :
236 1 : if (m_controlsListChanged.isConnected()) {
237 0 : m_controlsListChanged.notify();
238 : }
239 1 : }
240 :
241 14 : void NavigationPanel::requestActive(INavigationControl* control, bool enableHighlight,
242 : INavigation::ActivationType activationType)
243 : {
244 14 : if (m_section) {
245 14 : m_section->requestActive(this, control, enableHighlight, activationType);
246 : }
247 14 : }
|