summaryrefslogtreecommitdiffstats
path: root/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-03-05 14:37:37 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-08 11:35:44 +0200
commit8307ab784eb4d8d22441ee61f02cb381684ca3a2 (patch)
tree9ad1be637574d2979b5a63b3087dfab7770daf2f /src/plugins/accessible/widgets/qaccessiblewidgets.cpp
parent6f0dc9f4c7c1405bdbfef32395d0fb091bb0c8c8 (diff)
Make QTextCursor accessibility boundary finder available
This allows re-using the function in QtQuick. In addition TextBoundaryType is moved to QAccessible and QAccessible2 as namespace ceases to exist. Change-Id: I184bc2c181a22ca51ac4db4e5a080dc26d4acfe0 Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src/plugins/accessible/widgets/qaccessiblewidgets.cpp')
-rw-r--r--src/plugins/accessible/widgets/qaccessiblewidgets.cpp94
1 files changed, 16 insertions, 78 deletions
diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
index 751a722bb8..f20823f25b 100644
--- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
@@ -72,8 +72,6 @@
QT_BEGIN_NAMESPACE
-using namespace QAccessible2;
-
QString Q_GUI_EXPORT qt_accStripAmp(const QString &text);
QString Q_GUI_EXPORT qt_accHotKey(const QString &text);
@@ -997,83 +995,18 @@ QPoint QAccessibleTextWidget::scrollBarPosition() const
return QPoint(0, 0);
}
-QPair< int, int > QAccessibleTextWidget::getBoundaries(int offset, BoundaryType boundaryType) const
-{
- if (offset >= characterCount())
- return QPair<int, int>(characterCount(), characterCount());
- if (offset < 0)
- return QPair<int, int>(0, 0);
-
- QTextCursor cursor = textCursor();
- QPair<int, int> result;
-
- cursor.setPosition(offset);
- switch (boundaryType) {
- case CharBoundary:
- result.first = cursor.position();
- cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
- result.second = cursor.position();
- break;
- case WordBoundary:
- cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
- result.first = cursor.position();
- cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
- result.second = cursor.position();
- break;
- case SentenceBoundary: {
- // QCursor does not provide functionality to move to next sentence.
- // We therefore find the current block, then go through the block using
- // QTextBoundaryFinder and find the sentence the \offset represents
- cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
- result.first = cursor.position();
- cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
- result.second = cursor.position();
- QString blockText = cursor.selectedText();
- const int offsetWithinBlockText = offset - result.first;
- QTextBoundaryFinder sentenceFinder(QTextBoundaryFinder::Sentence, blockText);
- sentenceFinder.setPosition(offsetWithinBlockText);
- int prevBoundary = offsetWithinBlockText;
- int nextBoundary = offsetWithinBlockText;
- if (!(sentenceFinder.boundaryReasons() & QTextBoundaryFinder::StartOfItem))
- prevBoundary = sentenceFinder.toPreviousBoundary();
- nextBoundary = sentenceFinder.toNextBoundary();
- if (nextBoundary != -1)
- result.second = result.first + nextBoundary;
- if (prevBoundary != -1)
- result.first += prevBoundary;
- break; }
- case LineBoundary:
- cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
- result.first = cursor.position();
- cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
- result.second = cursor.position();
- break;
- case ParagraphBoundary:
- cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
- result.first = cursor.position();
- cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
- result.second = cursor.position();
- break;
- case NoBoundary:
- result.first = 0;
- result.second = characterCount();
- break;
- default:
- qWarning("QAccessibleTextWidget::getBoundaries: Unknown boundary type %d", boundaryType);
- result.first = -1;
- result.second = -1;
- }
- return result;
-}
-QString QAccessibleTextWidget::textBeforeOffset(int offset, BoundaryType boundaryType,
+QString QAccessibleTextWidget::textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType,
int *startOffset, int *endOffset) const
{
Q_ASSERT(startOffset);
Q_ASSERT(endOffset);
- QPair<int, int> boundaries = getBoundaries(offset, boundaryType);
- boundaries = getBoundaries(boundaries.first - 1, boundaryType);
+ QTextCursor cursor = textCursor();
+ cursor.setPosition(offset);
+ QPair<int, int> boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType);
+ cursor.setPosition(boundaries.first - 1);
+ boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType);
*startOffset = boundaries.first;
*endOffset = boundaries.second;
@@ -1082,14 +1015,17 @@ QString QAccessibleTextWidget::textBeforeOffset(int offset, BoundaryType boundar
}
-QString QAccessibleTextWidget::textAfterOffset(int offset, BoundaryType boundaryType,
+QString QAccessibleTextWidget::textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType,
int *startOffset, int *endOffset) const
{
Q_ASSERT(startOffset);
Q_ASSERT(endOffset);
- QPair<int, int> boundaries = getBoundaries(offset, boundaryType);
- boundaries = getBoundaries(boundaries.second, boundaryType);
+ QTextCursor cursor = textCursor();
+ cursor.setPosition(offset);
+ QPair<int, int> boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType);
+ cursor.setPosition(boundaries.second);
+ boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType);
*startOffset = boundaries.first;
*endOffset = boundaries.second;
@@ -1097,13 +1033,15 @@ QString QAccessibleTextWidget::textAfterOffset(int offset, BoundaryType boundary
return text(boundaries.first, boundaries.second);
}
-QString QAccessibleTextWidget::textAtOffset(int offset, BoundaryType boundaryType,
+QString QAccessibleTextWidget::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
int *startOffset, int *endOffset) const
{
Q_ASSERT(startOffset);
Q_ASSERT(endOffset);
- QPair<int, int> boundaries = getBoundaries(offset, boundaryType);
+ QTextCursor cursor = textCursor();
+ cursor.setPosition(offset);
+ QPair<int, int> boundaries = QAccessible::qAccessibleTextBoundaryHelper(cursor, boundaryType);
*startOffset = boundaries.first;
*endOffset = boundaries.second;