Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickaccessibleattached_p.h
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
4#ifndef QQUICKACCESSIBLEATTACHED_H
5#define QQUICKACCESSIBLEATTACHED_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/qquickitem.h>
19
20#include <QtCore/qobject.h>
21#include <QtCore/qstring.h>
22
23#if QT_CONFIG(accessibility)
24
25#include <QtGui/qaccessible.h>
26#include <private/qtquickglobal_p.h>
27
29
30
31#define STATE_PROPERTY(P) \
32 Q_PROPERTY(bool P READ P WRITE set_ ## P NOTIFY P ## Changed FINAL) \
33 bool P() const { return m_state.P ; } \
34 void set_ ## P(bool arg) \
35 { \
36 m_stateExplicitlySet.P = true; \
37 if (m_state.P == arg) \
38 return; \
39 m_state.P = arg; \
40 Q_EMIT P ## Changed(arg); \
41 QAccessible::State changedState; \
42 changedState.P = true; \
43 QAccessibleStateChangeEvent ev(parent(), changedState); \
44 QAccessible::updateAccessibility(&ev); \
45 } \
46 Q_SIGNAL void P ## Changed(bool arg);
47
48class Q_QUICK_EXPORT QQuickAccessibleAttached : public QObject
49{
51 Q_PROPERTY(QAccessible::Role role READ role WRITE setRole NOTIFY roleChanged FINAL)
52 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
53 Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged FINAL)
54 Q_PROPERTY(bool ignored READ ignored WRITE setIgnored NOTIFY ignoredChanged FINAL)
55
56 QML_NAMED_ELEMENT(Accessible)
58 QML_UNCREATABLE("Accessible is only available via attached properties.")
59 QML_ATTACHED(QQuickAccessibleAttached)
61
62public:
63 STATE_PROPERTY(checkable)
64 STATE_PROPERTY(checked)
65 STATE_PROPERTY(editable)
66 STATE_PROPERTY(focusable)
67 STATE_PROPERTY(focused)
68 STATE_PROPERTY(multiLine)
69 STATE_PROPERTY(readOnly)
70 STATE_PROPERTY(selected)
71 STATE_PROPERTY(selectable)
72 STATE_PROPERTY(pressed)
73 STATE_PROPERTY(checkStateMixed)
74 STATE_PROPERTY(defaultButton)
75 STATE_PROPERTY(passwordEdit)
76 STATE_PROPERTY(selectableText)
77 STATE_PROPERTY(searchEdit)
78
79 QQuickAccessibleAttached(QObject *parent);
80 ~QQuickAccessibleAttached();
81
82 QAccessible::Role role() const { return m_role; }
83 void setRole(QAccessible::Role role);
84 QString name() const {
85 if (m_state.passwordEdit)
86 return QString();
87 return m_name;
88 }
89
90 bool wasNameExplicitlySet() const;
91 void setName(const QString &name) {
92 m_nameExplicitlySet = true;
93 if (name != m_name) {
94 m_name = name;
95 Q_EMIT nameChanged();
96 QAccessibleEvent ev(parent(), QAccessible::NameChanged);
97 QAccessible::updateAccessibility(&ev);
98 }
99 }
100 void setNameImplicitly(const QString &name);
101
102 QString description() const { return m_description; }
103 void setDescription(const QString &description)
104 {
105 if (m_description != description) {
106 m_description = description;
107 Q_EMIT descriptionChanged();
108 QAccessibleEvent ev(parent(), QAccessible::DescriptionChanged);
109 QAccessible::updateAccessibility(&ev);
110 }
111 }
112
113 // Factory function
114 static QQuickAccessibleAttached *qmlAttachedProperties(QObject *obj);
115
116 static QQuickAccessibleAttached *attachedProperties(const QObject *obj)
117 {
118 return qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(obj, false));
119 }
120
121 // Property getter
122 static QVariant property(const QObject *object, const char *propertyName)
123 {
124 if (QObject *attachedObject = QQuickAccessibleAttached::attachedProperties(object))
125 return attachedObject->property(propertyName);
126 return QVariant();
127 }
128
129 static bool setProperty(QObject *object, const char *propertyName, const QVariant &value)
130 {
131 QObject *obj = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(object, true);
132 if (!obj) {
133 qWarning("cannot set property Accessible.%s of QObject %s", propertyName, object->metaObject()->className());
134 return false;
135 }
136 return obj->setProperty(propertyName, value);
137 }
138
139 static QObject *findAccessible(QObject *object, QAccessible::Role role = QAccessible::NoRole)
140 {
141 while (object) {
142 QQuickAccessibleAttached *att = QQuickAccessibleAttached::attachedProperties(object);
143 if (att && (role == QAccessible::NoRole || att->role() == role)) {
144 break;
145 }
146 object = object->parent();
147 }
148 return object;
149 }
150
151 QAccessible::State state() const { return m_state; }
152 bool ignored() const;
153 bool doAction(const QString &actionName);
154 void availableActions(QStringList *actions) const;
155
156 Q_REVISION(6, 2) Q_INVOKABLE static QString stripHtml(const QString &html);
157
158public Q_SLOTS:
159 void valueChanged() {
160 QAccessibleValueChangeEvent ev(parent(), parent()->property("value"));
161 QAccessible::updateAccessibility(&ev);
162 }
163 void cursorPositionChanged() {
164 QAccessibleTextCursorEvent ev(parent(), parent()->property("cursorPosition").toInt());
165 QAccessible::updateAccessibility(&ev);
166 }
167
168 void setIgnored(bool ignored);
169
171 void roleChanged();
172 void nameChanged();
173 void descriptionChanged();
174 void ignoredChanged();
175 void pressAction();
176 void toggleAction();
177 void increaseAction();
178 void decreaseAction();
179 void scrollUpAction();
180 void scrollDownAction();
181 void scrollLeftAction();
182 void scrollRightAction();
183 void previousPageAction();
184 void nextPageAction();
185
186private:
187 QQuickItem *item() const { return qobject_cast<QQuickItem*>(parent()); }
188
189 QAccessible::Role m_role;
190 QAccessible::State m_state;
191 QAccessible::State m_stateExplicitlySet;
192 QString m_name;
193 bool m_nameExplicitlySet = false;
194 QString m_description;
195
196 static QMetaMethod sigPress;
197 static QMetaMethod sigToggle;
198 static QMetaMethod sigIncrease;
199 static QMetaMethod sigDecrease;
200 static QMetaMethod sigScrollUp;
201 static QMetaMethod sigScrollDown;
202 static QMetaMethod sigScrollLeft;
203 static QMetaMethod sigScrollRight;
204 static QMetaMethod sigPreviousPage;
205 static QMetaMethod sigNextPage;
206
207public:
208 using QObject::property;
209};
210
211
213
214#endif // accessibility
215
216#endif
\inmodule QtGui
The QAccessible class provides enums and static functions related to accessibility.
\inmodule QtCore
Definition qmetaobject.h:19
\inmodule QtCore
Definition qobject.h:103
QVariant property(const char *name) const
Returns the value of the object's name property.
Definition qobject.cpp:4323
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
employee setName("Richard Schmit")
else opt state
[0]
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
GLuint object
[3]
GLuint name
GLhandleARB obj
[2]
#define QML_UNCREATABLE(REASON)
#define QML_NAMED_ELEMENT(NAME)
#define QML_EXTENDED_NAMESPACE(EXTENDED_NAMESPACE)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QML_ATTACHED(ATTACHED_TYPE)
static QQuickAttachedPropertyPropagator * attachedObject(const QMetaObject *type, QObject *object, bool create=false)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_EMIT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
static int toInt(const QChar &qc, int R)
const char property[13]
Definition qwizard.cpp:101
QGraphicsItem * item
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)