const int y1 = fm.height() * 3 / 2;
int pos = texteditObject->positionAt(texteditObject->width()/2, y0);
- int width = 0;
+ int widthBegin = 0;
+ int widthEnd = 0;
if (!qmlDisableDistanceField()) {
- QTextLayout layout(texteditObject->text().left(pos));
+ QTextLayout layout(texteditObject->text());
- {
- QTextOption option;
- option.setUseDesignMetrics(true);
- layout.setTextOption(option);
- }
+ QTextOption option;
+ option.setUseDesignMetrics(true);
+ layout.setTextOption(option);
layout.beginLayout();
QTextLine line = layout.createLine();
layout.endLayout();
- width = ceil(line.horizontalAdvance());
-
+ widthBegin = floor(line.cursorToX(pos - 1));
+ widthEnd = ceil(line.cursorToX(pos + 1));
} else {
- width = fm.width(texteditObject->text().left(pos));
+ widthBegin = fm.width(texteditObject->text().left(pos - 1));
+ widthEnd = fm.width(texteditObject->text().left(pos + 1));
}
-
- int diff = abs(int(width-texteditObject->width()/2));
-
- QEXPECT_FAIL("", "QTBUG-21689", Abort);
- // some tollerance for different fonts.
-#ifdef Q_OS_LINUX
- QVERIFY(diff < 2);
-#else
- QVERIFY(diff < 5);
-#endif
+ QVERIFY(widthBegin <= texteditObject->width() / 2);
+ QVERIFY(widthEnd >= texteditObject->width() / 2);
const qreal x0 = texteditObject->positionToRectangle(pos).x();
const qreal x1 = texteditObject->positionToRectangle(pos + 1).x();
texteditObject->setCursorPosition(0);
QInputMethodEvent inputEvent(preeditText, QList<QInputMethodEvent::Attribute>());
- QGuiApplication::sendEvent(&canvas, &inputEvent);
+ QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &inputEvent);
// Check all points within the preedit text return the same position.
QCOMPARE(texteditObject->positionAt(0, y0), 0);
int pos = textinputObject->positionAt(textinputObject->width()/2);
int textWidth = 0;
- int textLeftWidth = 0;
+ int textLeftWidthBegin = 0;
+ int textLeftWidthEnd = 0;
if (!qmlDisableDistanceField()) {
- {
- QTextLayout layout(textinputObject->text().left(pos));
+ QTextLayout layout(textinputObject->text());
- {
- QTextOption option;
- option.setUseDesignMetrics(true);
- layout.setTextOption(option);
- }
-
- layout.beginLayout();
- QTextLine line = layout.createLine();
- layout.endLayout();
-
- textLeftWidth = ceil(line.horizontalAdvance());
- }
- {
- QTextLayout layout(textinputObject->text());
-
- {
- QTextOption option;
- option.setUseDesignMetrics(true);
- layout.setTextOption(option);
- }
+ QTextOption option;
+ option.setUseDesignMetrics(true);
+ layout.setTextOption(option);
- layout.beginLayout();
- QTextLine line = layout.createLine();
- layout.endLayout();
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ layout.endLayout();
- textWidth = ceil(line.horizontalAdvance());
- }
+ textLeftWidthBegin = floor(line.cursorToX(pos - 1));
+ textLeftWidthEnd = ceil(line.cursorToX(pos + 1));
+ textWidth = floor(line.horizontalAdvance());
} else {
textWidth = fm.width(textinputObject->text());
- textLeftWidth = fm.width(textinputObject->text().left(pos));
+ textLeftWidthBegin = fm.width(textinputObject->text().left(pos - 1));
+ textLeftWidthEnd = fm.width(textinputObject->text().left(pos + 1));
}
- int diff = abs(textWidth - (textLeftWidth+textinputObject->width()/2));
-
- // some tollerance for different fonts.
- QEXPECT_FAIL("", "QTBUG-21689", Abort);
-#ifdef Q_OS_LINUX
- QVERIFY(diff < 2);
-#else
- QVERIFY(diff < 5);
-#endif
+ QVERIFY(textLeftWidthBegin <= textWidth - textinputObject->width() / 2);
+ QVERIFY(textLeftWidthEnd >= textWidth - textinputObject->width() / 2);
int x = textinputObject->positionToRectangle(pos + 1).x() - 1;
QCOMPARE(textinputObject->positionAt(x, QQuickTextInput::CursorBetweenCharacters), pos + 1);
pos = textinputObject->positionAt(textinputObject->width()/2);
if (!qmlDisableDistanceField()) {
- {
- QTextLayout layout(textinputObject->text().left(pos));
+ QTextLayout layout(textinputObject->text());
- {
- QTextOption option;
- option.setUseDesignMetrics(true);
- layout.setTextOption(option);
- }
+ QTextOption option;
+ option.setUseDesignMetrics(true);
+ layout.setTextOption(option);
- layout.beginLayout();
- QTextLine line = layout.createLine();
- layout.endLayout();
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ layout.endLayout();
- textLeftWidth = ceil(line.horizontalAdvance());
- }
+ textLeftWidthBegin = floor(line.cursorToX(pos - 1));
+ textLeftWidthEnd = ceil(line.cursorToX(pos + 1));
} else {
- textLeftWidth = fm.width(textinputObject->text().left(pos));
+ textLeftWidthBegin = fm.width(textinputObject->text().left(pos - 1));
+ textLeftWidthEnd = fm.width(textinputObject->text().left(pos + 1));
}
- diff = abs(int(textLeftWidth-textinputObject->width()/2));
-
- // some tollerance for different fonts.
-#ifdef Q_OS_LINUX
- QVERIFY(diff < 2);
-#else
- QVERIFY(diff < 5);
-#endif
+ QVERIFY(textLeftWidthBegin <= textinputObject->width() / 2);
+ QVERIFY(textLeftWidthEnd >= textinputObject->width() / 2);
x = textinputObject->positionToRectangle(pos + 1).x() - 1;
QCOMPARE(textinputObject->positionAt(x, QQuickTextInput::CursorBetweenCharacters), pos + 1);
textinputObject->setCursorPosition(0);
QInputMethodEvent inputEvent(preeditText, QList<QInputMethodEvent::Attribute>());
- QGuiApplication::sendEvent(&canvas, &inputEvent);
+ QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &inputEvent);
// Check all points within the preedit text return the same position.
QCOMPARE(textinputObject->positionAt(0), 0);