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
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 "accessibleapprootinterface.h"
23 :
24 : #include <QAccessible>
25 : #include <QGuiApplication>
26 :
27 : #include "accessibleapprootobject.h"
28 :
29 : using namespace muse::accessibility;
30 :
31 0 : AccessibleAppRootInterface::AccessibleAppRootInterface(AccessibleAppRootObject* root)
32 0 : : m_root(root)
33 : {
34 0 : }
35 :
36 0 : bool AccessibleAppRootInterface::isValid() const
37 : {
38 0 : return m_root != nullptr;
39 : }
40 :
41 0 : QObject* AccessibleAppRootInterface::object() const
42 : {
43 0 : return m_root;
44 : }
45 :
46 0 : QWindow* AccessibleAppRootInterface::window() const
47 : {
48 0 : return nullptr;
49 : }
50 :
51 0 : QRect AccessibleAppRootInterface::rect() const
52 : {
53 0 : return {};
54 : }
55 :
56 0 : QAccessibleInterface* AccessibleAppRootInterface::parent() const
57 : {
58 0 : return nullptr;
59 : }
60 :
61 0 : int AccessibleAppRootInterface::childCount() const
62 : {
63 0 : return m_root ? m_root->windowCount() : 0;
64 : }
65 :
66 0 : QAccessibleInterface* AccessibleAppRootInterface::child(int index) const
67 : {
68 0 : if (!m_root) {
69 0 : return nullptr;
70 : }
71 :
72 0 : return m_root->windowIface(index);
73 : }
74 :
75 0 : int AccessibleAppRootInterface::indexOfChild(const QAccessibleInterface* iface) const
76 : {
77 0 : if (!m_root || !iface) {
78 0 : return -1;
79 : }
80 :
81 0 : QWindow* childWindow = iface->window();
82 0 : for (int i = 0; i < m_root->windowCount(); ++i) {
83 0 : if (m_root->windowAt(i) == childWindow) {
84 0 : return i;
85 : }
86 : }
87 :
88 0 : return -1;
89 : }
90 :
91 0 : QAccessibleInterface* AccessibleAppRootInterface::focusChild() const
92 : {
93 0 : if (!m_root) {
94 0 : return nullptr;
95 : }
96 :
97 0 : QWindow* w = qApp->focusWindow();
98 0 : while (w) {
99 0 : for (int i = 0; i < m_root->windowCount(); ++i) {
100 0 : if (m_root->windowAt(i) == w) {
101 0 : QAccessibleInterface* windowIface = child(i);
102 0 : if (windowIface) {
103 0 : QAccessibleInterface* focusedChild = windowIface->focusChild();
104 0 : return focusedChild ? focusedChild : windowIface;
105 : }
106 0 : return nullptr;
107 : }
108 : }
109 0 : w = w->transientParent();
110 : }
111 :
112 0 : return nullptr;
113 : }
114 :
115 0 : QAccessibleInterface* AccessibleAppRootInterface::childAt(int, int) const
116 : {
117 0 : return nullptr;
118 : }
119 :
120 0 : QAccessible::State AccessibleAppRootInterface::state() const
121 : {
122 0 : QAccessible::State st;
123 0 : st.active = true;
124 0 : return st;
125 : }
126 :
127 0 : QAccessible::Role AccessibleAppRootInterface::role() const
128 : {
129 0 : return QAccessible::Application;
130 : }
131 :
132 0 : QString AccessibleAppRootInterface::text(QAccessible::Text t) const
133 : {
134 0 : if (t == QAccessible::Name) {
135 0 : return QGuiApplication::applicationName();
136 : }
137 0 : return {};
138 : }
139 :
140 0 : void AccessibleAppRootInterface::setText(QAccessible::Text, const QString&)
141 : {
142 0 : }
143 :
144 0 : void* AccessibleAppRootInterface::interface_cast(QAccessible::InterfaceType)
145 : {
146 0 : return nullptr;
147 : }
|