Q_Q(QQuickTextInput);
QTextLine currentLine = m_textLayout.lineForTextPosition(m_cursor + m_preeditCursor);
const int preeditLength = m_textLayout.preeditAreaText().length();
- const int width = q->width();
+ const int width = qMax(0, qFloor(q->width()));
int widthUsed = currentLine.isValid() ? qRound(currentLine.naturalTextWidth()) : 0;
int previousScroll = hscroll;
if (!autoScroll || widthUsed <= width || m_echoMode == QQuickTextInput::NoEcho) {
hscroll = 0;
} else {
+ Q_ASSERT(currentLine.isValid());
int cix = qRound(currentLine.cursorToX(m_cursor + preeditLength));
if (cix - hscroll >= width) {
// text doesn't fit, cursor is to the right of br (scroll right)
{
Q_Q(QQuickTextInput);
const int preeditLength = m_textLayout.preeditAreaText().length();
- const int height = q->height();
+ const int height = qMax(0, qFloor(q->height()));
int heightUsed = boundingRect.height();
int previousScroll = vscroll;
break;
}
} else {
- QRectF r = m_textLayout.lineForTextPosition(m_cursor + preeditLength).rect();
+ QTextLine currentLine = m_textLayout.lineForTextPosition(m_cursor + preeditLength);
+ QRectF r = currentLine.isValid() ? currentLine.rect() : QRectF();
int top = qFloor(r.top());
int bottom = qCeil(r.bottom());
if (preeditLength > 0) {
// check to ensure long pre-edit text doesn't push the cursor
// off the top
- top = qRound(m_textLayout.lineForTextPosition(
- m_cursor + qMax(0, m_preeditCursor - 1)).rect().top());
- if (top < vscroll)
- vscroll = top;
+ currentLine = m_textLayout.lineForTextPosition(m_cursor + qMax(0, m_preeditCursor - 1));
+ top = currentLine.isValid() ? qRound(currentLine.rect().top()) : 0;
+ if (top < vscroll)
+ vscroll = top;
}
}
if (previousScroll != vscroll)
void QTBUG_19956_data();
void QTBUG_19956_regexp();
+ void negativeDimensions();
+
private:
void simulateKey(QQuickView *, int key);
QVERIFY(canvas.rootObject()->property("acceptableInput").toBool());
}
+
+void tst_qquicktextinput::negativeDimensions()
+{
+ // Verify this doesn't assert during initialization.
+ QDeclarativeComponent component(&engine, testFileUrl("negativeDimensions.qml"));
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(o);
+ QQuickTextInput *input = o->findChild<QQuickTextInput *>("input");
+ QVERIFY(input);
+ QCOMPARE(input->width(), qreal(-1));
+ QCOMPARE(input->height(), qreal(-1));
+}
+
QTEST_MAIN(tst_qquicktextinput)
#include "tst_qquicktextinput.moc"