aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-10-20 12:41:55 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-10-21 15:33:51 +0000
commitbc546e14688c7056ac36b6f478fde852b5afaf46 (patch)
tree75cf4ed7146a362b11a9531d5314f03d738a3a96 /src/templates
parent8e1df766cf9e74661b50de4f4ed489af5b4edfc8 (diff)
QQuickControl: dynamically create a11y attached object
Using QAccessible::ActivationObserver approach. Change-Id: Ib99c1f9b7b0c37a3e8a4747db265c9df77acc1f8 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates')
-rw-r--r--src/templates/qquickabstractbutton.cpp18
-rw-r--r--src/templates/qquickabstractbutton_p.h4
-rw-r--r--src/templates/qquickbusyindicator.cpp7
-rw-r--r--src/templates/qquickcheckbox.cpp7
-rw-r--r--src/templates/qquickcontrol.cpp59
-rw-r--r--src/templates/qquickcontrol_p.h5
-rw-r--r--src/templates/qquickcontrol_p_p.h15
-rw-r--r--src/templates/qquickdial.cpp13
-rw-r--r--src/templates/qquickdial_p.h4
-rw-r--r--src/templates/qquicklabel.cpp53
-rw-r--r--src/templates/qquicklabel_p.h2
-rw-r--r--src/templates/qquicklabel_p_p.h16
-rw-r--r--src/templates/qquickpageindicator.cpp6
-rw-r--r--src/templates/qquickprogressbar.cpp6
-rw-r--r--src/templates/qquickrangeslider.cpp2
-rw-r--r--src/templates/qquickscrollbar.cpp17
-rw-r--r--src/templates/qquickscrollbar_p.h4
-rw-r--r--src/templates/qquickscrollindicator.cpp6
-rw-r--r--src/templates/qquickslider.cpp17
-rw-r--r--src/templates/qquickslider_p.h4
-rw-r--r--src/templates/qquickswitch.cpp1
-rw-r--r--src/templates/qquicktabbar.cpp6
-rw-r--r--src/templates/qquicktextarea.cpp59
-rw-r--r--src/templates/qquicktextarea_p.h2
-rw-r--r--src/templates/qquicktextarea_p_p.h16
-rw-r--r--src/templates/qquicktextfield.cpp65
-rw-r--r--src/templates/qquicktextfield_p.h2
-rw-r--r--src/templates/qquicktextfield_p_p.h19
28 files changed, 329 insertions, 106 deletions
diff --git a/src/templates/qquickabstractbutton.cpp b/src/templates/qquickabstractbutton.cpp
index ec3bff83..44e1189e 100644
--- a/src/templates/qquickabstractbutton.cpp
+++ b/src/templates/qquickabstractbutton.cpp
@@ -98,6 +98,7 @@ QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() :
pressed(false), checked(false), checkable(false), exclusive(false),
label(Q_NULLPTR), indicator(Q_NULLPTR)
{
+ m_accessibleRole = 0x0000002B; // QAccessible::Button
}
QQuickAbstractButton::QQuickAbstractButton(QQuickItem *parent) :
@@ -105,7 +106,6 @@ QQuickAbstractButton::QQuickAbstractButton(QQuickItem *parent) :
{
setActiveFocusOnTab(true);
setAcceptedMouseButtons(Qt::LeftButton);
- setAccessibleRole(0x0000002B); //QAccessible::Button
}
QQuickAbstractButton::QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent) :
@@ -113,7 +113,6 @@ QQuickAbstractButton::QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQui
{
setActiveFocusOnTab(true);
setAcceptedMouseButtons(Qt::LeftButton);
- setAccessibleRole(0x0000002B); //QAccessible::Button
}
/*!
@@ -383,4 +382,19 @@ void QQuickAbstractButton::nextCheckState()
setChecked(d->exclusive || !d->checked);
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickAbstractButton::accessibilityActiveChanged(bool active)
+{
+ QQuickControl::accessibilityActiveChanged(active);
+
+ Q_D(QQuickAbstractButton);
+ if (active) {
+ setAccessibleName(d->text);
+ setAccessibleProperty("pressed", d->pressed);
+ setAccessibleProperty("checked", d->checked);
+ setAccessibleProperty("checkable", d->checkable);
+ }
+}
+#endif
+
QT_END_NAMESPACE
diff --git a/src/templates/qquickabstractbutton_p.h b/src/templates/qquickabstractbutton_p.h
index 949117ae..b5a1b660 100644
--- a/src/templates/qquickabstractbutton_p.h
+++ b/src/templates/qquickabstractbutton_p.h
@@ -120,6 +120,10 @@ protected:
virtual void checkStateSet();
virtual void nextCheckState();
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+#endif
+
private:
Q_DISABLE_COPY(QQuickAbstractButton)
Q_DECLARE_PRIVATE(QQuickAbstractButton)
diff --git a/src/templates/qquickbusyindicator.cpp b/src/templates/qquickbusyindicator.cpp
index 76196ab8..3bfedf6b 100644
--- a/src/templates/qquickbusyindicator.cpp
+++ b/src/templates/qquickbusyindicator.cpp
@@ -66,7 +66,11 @@ QT_BEGIN_NAMESPACE
class QQuickBusyIndicatorPrivate : public QQuickControlPrivate
{
public:
- QQuickBusyIndicatorPrivate() : running(true), indicator(Q_NULLPTR) { }
+ QQuickBusyIndicatorPrivate()
+ : running(true), indicator(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x00000027; //QAccessible::Indicator
+ }
bool running;
QQuickItem *indicator;
@@ -75,7 +79,6 @@ public:
QQuickBusyIndicator::QQuickBusyIndicator(QQuickItem *parent) :
QQuickControl(*(new QQuickBusyIndicatorPrivate), parent)
{
- setAccessibleRole(0x00000027); //QAccessible::Indicator
}
/*!
diff --git a/src/templates/qquickcheckbox.cpp b/src/templates/qquickcheckbox.cpp
index fbcf2c33..8dd43241 100644
--- a/src/templates/qquickcheckbox.cpp
+++ b/src/templates/qquickcheckbox.cpp
@@ -86,7 +86,11 @@ class QQuickCheckBoxPrivate : public QQuickAbstractButtonPrivate
Q_DECLARE_PUBLIC(QQuickCheckBox)
public:
- QQuickCheckBoxPrivate() : tristate(false), checkState(Qt::Unchecked) { }
+ QQuickCheckBoxPrivate()
+ : tristate(false), checkState(Qt::Unchecked)
+ {
+ m_accessibleRole = 0x0000002C; // QAccessible::CheckBox
+ }
bool tristate;
Qt::CheckState checkState;
@@ -96,7 +100,6 @@ QQuickCheckBox::QQuickCheckBox(QQuickItem *parent) :
QQuickAbstractButton(*(new QQuickCheckBoxPrivate), parent)
{
setCheckable(true);
- setAccessibleRole(0x0000002C); //QAccessible::CheckBox
}
/*!
diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp
index 61a30b60..1a90c8fe 100644
--- a/src/templates/qquickcontrol.cpp
+++ b/src/templates/qquickcontrol.cpp
@@ -65,8 +65,18 @@ QQuickControlPrivate::QQuickControlPrivate() :
hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false),
padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0),
layoutDirection(Qt::LeftToRight), background(Q_NULLPTR), contentItem(Q_NULLPTR),
- accessibleAttached(Q_NULLPTR), accessibleRole(0) // QAccessible::NoRole
+ accessibleAttached(Q_NULLPTR), m_accessibleRole(0) // QAccessible::NoRole
{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::installActivationObserver(this);
+#endif
+}
+
+QQuickControlPrivate::~QQuickControlPrivate()
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::removeActivationObserver(this);
+#endif
}
void QQuickControlPrivate::mirrorChange()
@@ -156,6 +166,32 @@ void QQuickControlPrivate::resizeContent()
}
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickControlPrivate::accessibilityActiveChanged(bool active)
+{
+ Q_Q(QQuickControl);
+ return q->accessibilityActiveChanged(active);
+}
+
+QAccessible::Role QQuickControlPrivate::accessibleRole() const
+{
+ return (QAccessible::Role)m_accessibleRole;
+}
+
+void QQuickControl::accessibilityActiveChanged(bool active)
+{
+ Q_D(QQuickControl);
+ if (d->accessibleAttached || !active)
+ return;
+
+ d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true));
+ if (d->accessibleAttached)
+ d->accessibleAttached->setRole((QAccessible::Role)(d->m_accessibleRole));
+ else
+ qWarning() << "QQuickControl: " << this << " QQuickAccessibleAttached object creation failed!";
+}
+#endif
+
/*!
\internal
@@ -228,18 +264,14 @@ void QQuickControlPrivate::updateFontRecur(QQuickItem *item, const QFont &f)
int QQuickControl::accessibleRole() const
{
-#ifndef QT_NO_ACCESSIBILITY
Q_D(const QQuickControl);
- if (d->accessibleAttached)
- return d->accessibleAttached->role();
-#endif
- return 0; // QAccessible::NoRole
+ return d->m_accessibleRole;
}
void QQuickControl::setAccessibleRole(int role)
{
Q_D(QQuickControl);
- d->accessibleRole = role;
+ d->m_accessibleRole = role;
#ifndef QT_NO_ACCESSIBILITY
if (d->accessibleAttached)
d->accessibleAttached->setRole((QAccessible::Role)role);
@@ -678,19 +710,6 @@ void QQuickControl::setContentItem(QQuickItem *item)
}
}
-void QQuickControl::classBegin()
-{
- QQuickItem::classBegin();
-#ifndef QT_NO_ACCESSIBILITY
- Q_D(QQuickControl);
- d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true));
- if (d->accessibleAttached)
- d->accessibleAttached->setRole((QAccessible::Role)(d->accessibleRole));
- else
- qWarning() << "QQuickControl: QQuickAccessibleAttached object creation failed!";
-#endif
-}
-
void QQuickControl::mousePressEvent(QMouseEvent *event)
{
event->accept();
diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h
index daf1738e..675ec79e 100644
--- a/src/templates/qquickcontrol_p.h
+++ b/src/templates/qquickcontrol_p.h
@@ -149,8 +149,11 @@ protected:
virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding);
virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem);
- void classBegin() Q_DECL_OVERRIDE;
+#ifndef QT_NO_ACCESSIBILITY
+ virtual void accessibilityActiveChanged(bool active);
+#endif
+ // helper functions which avoid to check QT_NO_ACCESSIBILITY
int accessibleRole() const; // int for QAccessible::Role
void setAccessibleRole(int role); // int for QAccessible::Role
diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h
index 58f3e557..ceabc130 100644
--- a/src/templates/qquickcontrol_p_p.h
+++ b/src/templates/qquickcontrol_p_p.h
@@ -50,16 +50,24 @@
#include <QtQuick/private/qquickitem_p.h>
+#ifndef QT_NO_ACCESSIBILITY
+#include <QtGui/qaccessible.h>
+#endif
+
QT_BEGIN_NAMESPACE
class QQuickAccessibleAttached;
class Q_LABSTEMPLATES_EXPORT QQuickControlPrivate : public QQuickItemPrivate
+#ifndef QT_NO_ACCESSIBILITY
+ , public QAccessible::ActivationObserver
+#endif
{
Q_DECLARE_PUBLIC(QQuickControl)
public:
QQuickControlPrivate();
+ virtual ~QQuickControlPrivate();
static QQuickControlPrivate *get(QQuickControl *control)
{
@@ -76,6 +84,11 @@ public:
void resizeBackground();
void resizeContent();
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+ QAccessible::Role accessibleRole() const Q_DECL_OVERRIDE;
+#endif
+
void updateFont(const QFont &);
static void updateFontRecur(QQuickItem *item, const QFont &);
inline void setFont_helper(const QFont &f) {
@@ -101,7 +114,7 @@ public:
QQuickItem *background;
QQuickItem *contentItem;
QQuickAccessibleAttached *accessibleAttached;
- int accessibleRole;
+ int m_accessibleRole;
};
Q_DECLARE_TYPEINFO(QQuickControlPrivate, Q_COMPLEX_TYPE);
diff --git a/src/templates/qquickdial.cpp b/src/templates/qquickdial.cpp
index 4192d9de..65f653f9 100644
--- a/src/templates/qquickdial.cpp
+++ b/src/templates/qquickdial.cpp
@@ -92,6 +92,7 @@ public:
snapMode(QQuickDial::NoSnap),
handle(Q_NULLPTR)
{
+ m_accessibleRole = 0x00000031; // QAccessible::Dial
}
qreal valueAt(qreal position) const;
@@ -163,7 +164,6 @@ QQuickDial::QQuickDial(QQuickItem *parent) :
QQuickControl(*(new QQuickDialPrivate), parent)
{
setActiveFocusOnTab(true);
- setAccessibleRole(0x00000031); //QAccessible::Dial
setAcceptedMouseButtons(Qt::LeftButton);
}
@@ -524,4 +524,15 @@ void QQuickDial::componentComplete()
d->updatePosition();
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickDial::accessibilityActiveChanged(bool active)
+{
+ QQuickControl::accessibilityActiveChanged(active);
+
+ Q_D(QQuickDial);
+ if (active)
+ setAccessibleProperty("pressed", d->pressed);
+}
+#endif
+
QT_END_NAMESPACE
diff --git a/src/templates/qquickdial_p.h b/src/templates/qquickdial_p.h
index 6ed7a2b8..bffb602c 100644
--- a/src/templates/qquickdial_p.h
+++ b/src/templates/qquickdial_p.h
@@ -130,6 +130,10 @@ protected:
void mirrorChange() Q_DECL_OVERRIDE;
void componentComplete() Q_DECL_OVERRIDE;
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+#endif
+
private:
Q_DISABLE_COPY(QQuickDial)
Q_DECLARE_PRIVATE(QQuickDial)
diff --git a/src/templates/qquicklabel.cpp b/src/templates/qquicklabel.cpp
index efc7ee74..f344a022 100644
--- a/src/templates/qquicklabel.cpp
+++ b/src/templates/qquicklabel.cpp
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
QQuickLabel::QQuickLabel(QQuickItem *parent) :
QQuickText(*(new QQuickLabelPrivate), parent)
{
- Q_D(const QQuickLabel);
+ Q_D(QQuickLabel);
QObjectPrivate::connect(this, &QQuickText::textChanged,
d, &QQuickLabelPrivate::_q_textChanged);
}
@@ -80,6 +80,22 @@ QQuickLabel::~QQuickLabel()
{
}
+QQuickLabelPrivate::QQuickLabelPrivate()
+ : background(Q_NULLPTR), accessibleAttached(Q_NULLPTR)
+ , m_accessibleRole(0x00000029) // Accessible.StaticText
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::installActivationObserver(this);
+#endif
+}
+
+QQuickLabelPrivate::~QQuickLabelPrivate()
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::removeActivationObserver(this);
+#endif
+}
+
/*!
\internal
@@ -111,6 +127,28 @@ void QQuickLabelPrivate::_q_textChanged(const QString &text)
#endif
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickLabelPrivate::accessibilityActiveChanged(bool active)
+{
+ if (accessibleAttached || !active)
+ return;
+
+ Q_Q(QQuickLabel);
+ accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q, true));
+ if (accessibleAttached) {
+ accessibleAttached->setRole((QAccessible::Role)m_accessibleRole);
+ accessibleAttached->setName(text);
+ } else {
+ qWarning() << "QQuickLabel: " << q << " QQuickAccessibleAttached object creation failed!";
+ }
+}
+
+QAccessible::Role QQuickLabelPrivate::accessibleRole() const
+{
+ return QAccessible::Role(m_accessibleRole);
+}
+#endif
+
QFont QQuickLabel::font() const
{
return QQuickText::font();
@@ -136,19 +174,6 @@ void QQuickLabel::setFont(const QFont &font)
emit fontChanged();
}
-void QQuickLabel::classBegin()
-{
- QQuickText::classBegin();
-#ifndef QT_NO_ACCESSIBILITY
- Q_D(QQuickLabel);
- d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true));
- if (d->accessibleAttached)
- d->accessibleAttached->setRole((QAccessible::Role)0x00000029); // Accessible.StaticText
- else
- qWarning() << "QQuickLabel: QQuickAccessibleAttached object creation failed!";
-#endif
-}
-
/*!
\qmlproperty Item Qt.labs.controls::Label::background
diff --git a/src/templates/qquicklabel_p.h b/src/templates/qquicklabel_p.h
index 153f9c8c..77258e84 100644
--- a/src/templates/qquicklabel_p.h
+++ b/src/templates/qquicklabel_p.h
@@ -78,8 +78,6 @@ Q_SIGNALS:
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
- void classBegin() Q_DECL_OVERRIDE;
-
private:
Q_DISABLE_COPY(QQuickLabel)
Q_DECLARE_PRIVATE(QQuickLabel)
diff --git a/src/templates/qquicklabel_p_p.h b/src/templates/qquicklabel_p_p.h
index 16a66cc6..c2a064fe 100644
--- a/src/templates/qquicklabel_p_p.h
+++ b/src/templates/qquicklabel_p_p.h
@@ -50,16 +50,24 @@
#include <QtQuick/private/qquicktext_p_p.h>
+#ifndef QT_NO_ACCESSIBILITY
+#include <QtGui/qaccessible.h>
+#endif
+
QT_BEGIN_NAMESPACE
class QQuickAccessibleAttached;
class QQuickLabelPrivate : public QQuickTextPrivate
+#ifndef QT_NO_ACCESSIBILITY
+ , public QAccessible::ActivationObserver
+#endif
{
Q_DECLARE_PUBLIC(QQuickLabel)
public:
- QQuickLabelPrivate() : background(Q_NULLPTR), accessibleAttached(Q_NULLPTR) { }
+ QQuickLabelPrivate();
+ ~QQuickLabelPrivate();
static QQuickLabelPrivate *get(QQuickLabel *item) {
return static_cast<QQuickLabelPrivate *>(QObjectPrivate::get(item)); }
@@ -69,8 +77,14 @@ public:
void _q_textChanged(const QString &text);
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+ virtual QAccessible::Role accessibleRole() const Q_DECL_OVERRIDE;
+#endif
+
QQuickItem *background;
QQuickAccessibleAttached *accessibleAttached;
+ int m_accessibleRole;
};
Q_DECLARE_TYPEINFO(QQuickLabelPrivate, Q_COMPLEX_TYPE);
diff --git a/src/templates/qquickpageindicator.cpp b/src/templates/qquickpageindicator.cpp
index 18cd33ff..bf8dbc3a 100644
--- a/src/templates/qquickpageindicator.cpp
+++ b/src/templates/qquickpageindicator.cpp
@@ -66,7 +66,10 @@ class QQuickPageIndicatorPrivate : public QQuickControlPrivate, public QQuickIte
public:
QQuickPageIndicatorPrivate() : count(0), currentIndex(0),
- interactive(false), delegate(Q_NULLPTR), pressedItem(Q_NULLPTR) { }
+ interactive(false), delegate(Q_NULLPTR), pressedItem(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x00000027; //QAccessible::Indicator
+ }
QQuickItem *itemAt(const QPoint &pos) const;
void updatePressed(bool pressed, const QPoint &pos = QPoint());
@@ -121,7 +124,6 @@ void QQuickPageIndicatorPrivate::itemChildAdded(QQuickItem *, QQuickItem *child)
QQuickPageIndicator::QQuickPageIndicator(QQuickItem *parent) :
QQuickControl(*(new QQuickPageIndicatorPrivate), parent)
{
- setAccessibleRole(0x00000027); //QAccessible::Indicator
}
/*!
diff --git a/src/templates/qquickprogressbar.cpp b/src/templates/qquickprogressbar.cpp
index 4113ba9a..c05962ba 100644
--- a/src/templates/qquickprogressbar.cpp
+++ b/src/templates/qquickprogressbar.cpp
@@ -68,7 +68,10 @@ QT_BEGIN_NAMESPACE
class QQuickProgressBarPrivate : public QQuickControlPrivate
{
public:
- QQuickProgressBarPrivate() : from(0), to(1.0), value(0), indeterminate(false), indicator(Q_NULLPTR) { }
+ QQuickProgressBarPrivate() : from(0), to(1.0), value(0), indeterminate(false), indicator(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x00000030; //QAccessible::ProgressBar
+ }
qreal from;
qreal to;
@@ -80,7 +83,6 @@ public:
QQuickProgressBar::QQuickProgressBar(QQuickItem *parent) :
QQuickControl(*(new QQuickProgressBarPrivate), parent)
{
- setAccessibleRole(0x00000030); //QAccessible::ProgressBar
}
/*!
diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp
index df5f1f08..17654fc4 100644
--- a/src/templates/qquickrangeslider.cpp
+++ b/src/templates/qquickrangeslider.cpp
@@ -301,6 +301,7 @@ public:
snapMode(QQuickRangeSlider::NoSnap),
track(Q_NULLPTR)
{
+ m_accessibleRole = 0x00000033; //QAccessible::Slider
}
qreal from;
@@ -356,7 +357,6 @@ QQuickRangeSlider::QQuickRangeSlider(QQuickItem *parent) :
d->second = new QQuickRangeSliderNode(1.0, this);
setAcceptedMouseButtons(Qt::LeftButton);
- setAccessibleRole(0x00000033); //QAccessible::Slider
setFlag(QQuickItem::ItemIsFocusScope);
}
diff --git a/src/templates/qquickscrollbar.cpp b/src/templates/qquickscrollbar.cpp
index 559efaaa..cb3e2766 100644
--- a/src/templates/qquickscrollbar.cpp
+++ b/src/templates/qquickscrollbar.cpp
@@ -81,7 +81,10 @@ class QQuickScrollBarPrivate : public QQuickControlPrivate
public:
QQuickScrollBarPrivate() : size(0), position(0), offset(0),
active(false), pressed(false), moving(false),
- orientation(Qt::Vertical), handle(Q_NULLPTR) { }
+ orientation(Qt::Vertical), handle(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x00000003; // QAccessible::ScrollBar
+ }
static QQuickScrollBarPrivate *get(QQuickScrollBar *bar)
{
@@ -103,7 +106,6 @@ QQuickScrollBar::QQuickScrollBar(QQuickItem *parent) :
{
setKeepMouseGrab(true);
setAcceptedMouseButtons(Qt::LeftButton);
- setAccessibleRole(0x00000003); //QAccessible::ScrollBar
}
QQuickScrollBarAttached *QQuickScrollBar::qmlAttachedProperties(QObject *object)
@@ -287,6 +289,17 @@ qreal QQuickScrollBar::positionAt(const QPoint &point) const
return point.y() / height();
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickScrollBar::accessibilityActiveChanged(bool active)
+{
+ QQuickControl::accessibilityActiveChanged(active);
+
+ Q_D(QQuickScrollBar);
+ if (active)
+ setAccessibleProperty("pressed", d->pressed);
+}
+#endif
+
class QQuickScrollBarAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener
{
public:
diff --git a/src/templates/qquickscrollbar_p.h b/src/templates/qquickscrollbar_p.h
index 10cb470b..34ed8b8c 100644
--- a/src/templates/qquickscrollbar_p.h
+++ b/src/templates/qquickscrollbar_p.h
@@ -105,6 +105,10 @@ protected:
virtual qreal positionAt(const QPoint &point) const;
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+#endif
+
private:
Q_DISABLE_COPY(QQuickScrollBar)
Q_DECLARE_PRIVATE(QQuickScrollBar)
diff --git a/src/templates/qquickscrollindicator.cpp b/src/templates/qquickscrollindicator.cpp
index 869e784c..d8bc8d06 100644
--- a/src/templates/qquickscrollindicator.cpp
+++ b/src/templates/qquickscrollindicator.cpp
@@ -80,7 +80,10 @@ class QQuickScrollIndicatorPrivate : public QQuickControlPrivate
{
public:
QQuickScrollIndicatorPrivate() : size(0), position(0),
- active(false), orientation(Qt::Vertical), indicator(Q_NULLPTR) { }
+ active(false), orientation(Qt::Vertical), indicator(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x00000027; //QAccessible::Indicator
+ }
qreal size;
qreal position;
@@ -92,7 +95,6 @@ public:
QQuickScrollIndicator::QQuickScrollIndicator(QQuickItem *parent) :
QQuickControl(*(new QQuickScrollIndicatorPrivate), parent)
{
- setAccessibleRole(0x00000027); //QAccessible::Indicator
}
QQuickScrollIndicatorAttached *QQuickScrollIndicator::qmlAttachedProperties(QObject *object)
diff --git a/src/templates/qquickslider.cpp b/src/templates/qquickslider.cpp
index 9e15f1aa..3413d504 100644
--- a/src/templates/qquickslider.cpp
+++ b/src/templates/qquickslider.cpp
@@ -78,7 +78,10 @@ class QQuickSliderPrivate : public QQuickControlPrivate
public:
QQuickSliderPrivate() : from(0), to(1), value(0), position(0), stepSize(0), pressed(false),
orientation(Qt::Horizontal), snapMode(QQuickSlider::NoSnap),
- handle(Q_NULLPTR), track(Q_NULLPTR) { }
+ handle(Q_NULLPTR), track(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x00000033; // QAccessible::Slider
+ }
qreal valueAt(qreal position) const;
qreal snapPosition(qreal position) const;
@@ -157,7 +160,6 @@ QQuickSlider::QQuickSlider(QQuickItem *parent) :
{
setActiveFocusOnTab(true);
setAcceptedMouseButtons(Qt::LeftButton);
- setAccessibleRole(0x00000033); //QAccessible::Slider
}
/*!
@@ -555,4 +557,15 @@ void QQuickSlider::componentComplete()
d->updatePosition();
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickSlider::accessibilityActiveChanged(bool active)
+{
+ QQuickControl::accessibilityActiveChanged(active);
+
+ Q_D(QQuickSlider);
+ if (active)
+ setAccessibleProperty("pressed", d->pressed);
+}
+#endif
+
QT_END_NAMESPACE
diff --git a/src/templates/qquickslider_p.h b/src/templates/qquickslider_p.h
index 4cafbfda..9b37d740 100644
--- a/src/templates/qquickslider_p.h
+++ b/src/templates/qquickslider_p.h
@@ -136,6 +136,10 @@ protected:
void mirrorChange() Q_DECL_OVERRIDE;
void componentComplete() Q_DECL_OVERRIDE;
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+#endif
+
private:
Q_DISABLE_COPY(QQuickSlider)
Q_DECLARE_PRIVATE(QQuickSlider)
diff --git a/src/templates/qquickswitch.cpp b/src/templates/qquickswitch.cpp
index 7259e75d..35b0b85c 100644
--- a/src/templates/qquickswitch.cpp
+++ b/src/templates/qquickswitch.cpp
@@ -105,7 +105,6 @@ QQuickSwitch::QQuickSwitch(QQuickItem *parent) :
setCheckable(true);
setFiltersChildMouseEvents(true);
QObjectPrivate::connect(this, &QQuickAbstractButton::checkedChanged, d_func(), &QQuickSwitchPrivate::updatePosition);
- setAccessibleRole(0x0000002B); //QAccessible::Button
}
/*!
diff --git a/src/templates/qquicktabbar.cpp b/src/templates/qquicktabbar.cpp
index 6068a832..890e38cb 100644
--- a/src/templates/qquicktabbar.cpp
+++ b/src/templates/qquicktabbar.cpp
@@ -67,7 +67,10 @@ class QQuickTabBarPrivate : public QQuickContainerPrivate
Q_DECLARE_PUBLIC(QQuickTabBar)
public:
- QQuickTabBarPrivate() : group(Q_NULLPTR) { }
+ QQuickTabBarPrivate() : group(Q_NULLPTR)
+ {
+ m_accessibleRole = 0x0000003C; //QAccessible::PageTabList
+ }
void updateLayout();
void updateCurrent();
@@ -134,7 +137,6 @@ QQuickTabBar::QQuickTabBar(QQuickItem *parent) :
{
Q_D(QQuickTabBar);
setFlag(ItemIsFocusScope);
- setAccessibleRole(0x0000003C); //QAccessible::PageTabList
d->group = new QQuickExclusiveGroup(this);
connect(d->group, &QQuickExclusiveGroup::currentChanged, this, &QQuickTabBar::currentItemChanged);
diff --git a/src/templates/qquicktextarea.cpp b/src/templates/qquicktextarea.cpp
index 0cc34ecb..dafa040b 100644
--- a/src/templates/qquicktextarea.cpp
+++ b/src/templates/qquicktextarea.cpp
@@ -70,6 +70,23 @@ QT_BEGIN_NAMESPACE
\sa TextField, {Customizing TextArea}, {Input Controls}
*/
+QQuickTextAreaPrivate::QQuickTextAreaPrivate()
+ : background(Q_NULLPTR), placeholder(Q_NULLPTR), accessibleAttached(Q_NULLPTR)
+ , m_accessibleRole(0x0000002A) // Accessible.EditableText
+
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::installActivationObserver(this);
+#endif
+}
+
+QQuickTextAreaPrivate::~QQuickTextAreaPrivate()
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::removeActivationObserver(this);
+#endif
+}
+
void QQuickTextAreaPrivate::resizeBackground()
{
Q_Q(QQuickTextArea);
@@ -149,9 +166,8 @@ void QQuickTextAreaPrivate::resolveFont()
void QQuickTextAreaPrivate::_q_readOnlyChanged(bool isReadOnly)
{
#ifndef QT_NO_ACCESSIBILITY
- Q_Q(QQuickTextArea);
if (accessibleAttached)
- QQuickAccessibleAttached::setProperty(q, "readOnly", isReadOnly);
+ accessibleAttached->set_readOnly(isReadOnly);
#else
Q_UNUSED(isReadOnly)
#endif
@@ -167,6 +183,30 @@ void QQuickTextAreaPrivate::_q_placeholderTextChanged(const QString &text)
#endif
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickTextAreaPrivate::accessibilityActiveChanged(bool active)
+{
+ if (accessibleAttached || !active)
+ return;
+
+ Q_Q(QQuickTextArea);
+ accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q, true));
+ if (accessibleAttached) {
+ accessibleAttached->setRole((QAccessible::Role)m_accessibleRole);
+ accessibleAttached->set_readOnly(q->isReadOnly());
+ if (placeholder)
+ accessibleAttached->setDescription(placeholder->text());
+ } else {
+ qWarning() << "QQuickTextArea: " << q << " QQuickAccessibleAttached object creation failed!";
+ }
+}
+
+QAccessible::Role QQuickTextAreaPrivate::accessibleRole() const
+{
+ return QAccessible::Role(m_accessibleRole);
+}
+#endif
+
QFont QQuickTextArea::font() const
{
return QQuickTextEdit::font();
@@ -335,19 +375,4 @@ void QQuickTextArea::timerEvent(QTimerEvent *event)
}
}
-void QQuickTextArea::classBegin()
-{
- QQuickTextEdit::classBegin();
-#ifndef QT_NO_ACCESSIBILITY
- Q_D(QQuickTextArea);
- d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true));
- if (d->accessibleAttached) {
- d->accessibleAttached->setRole((QAccessible::Role)(0x0000002A)); // Accessible.EditableText
- QQuickAccessibleAttached::setProperty(this, "multiLine", true);
- } else {
- qWarning() << "QQuickTextArea: QQuickAccessibleAttached object creation failed!";
- }
-#endif
-}
-
QT_END_NAMESPACE
diff --git a/src/templates/qquicktextarea_p.h b/src/templates/qquicktextarea_p.h
index 4acd2e82..a77cfeb8 100644
--- a/src/templates/qquicktextarea_p.h
+++ b/src/templates/qquicktextarea_p.h
@@ -95,8 +95,6 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
- void classBegin() Q_DECL_OVERRIDE;
-
private:
Q_DISABLE_COPY(QQuickTextArea)
Q_DECLARE_PRIVATE(QQuickTextArea)
diff --git a/src/templates/qquicktextarea_p_p.h b/src/templates/qquicktextarea_p_p.h
index e53c5beb..01959354 100644
--- a/src/templates/qquicktextarea_p_p.h
+++ b/src/templates/qquicktextarea_p_p.h
@@ -53,16 +53,24 @@
#include "qquicktextarea_p.h"
+#ifndef QT_NO_ACCESSIBILITY
+#include <QtGui/qaccessible.h>
+#endif
+
QT_BEGIN_NAMESPACE
class QQuickAccessibleAttached;
class QQuickTextAreaPrivate : public QQuickTextEditPrivate
+#ifndef QT_NO_ACCESSIBILITY
+ , public QAccessible::ActivationObserver
+#endif
{
Q_DECLARE_PUBLIC(QQuickTextArea)
public:
- QQuickTextAreaPrivate() : background(Q_NULLPTR), placeholder(Q_NULLPTR), accessibleAttached(Q_NULLPTR) { }
+ QQuickTextAreaPrivate();
+ ~QQuickTextAreaPrivate();
static QQuickTextAreaPrivate *get(QQuickTextArea *item) {
return static_cast<QQuickTextAreaPrivate *>(QObjectPrivate::get(item)); }
@@ -79,10 +87,16 @@ public:
void _q_readOnlyChanged(bool isReadOnly);
void _q_placeholderTextChanged(const QString &text);
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+ QAccessible::Role accessibleRole() const Q_DECL_OVERRIDE;
+#endif
+
QQuickItem *background;
QQuickText *placeholder;
QQuickPressAndHoldHelper pressAndHoldHelper;
QQuickAccessibleAttached *accessibleAttached;
+ int m_accessibleRole;
};
Q_DECLARE_TYPEINFO(QQuickTextAreaPrivate, Q_COMPLEX_TYPE);
diff --git a/src/templates/qquicktextfield.cpp b/src/templates/qquicktextfield.cpp
index 945502c9..61cac6c4 100644
--- a/src/templates/qquicktextfield.cpp
+++ b/src/templates/qquicktextfield.cpp
@@ -88,6 +88,24 @@ QT_BEGIN_NAMESPACE
position of the press, and which button is pressed.
*/
+QQuickTextFieldPrivate::QQuickTextFieldPrivate()
+ : background(Q_NULLPTR)
+ , placeholder(Q_NULLPTR)
+ , accessibleAttached(Q_NULLPTR)
+ , m_accessibleRole(0x0000002A) // Accessible.EditableText
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::installActivationObserver(this);
+#endif
+}
+
+QQuickTextFieldPrivate::~QQuickTextFieldPrivate()
+{
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::removeActivationObserver(this);
+#endif
+}
+
void QQuickTextFieldPrivate::resizeBackground()
{
Q_Q(QQuickTextField);
@@ -169,9 +187,8 @@ void QQuickTextFieldPrivate::resolveFont()
void QQuickTextFieldPrivate::_q_readOnlyChanged(bool isReadOnly)
{
#ifndef QT_NO_ACCESSIBILITY
- Q_Q(QQuickTextField);
if (accessibleAttached)
- QQuickAccessibleAttached::setProperty(q, "readOnly", isReadOnly);
+ accessibleAttached->set_readOnly(isReadOnly);
#else
Q_UNUSED(isReadOnly)
#endif
@@ -190,15 +207,38 @@ void QQuickTextFieldPrivate::_q_placeholderTextChanged(const QString &text)
void QQuickTextFieldPrivate::_q_echoModeChanged(QQuickTextField::EchoMode echoMode)
{
#ifndef QT_NO_ACCESSIBILITY
- Q_Q(QQuickTextField);
if (accessibleAttached)
- QQuickAccessibleAttached::setProperty(q, "passwordEdit",
- (echoMode == QQuickTextField::Password || echoMode == QQuickTextField::PasswordEchoOnEdit) ? true : false);
+ accessibleAttached->set_passwordEdit((echoMode == QQuickTextField::Password || echoMode == QQuickTextField::PasswordEchoOnEdit) ? true : false);
#else
Q_UNUSED(echoMode)
#endif
}
+#ifndef QT_NO_ACCESSIBILITY
+void QQuickTextFieldPrivate::accessibilityActiveChanged(bool active)
+{
+ if (accessibleAttached || !active)
+ return;
+
+ Q_Q(QQuickTextField);
+ accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q, true));
+ if (accessibleAttached) {
+ accessibleAttached->setRole((QAccessible::Role)m_accessibleRole);
+ accessibleAttached->set_readOnly(m_readOnly);
+ accessibleAttached->set_passwordEdit((m_echoMode == QQuickTextField::Password || m_echoMode == QQuickTextField::PasswordEchoOnEdit) ? true : false);
+ if (placeholder)
+ accessibleAttached->setDescription(placeholder->text());
+ } else {
+ qWarning() << "QQuickTextField: " << q << " QQuickAccessibleAttached object creation failed!";
+ }
+}
+
+QAccessible::Role QQuickTextFieldPrivate::accessibleRole() const
+{
+ return QAccessible::Role(m_accessibleRole);
+}
+#endif
+
QFont QQuickTextField::font() const
{
return QQuickTextInput::font();
@@ -367,19 +407,4 @@ void QQuickTextField::timerEvent(QTimerEvent *event)
}
}
-void QQuickTextField::classBegin()
-{
- QQuickTextInput::classBegin();
-#ifndef QT_NO_ACCESSIBILITY
- Q_D(QQuickTextField);
- d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true));
- if (d->accessibleAttached) {
- d->accessibleAttached->setRole((QAccessible::Role)(0x0000002A)); // Accessible.EditableText
- QQuickAccessibleAttached::setProperty(this, "multiLine", true);
- } else {
- qWarning() << "QQuickTextField: QQuickAccessibleAttached object creation failed!";
- }
-#endif
-}
-
QT_END_NAMESPACE
diff --git a/src/templates/qquicktextfield_p.h b/src/templates/qquicktextfield_p.h
index f13802b7..445cf3d9 100644
--- a/src/templates/qquicktextfield_p.h
+++ b/src/templates/qquicktextfield_p.h
@@ -95,8 +95,6 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
- void classBegin() Q_DECL_OVERRIDE;
-
private:
Q_DISABLE_COPY(QQuickTextField)
Q_DECLARE_PRIVATE(QQuickTextField)
diff --git a/src/templates/qquicktextfield_p_p.h b/src/templates/qquicktextfield_p_p.h
index a60efb09..3c73983d 100644
--- a/src/templates/qquicktextfield_p_p.h
+++ b/src/templates/qquicktextfield_p_p.h
@@ -53,19 +53,24 @@
#include "qquicktextfield_p.h"
+#ifndef QT_NO_ACCESSIBILITY
+#include <QtGui/qaccessible.h>
+#endif
+
QT_BEGIN_NAMESPACE
class QQuickAccessibleAttached;
class QQuickTextFieldPrivate : public QQuickTextInputPrivate
+#ifndef QT_NO_ACCESSIBILITY
+ , public QAccessible::ActivationObserver
+#endif
{
Q_DECLARE_PUBLIC(QQuickTextField)
public:
- QQuickTextFieldPrivate()
- : background(Q_NULLPTR)
- , placeholder(Q_NULLPTR)
- { }
+ QQuickTextFieldPrivate();
+ ~QQuickTextFieldPrivate();
static QQuickTextFieldPrivate *get(QQuickTextField *item) {
return static_cast<QQuickTextFieldPrivate *>(QObjectPrivate::get(item)); }
@@ -83,10 +88,16 @@ public:
void _q_placeholderTextChanged(const QString &text);
void _q_echoModeChanged(QQuickTextField::EchoMode echoMode);
+#ifndef QT_NO_ACCESSIBILITY
+ void accessibilityActiveChanged(bool active) Q_DECL_OVERRIDE;
+ QAccessible::Role accessibleRole() const Q_DECL_OVERRIDE;
+#endif
+
QQuickItem *background;
QQuickText *placeholder;
QQuickPressAndHoldHelper pressAndHoldHelper;
QQuickAccessibleAttached *accessibleAttached;
+ int m_accessibleRole;
};
Q_DECLARE_TYPEINFO(QQuickTextFieldPrivate, Q_COMPLEX_TYPE);