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
qaccessiblequickflickable.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/qquickflickable_p.h>
8
9QT_BEGIN_NAMESPACE
10
11#if QT_CONFIG(accessibility)
12
13QAccessibleQuickFlickable::QAccessibleQuickFlickable(QQuickFlickable *flickable)
14 : QAccessibleQuickItem(flickable)
15{
16}
17
18QSizeF QAccessibleQuickFlickable::contentSize() const
19{
20 if (auto *f = flickable())
21 return { f->contentWidth(), f->contentHeight() };
22
23 return { };
24}
25
26QPointF QAccessibleQuickFlickable::position() const
27{
28 if (auto *f = flickable()) {
29 const qreal contentWidth = f->contentWidth();
30 const qreal contentHeight = f->contentHeight();
31
32 if (contentWidth == 0 || contentHeight == 0)
33 return { 0, 0 };
34
35 // The QML Flickable uses the contentX property to realize the leftMargin
36 // so the normalized position needs to account for this. The same goes
37 // for the Y position.
38 const qreal effectiveXPosition = f->contentX() + f->leftMargin() + f->originX();
39 const qreal effectiveYPosition = f->contentY() + f->topMargin() + f->originY();
40 return { effectiveXPosition / contentWidth, effectiveYPosition / contentHeight };
41 }
42
43 return { };
44}
45
46QSizeF QAccessibleQuickFlickable::viewportSize() const
47{
48 if (auto *f = flickable()) {
49 const qreal contentWidth = f->contentWidth();
50 const qreal contentHeight = f->contentHeight();
51
52 if (contentWidth == 0 || contentHeight == 0)
53 return { 1, 1 };
54
55 const qreal effectiveWidth = f->width() - f->leftMargin() - f->rightMargin();
56 const qreal effectiveHeight = f->height() - f->topMargin() - f->bottomMargin();
57 return { std::min(1.0, effectiveWidth / contentWidth),
58 std::min(1.0, effectiveHeight / contentHeight) };
59 }
60
61 return { };
62}
63
64bool QAccessibleQuickFlickable::isIndexed() const
65{
66 return false;
67}
68
69void QAccessibleQuickFlickable::setPosition(const QPointF &position)
70{
71 if (auto *f = flickable()) {
72 const qreal contentWidth = f->contentWidth();
73 const qreal contentHeight = f->contentHeight();
74
75 if (contentWidth == 0 || contentHeight == 0) {
76 f->setContentX(0);
77 f->setContentY(0);
78 return;
79 }
80
81 f->setContentX(position.x() * contentWidth - f->leftMargin() - f->originX());
82 f->setContentY(position.y() * contentHeight - f->topMargin() - f->originY());
83 }
84}
85
86void *QAccessibleQuickFlickable::interface_cast(QAccessible::InterfaceType t)
87{
88 if (t == QAccessible::ViewportInterface)
89 return static_cast<QAccessibleViewportInterface *>(this);
90
91 return QAccessibleQuickItem::interface_cast(t);
92}
93
94QQuickFlickable *QAccessibleQuickFlickable::flickable() const
95{
96 return qobject_cast<QQuickFlickable *>(object());
97}
98
99#endif // accessibility
100
101QT_END_NAMESPACE