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
qaccessiblequicklistview.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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 <QtQuick/private/qquicklistview_p.h>
8
9QT_BEGIN_NAMESPACE
10
11#if QT_CONFIG(accessibility)
12
13QAccessibleQuickListView::QAccessibleQuickListView(QQuickListView *listView)
14 : QAccessibleQuickItem(listView)
15{
16}
17
18QSizeF QAccessibleQuickListView::contentSize() const
19{
20 if (auto *l = listView()) {
21 const int count = l->count();
22 if (count == 0)
23 return { 0, 0 };
24
25 if (l->orientation() == QQuickListView::Horizontal)
26 return { static_cast<qreal>(count), 1 };
27
28 return { 1, static_cast<qreal>(count) };
29 }
30
31 return { };
32}
33
34QPointF QAccessibleQuickListView::position() const
35{
36 if (auto *l = listView()) {
37 const int count = l->count();
38 if (count == 0)
39 return { 0, 0 };
40
41 if (l->orientation() == QQuickListView::Horizontal) {
42 // compensate for undershooting of underlying Flickable
43 const int startIndex = std::max(0, l->indexAt(l->contentX(), 0));
44 return { static_cast<qreal>(startIndex) / count, 0 };
45 }
46
47 // compensate for undershooting of underlying Flickable
48 const int startIndex = std::max(0, l->indexAt(0, l->contentY()));
49 return { 0, static_cast<qreal>(startIndex) / count };
50 }
51
52 return { };
53}
54
55QSizeF QAccessibleQuickListView::viewportSize() const
56{
57 if (auto *l = listView()) {
58 const int count = l->count();
59 if (count == 0)
60 return { 1, 1 };
61
62 if (l->orientation() == QQuickListView::Horizontal) {
63 const int startIndex = std::max(0, l->indexAt(l->contentX(), 0));
64 int endIndex = l->indexAt(l->contentX() + l->width() - 1, 0);
65 // compensate for overshooting of underlying Flickable
66 if (endIndex == -1)
67 endIndex = count - 1;
68
69 return { static_cast<qreal>(endIndex - startIndex + 1) / count, 1 };
70 }
71 const int startIndex = std::max(0, l->indexAt(0, l->contentY()));
72 int endIndex = l->indexAt(0, l->contentY() + l->height() - 1);
73 // compensate for overshooting of underlying Flickable
74 if (endIndex == -1)
75 endIndex = count - 1;
76
77 return { 1, static_cast<qreal>(endIndex - startIndex + 1) / count };
78 }
79
80 return { };
81}
82
83bool QAccessibleQuickListView::isIndexed() const
84{
85 return true;
86}
87
88void QAccessibleQuickListView::setPosition(QPointF position)
89{
90 if (auto *l = listView()) {
91 if (l->orientation() == QQuickListView::Horizontal) {
92 l->positionViewAtIndex(static_cast<int>(position.x() * l->count()),
93 QQuickListView::Beginning);
94 return;
95 }
96
97 l->positionViewAtIndex(static_cast<int>(position.y() * l->count()),
98 QQuickListView::Beginning);
99 }
100}
101
102void *QAccessibleQuickListView::interface_cast(QAccessible::InterfaceType t)
103{
104 if (t == QAccessible::ViewportInterface)
105 return static_cast<QAccessibleViewportInterface *>(this);
106
107 return QAccessibleQuickItem::interface_cast(t);
108}
109
110QQuickListView *QAccessibleQuickListView::listView() const
111{
112 return qobject_cast<QQuickListView *>(object());
113}
114
115#endif // accessibility
116
117QT_END_NAMESPACE