Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qaccessiblequickview.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtGui/qguiapplication.h>
8
9#include <QtQuick/qquickitem.h>
10#include <QtQuick/private/qquickitem_p.h>
11
13
14#if QT_CONFIG(accessibility)
15
16QT_BEGIN_NAMESPACE
17
18QAccessibleQuickWindow::QAccessibleQuickWindow(QQuickWindow *object)
19 :QAccessibleObject(object)
20{
21}
22
23QList<QQuickItem *> QAccessibleQuickWindow::rootItems() const
24{
25 if (QQuickItem *ci = window() ? window()->contentItem() : nullptr)
26 return accessibleUnignoredChildren(ci);
27 return QList<QQuickItem *>();
28}
29
30int QAccessibleQuickWindow::childCount() const
31{
32 return rootItems().size();
33}
34
35QAccessibleInterface *QAccessibleQuickWindow::parent() const
36{
37 // FIXME: for now we assume to be a top level window...
38 return QAccessible::queryAccessibleInterface(qApp);
39}
40
41QAccessibleInterface *QAccessibleQuickWindow::child(int index) const
42{
43 const QList<QQuickItem*> &kids = rootItems();
44 if (index >= 0 && index < kids.size())
45 return QAccessible::queryAccessibleInterface(kids.at(index));
46 return nullptr;
47}
48
49QAccessibleInterface *QAccessibleQuickWindow::focusChild() const
50{
51 QObject *focusObject = window() ? window()->focusObject() : nullptr;
52 if (focusObject) {
53 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(focusObject);
54 if (!iface || iface == this || !iface->focusChild())
55 return iface;
56 return iface->focusChild();
57 }
58 return nullptr;
59}
60
61QAccessible::Role QAccessibleQuickWindow::role() const
62{
63 return QAccessible::Window;
64}
65
66QAccessible::State QAccessibleQuickWindow::state() const
67{
68 QAccessible::State st;
69 if (window() == QGuiApplication::focusWindow())
70 st.active = true;
71 if (!window() || !window()->isVisible())
72 st.invisible = true;
73 return st;
74}
75
76QRect QAccessibleQuickWindow::rect() const
77{
78 if (!window())
79 return {};
80 return QRect(window()->x(), window()->y(), window()->width(), window()->height());
81}
82
83QString QAccessibleQuickWindow::text(QAccessible::Text text) const
84{
85 if (!window())
86 return {};
87#ifdef Q_ACCESSIBLE_QUICK_ITEM_ENABLE_DEBUG_DESCRIPTION
88 if (text == QAccessible::DebugDescription) {
89 return QString::fromLatin1(object()->metaObject()->className()) ;
90 }
91#endif
92 if (text == QAccessible::Name)
93 return window()->title();
94 else
95 return {};
96}
97
98QAccessibleInterface *QAccessibleQuickWindow::childAt(int x, int y) const
99{
100 Q_ASSERT(window());
101
102 if (!window()->contentItem())
103 return nullptr;
104
105 const QList<QQuickItem *> kids = accessibleUnignoredChildren(window()->contentItem(), true);
106 for (int i = kids.size() - 1; i >= 0; --i) {
107 QAccessibleInterface *childIface = QAccessible::queryAccessibleInterface(kids.at(i));
108 if (childIface && !childIface->state().invisible) {
109 if (QAccessibleInterface *iface = childIface->childAt(x, y))
110 return iface;
111 if (childIface->rect().contains(x, y))
112 return childIface;
113 }
114 }
115 return nullptr;
116}
117
118int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const
119{
120 int i = -1;
121 if (iface) {
122 const QList<QQuickItem *> &roots = rootItems();
123 i = roots.size() - 1;
124 while (i >= 0) {
125 if (iface->object() == roots.at(i))
126 break;
127 --i;
128 }
129 }
130 return i;
131}
132
133QT_END_NAMESPACE
134
135#endif // accessibility