From 02de9d7b6c851d7021dbb901d97c3f91209b1ea9 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 14 Oct 2014 10:44:47 +0200 Subject: text input: always let cursor rect have a width == 1 Instead of using a cursor width of null when a cursor delegate is set, we should to use a value of 1. Otherwise the rect we e.g return from cursorRect() will be invalid. An alternative would be to use the width of the delegate, but that was found to be controversial. On iOS we saw a bug with this when telling iOS to position text spelling popups underneath the cursor. Since the cursor rect we got was invalid (zero-width), no popup would show. Change-Id: Ice51b9a1bd33f331183e3acec61b7d9c0f5163cd Reviewed-by: Andrew den Exter --- src/quick/items/qquicktextcontrol.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'src/quick/items/qquicktextcontrol.cpp') diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index 2585caefb5..0ad21ccff3 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -965,7 +965,6 @@ QRectF QQuickTextControlPrivate::rectForPosition(int position) const const QTextBlock block = doc->findBlock(position); if (!block.isValid()) return QRectF(); - const QAbstractTextDocumentLayout *docLayout = doc->documentLayout(); const QTextLayout *layout = block.layout(); const QPointF layoutPos = q->blockBoundingRect(block).topLeft(); int relativePos = position - block.position(); @@ -980,24 +979,14 @@ QRectF QQuickTextControlPrivate::rectForPosition(int position) const #endif QTextLine line = layout->lineForTextPosition(relativePos); - int cursorWidth; - { - bool ok = false; -#ifndef QT_NO_PROPERTIES - cursorWidth = docLayout->property("cursorWidth").toInt(&ok); -#endif - if (!ok) - cursorWidth = 1; - } - QRectF r; if (line.isValid()) { qreal x = line.cursorToX(relativePos); qreal w = 0; - r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(), cursorWidth + w, line.height()); + r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(), textCursorWidth + w, line.height()); } else { - r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height + r = QRectF(layoutPos.x(), layoutPos.y(), textCursorWidth, 10); // #### correct height } return r; @@ -1510,19 +1499,6 @@ QString QQuickTextControl::anchorAt(const QPointF &pos) const return d->doc->documentLayout()->anchorAt(pos); } -void QQuickTextControl::setCursorWidth(int width) -{ - Q_D(QQuickTextControl); -#ifdef QT_NO_PROPERTIES - Q_UNUSED(width); -#else - if (width == -1) - width = textCursorWidth; - d->doc->documentLayout()->setProperty("cursorWidth", width); -#endif - d->repaintCursor(); -} - void QQuickTextControl::setAcceptRichText(bool accept) { Q_D(QQuickTextControl); -- cgit v1.2.3