summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-04-02 19:49:08 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-05 21:48:31 +0200
commitcc57a2e90f18a39ce3c74b6ad0db9a64aa135ddf (patch)
treea05e8c31601d85710f00fe1d8ebb21cabe9f048f /src
parent39c5098dbb3dd547c315c5baf0f83ebe81b28756 (diff)
Accessibility text updates for QTextEdit
For Mac this makes QTextEdit work nicely with VoiceOver. Task-number: QTBUG-37204 Change-Id: I1326d24ca6a932ad667ee395f62881b6ec64e892 Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp28
-rw-r--r--src/widgets/widgets/qwidgettextcontrol_p.h1
-rw-r--r--src/widgets/widgets/qwidgettextcontrol_p_p.h1
3 files changed, 30 insertions, 0 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 3740f3e698..9cc62fd10a 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -438,6 +438,7 @@ void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString
QObject::connect(doc, SIGNAL(contentsChanged()), q, SLOT(_q_updateCurrentCharFormatAndSelection()));
QObject::connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), q, SLOT(_q_emitCursorPosChanged(QTextCursor)));
+ QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q, SLOT(_q_contentsChanged(int,int,int)));
QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged()));
// convenience signal forwards
@@ -641,6 +642,33 @@ void QWidgetTextControlPrivate::_q_emitCursorPosChanged(const QTextCursor &someC
}
}
+void QWidgetTextControlPrivate::_q_contentsChanged(int from, int charsRemoved, int charsAdded)
+{
+ Q_Q(QWidgetTextControl);
+#ifndef QT_NO_ACCESSIBILITY
+ if (QAccessible::isActive()) {
+ QTextCursor tmp(doc);
+ tmp.setPosition(from);
+ tmp.setPosition(from + charsAdded, QTextCursor::KeepAnchor);
+ QString newText = tmp.selectedText();
+
+ // always report the right number of removed chars, but in lack of the real string use spaces
+ QString oldText = QString(charsRemoved, QLatin1Char(' '));
+
+ QAccessibleEvent *ev = 0;
+ if (charsRemoved == 0) {
+ ev = new QAccessibleTextInsertEvent(q->parent(), from, newText);
+ } else if (charsAdded == 0) {
+ ev = new QAccessibleTextRemoveEvent(q->parent(), from, oldText);
+ } else {
+ ev = new QAccessibleTextUpdateEvent(q->parent(), from, oldText, newText);
+ }
+ QAccessible::updateAccessibility(ev);
+ delete ev;
+ }
+#endif
+}
+
void QWidgetTextControlPrivate::_q_documentLayoutChanged()
{
Q_Q(QWidgetTextControl);
diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h
index 0c76355ca1..867b55fe32 100644
--- a/src/widgets/widgets/qwidgettextcontrol_p.h
+++ b/src/widgets/widgets/qwidgettextcontrol_p.h
@@ -262,6 +262,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_copyLink())
Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
+ Q_PRIVATE_SLOT(d_func(), void _q_contentsChanged(int, int, int))
};
diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h
index 727821015e..4d578c76f8 100644
--- a/src/widgets/widgets/qwidgettextcontrol_p_p.h
+++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h
@@ -111,6 +111,7 @@ public:
#endif
void _q_emitCursorPosChanged(const QTextCursor &someCursor);
+ void _q_contentsChanged(int from, int charsRemoved, int charsAdded);
void setBlinkingCursorEnabled(bool enable);