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 for (int i = childCount() - 1; i >= 0; --i) {
102 QAccessibleInterface *childIface = child(i);
103 if (childIface && !childIface->state().invisible) {
104 if (QAccessibleInterface *iface = childIface->childAt(x, y))
105 return iface;
106 if (childIface->rect().contains(x, y))
107 return childIface;
108 }
109 }
110 return nullptr;
111}
112
113int QAccessibleQuickWindow::indexOfChild(const QAccessibleInterface *iface) const
114{
115 int i = -1;
116 if (iface) {
117 const QList<QQuickItem *> &roots = rootItems();
118 i = roots.size() - 1;
119 while (i >= 0) {
120 if (iface->object() == roots.at(i))
121 break;
122 --i;
123 }
124 }
125 return i;
126}
127
128QT_END_NAMESPACE
129
130#endif // accessibility