summaryrefslogtreecommitdiffstats
path: root/src/widgets/accessible/qaccessiblewidgets.cpp
diff options
context:
space:
mode:
authorBoris Dušek <me@dusek.me>2015-01-04 22:50:38 +0100
committerBoris Dušek <me@dusek.me>2015-03-05 15:05:12 +0000
commit8944d2dcbb3c21152b37482a2dc8e05024406649 (patch)
tree38e77a7da9725c409141341c3211eb0df21c9696 /src/widgets/accessible/qaccessiblewidgets.cpp
parente19a43be9053a3112520bb110759ac12db31c2fe (diff)
Fix QAccessibleTextWidget::characterRect for off-cursor positions
Current code retrieved the character format at position where the cursor currently was, irrespective of the position actually passed to the characterRect function. This is now fixed and we retrieve the character format for the QTextFragment containing the specified offset. This fixes display of visual bounds around text by screen reader in some cases. E.g. on OS X, when searching text using VoiceOver, VoiceOver first queries the visual bounds of the found text (and thus also characterRect), and only then it moves cursor position to the found text. If before the change of position the cursor was on some text with different metrics (i.e. a bigger font), the visual bounds for the found text reflected those metrics, not the metrics of the actual found text for which the bounds were drawn. This resulted in smaller/bigger rectangles around the found text than was actually correct. Change-Id: If23b4b8492ec77f0f073fc5c25628b67b483724e Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'src/widgets/accessible/qaccessiblewidgets.cpp')
-rw-r--r--src/widgets/accessible/qaccessiblewidgets.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/widgets/accessible/qaccessiblewidgets.cpp b/src/widgets/accessible/qaccessiblewidgets.cpp
index 77958d65a5..a2bf14b25b 100644
--- a/src/widgets/accessible/qaccessiblewidgets.cpp
+++ b/src/widgets/accessible/qaccessiblewidgets.cpp
@@ -667,7 +667,20 @@ QRect QAccessibleTextWidget::characterRect(int offset) const
if (line.isValid()) {
qreal x = line.cursorToX(relativeOffset);
- QFontMetrics fm(textCursor().charFormat().font());
+
+ QTextCharFormat format;
+ QTextBlock::iterator iter = block.begin();
+ if (iter.atEnd())
+ format = block.charFormat();
+ else {
+ while (!iter.atEnd() && !iter.fragment().contains(offset))
+ ++iter;
+ if (iter.atEnd()) // newline should have same format as preceding character
+ --iter;
+ format = iter.fragment().charFormat();
+ }
+
+ QFontMetrics fm(format.font());
const QString ch = text(offset, offset + 1);
if (!ch.isEmpty()) {
int w = fm.width(ch);