Implement QAccessibleLineEdit::characterRect()
It was probably not implemented because it needed to access private APIs. However, accessing those from this a11y plugin is unproblematic. Forward-ported from Qt 4.8 with change d2fb64d52fc6ec229d775f829a9a0cb3d251aad3 (and then slightly improved) Change-Id: Ifa2d48c152fd75fc1fff49a05369787a7db3b902 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
parent
47459d3350
commit
b626b98b95
@ -53,6 +53,7 @@
|
|||||||
#include <qgroupbox.h>
|
#include <qgroupbox.h>
|
||||||
#include <qlcdnumber.h>
|
#include <qlcdnumber.h>
|
||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
|
#include <private/qlineedit_p.h>
|
||||||
#include <qstyle.h>
|
#include <qstyle.h>
|
||||||
#include <qstyleoption.h>
|
#include <qstyleoption.h>
|
||||||
#include <qtextdocument.h>
|
#include <qtextdocument.h>
|
||||||
@ -672,10 +673,20 @@ int QAccessibleLineEdit::cursorPosition() const
|
|||||||
return lineEdit()->cursorPosition();
|
return lineEdit()->cursorPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QAccessibleLineEdit::characterRect(int /*offset*/) const
|
QRect QAccessibleLineEdit::characterRect(int offset) const
|
||||||
{
|
{
|
||||||
// QLineEdit doesn't hand out character rects
|
int x = lineEdit()->d_func()->control->cursorToX(offset);
|
||||||
|
int y;
|
||||||
|
lineEdit()->getTextMargins(0, &y, 0, 0);
|
||||||
|
QFontMetrics fm(lineEdit()->font());
|
||||||
|
const QString ch = text(offset, offset + 1);
|
||||||
|
if (ch.isEmpty())
|
||||||
return QRect();
|
return QRect();
|
||||||
|
int w = fm.width(ch);
|
||||||
|
int h = fm.height();
|
||||||
|
QRect r(x, y, w, h);
|
||||||
|
r.moveTo(lineEdit()->mapToGlobal(r.topLeft()));
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QAccessibleLineEdit::selectionCount() const
|
int QAccessibleLineEdit::selectionCount() const
|
||||||
|
@ -225,6 +225,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QAbstractSpinBox;
|
friend class QAbstractSpinBox;
|
||||||
|
friend class QAccessibleLineEdit;
|
||||||
#ifdef QT_KEYPAD_NAVIGATION
|
#ifdef QT_KEYPAD_NAVIGATION
|
||||||
friend class QDateTimeEdit;
|
friend class QDateTimeEdit;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1906,6 +1906,22 @@ void tst_QAccessibility::lineEditTest()
|
|||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QLineEdit le(QStringLiteral("My characters have geometries."), toplevel);
|
||||||
|
// characterRect()
|
||||||
|
le.show();
|
||||||
|
QTest::qWaitForWindowShown(&le);
|
||||||
|
QAIPtr iface(QAccessible::queryAccessibleInterface(&le));
|
||||||
|
QAccessibleTextInterface* textIface = iface->textInterface();
|
||||||
|
QVERIFY(textIface);
|
||||||
|
const QRect lineEditRect = iface->rect();
|
||||||
|
// 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)));
|
||||||
|
}
|
||||||
|
QTestAccessibility::clearEvents();
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Test events: cursor movement, selection, text changes
|
// Test events: cursor movement, selection, text changes
|
||||||
QString text = "Hello, world";
|
QString text = "Hello, world";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user