diff options
author | Jan-Arve Saether <jan-arve.saether@nokia.com> | 2012-08-13 15:35:44 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-16 14:10:43 (GMT) |
commit | 8c749cab4d457644a14698709d1c74dfa4d5ac6e (patch) | |
tree | 5ef0f063f50db9fa835b8f0de3b78ff6dfb99061 | |
parent | 4917daf500f0403042de35fcc17daa2d7d4f8475 (diff) | |
download | Qt-8c749cab4d457644a14698709d1c74dfa4d5ac6e.zip Qt-8c749cab4d457644a14698709d1c74dfa4d5ac6e.tar.gz Qt-8c749cab4d457644a14698709d1c74dfa4d5ac6e.tar.bz2 |
Implement QAccessibleLineEdit::characterRect()
It was probably not implemented because it needed to access
private APIs.
However, accessing those from this a11y plugin is unproblematic.
Change-Id: Icadad45a83daa60e2fbc4cab17b91c84c3f36a7f
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
-rw-r--r-- | src/gui/widgets/qlineedit.h | 1 | ||||
-rw-r--r-- | src/plugins/accessible/widgets/simplewidgets.cpp | 19 | ||||
-rw-r--r-- | tests/auto/qaccessibility/tst_qaccessibility.cpp | 10 |
3 files changed, 27 insertions, 3 deletions
diff --git a/src/gui/widgets/qlineedit.h b/src/gui/widgets/qlineedit.h index 48ff06b..c14d188 100644 --- a/src/gui/widgets/qlineedit.h +++ b/src/gui/widgets/qlineedit.h @@ -273,6 +273,7 @@ Q_SIGNALS: private: friend class QAbstractSpinBox; + friend class QAccessibleLineEdit; #ifdef QT_KEYPAD_NAVIGATION friend class QDateTimeEdit; #endif diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index 46d76f0..126045e 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -51,6 +51,7 @@ #include <qgroupbox.h> #include <qlcdnumber.h> #include <qlineedit.h> +#include <private/qlineedit_p.h> #include <qstyle.h> #include <qstyleoption.h> @@ -876,10 +877,22 @@ int QAccessibleLineEdit::cursorPosition() return lineEdit()->cursorPosition(); } -QRect QAccessibleLineEdit::characterRect(int /*offset*/, CoordinateType /*coordType*/) +QRect QAccessibleLineEdit::characterRect(int offset, CoordinateType coordType) { - // QLineEdit doesn't hand out character rects - return QRect(); + int left, top, right, bottom; + lineEdit()->getTextMargins(&left, &top, &right, &bottom); + int x = lineEdit()->d_func()->control->cursorToX(offset); + int y = top; + QFontMetrics fm(lineEdit()->font()); + const QString ch = text(offset, offset + 1); + int w = fm.width(ch); + int h = fm.height(); + + QRect r(x, y, w, h); + if (coordType == QAccessible2::RelativeToScreen) + r.moveTo(lineEdit()->mapToGlobal(r.topLeft())); + + return r; } int QAccessibleLineEdit::selectionCount() diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 297e853..c42269b 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -3150,6 +3150,16 @@ void tst_QAccessibility::lineEditTest() QCOMPARE(textIface->textAtOffset(5, QAccessible2::LineBoundary,&start,&end), cite); QCOMPARE(textIface->textAtOffset(5, QAccessible2::NoBoundary,&start,&end), cite); + + // characterRect() + le3->show(); + QTest::qWaitForWindowShown(le3); + const QRect lineEditRect = iface->rect(0); + // Only first 10 characters, check if they are within the bounds of line edit + for (int i = 0; i < 10; ++i) { + QVERIFY(lineEditRect.contains(textIface->characterRect(i, QAccessible2::RelativeToScreen))); + } + delete iface; delete toplevel; QTestAccessibility::clearEvents(); |