From 6e5a642c9484536fc173714f560f739944368cf5 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 21 Apr 2011 14:15:38 +1000 Subject: Elide has unexpected effect on Text's implicitWidth The elided string was used to calculate the implicitWidth rather than the full string. Change-Id: I51b8800b47d4e32f4d5eef07c71df10e2df905b7 Task-number: QTBUG-18627 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativetext.cpp | 23 +++++++++++++++++----- .../graphicsitems/qdeclarativetext_p_p.h | 1 + .../qdeclarativetext/data/elideimplicitwidth.qml | 7 +++++++ .../qdeclarativetext/tst_qdeclarativetext.cpp | 7 +++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativetext/data/elideimplicitwidth.qml diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 720692c..1d51840 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -101,7 +101,8 @@ QDeclarativeTextPrivate::QDeclarativeTextPrivate() format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap), lineHeight(1), lineHeightMode(QDeclarativeText::ProportionalHeight), lineCount(1), truncated(false), maximumLineCount(INT_MAX), maximumLineCountValid(false), imageCacheDirty(true), updateOnComponentComplete(true), richText(false), singleline(false), - cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true), rightToLeftText(false), naturalWidth(0), doc(0) + cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true), + rightToLeftText(false), layoutTextElided(false), naturalWidth(0), doc(0) { cacheAllTextAsImage = enableImageCache(); QGraphicsItemPrivate::acceptedMouseButtons = Qt::LeftButton; @@ -217,6 +218,7 @@ void QDeclarativeTextPrivate::updateLayout() return; } + layoutTextElided = false; // Setup instance of QTextLayout for all cases other than richtext if (!richText) { layout.clearLayout(); @@ -227,10 +229,13 @@ void QDeclarativeTextPrivate::updateLayout() singleline = !tmp.contains(QChar::LineSeparator); if (singleline && !maximumLineCountValid && elideMode != QDeclarativeText::ElideNone && q->widthValid()) { QFontMetrics fm(font); - tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? - if (tmp != text && !truncated) { - truncated = true; - emit q->truncatedChanged(); + tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); + if (tmp != text) { + layoutTextElided = true; + if (!truncated) { + truncated = true; + emit q->truncatedChanged(); + } } } layout.setText(tmp); @@ -377,6 +382,12 @@ QRect QDeclarativeTextPrivate::setupTextLayout() if (requireImplicitWidth && q->widthValid()) { // requires an extra layout + QString elidedText; + if (layoutTextElided) { + // We have provided elided text to the layout, but we must calculate unelided width. + elidedText = layout.text(); + layout.setText(text); + } layout.beginLayout(); forever { QTextLine line = layout.createLine(); @@ -390,6 +401,8 @@ QRect QDeclarativeTextPrivate::setupTextLayout() br = br.united(line.naturalTextRect()); } naturalWidth = br.width(); + if (layoutTextElided) + layout.setText(elidedText); } if (maximumLineCountValid) { diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h index e3ab62a..6a3d581 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h @@ -116,6 +116,7 @@ public: bool requireImplicitWidth:1; bool hAlignImplicit:1; bool rightToLeftText:1; + bool layoutTextElided:1; QRect layedOutTextRect; QSize paintedSize; diff --git a/tests/auto/declarative/qdeclarativetext/data/elideimplicitwidth.qml b/tests/auto/declarative/qdeclarativetext/data/elideimplicitwidth.qml new file mode 100644 index 0000000..60ae15c --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/elideimplicitwidth.qml @@ -0,0 +1,7 @@ +import QtQuick 1.1 + +Text { + text: "Hello World" + elide: Text.ElideRight + width: 30 +} diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index ca6e87a..82b6f73 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -390,6 +390,13 @@ void tst_qdeclarativetext::elide() QCOMPARE(textObject->width(), 100.); } } + + // QTBUG-18627 + QUrl qmlfile = QUrl::fromLocalFile(SRCDIR "/data/elideimplicitwidth.qml"); + QDeclarativeComponent textComponent(&engine, qmlfile); + QDeclarativeItem *item = qobject_cast(textComponent.create()); + QVERIFY(item != 0); + QVERIFY(item->implicitWidth() > item->width()); } void tst_qdeclarativetext::textFormat() -- cgit v0.12 From 2f173e4945dd8414636c1061acfaf9c2d8b718d8 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 19 Apr 2011 14:00:48 +1000 Subject: Fix TextInput echoMode clearing inputMethodHints set by the user. Changing to the Normal echo mode from another mode clears the NoPredictiveText and NoAutoUppercase flags, irrespective of who originally set them. Add separate accessors for the property value so echo mode can overwrite the authoritive value without losing the value set in QML. Change-Id: I6a9563057bb17796b17ac7c2a3c564bb5e886c4d Task-number: QTBUG-18735 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativetextinput.cpp | 40 +++++++++++++++------ .../graphicsitems/qdeclarativetextinput_p.h | 5 ++- .../graphicsitems/qdeclarativetextinput_p_p.h | 4 ++- .../tst_qdeclarativetextinput.cpp | 42 +++++++++++++++++++++- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index e1c2107..ee241d6 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -862,6 +862,20 @@ bool QDeclarativeTextInput::hasAcceptableInput() const state. */ +void QDeclarativeTextInputPrivate::updateInputMethodHints() +{ + Q_Q(QDeclarativeTextInput); + Qt::InputMethodHints hints = inputMethodHints; + uint echo = control->echoMode(); + if (echo == QDeclarativeTextInput::Password || echo == QDeclarativeTextInput::NoEcho) + hints |= Qt::ImhHiddenText; + else if (echo == QDeclarativeTextInput::PasswordEchoOnEdit) + hints &= ~Qt::ImhHiddenText; + if (echo != QDeclarativeTextInput::Normal) + hints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + q->setInputMethodHints(hints); +} + /*! \qmlproperty enumeration TextInput::echoMode @@ -884,21 +898,27 @@ void QDeclarativeTextInput::setEchoMode(QDeclarativeTextInput::EchoMode echo) Q_D(QDeclarativeTextInput); if (echoMode() == echo) return; - Qt::InputMethodHints imHints = inputMethodHints(); - if (echo == Password || echo == NoEcho) - imHints |= Qt::ImhHiddenText; - else - imHints &= ~Qt::ImhHiddenText; - if (echo != Normal) - imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); - else - imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); - setInputMethodHints(imHints); d->control->setEchoMode((uint)echo); + d->updateInputMethodHints(); q_textChanged(); emit echoModeChanged(echoMode()); } +Qt::InputMethodHints QDeclarativeTextInput::imHints() const +{ + Q_D(const QDeclarativeTextInput); + return d->inputMethodHints; +} + +void QDeclarativeTextInput::setIMHints(Qt::InputMethodHints hints) +{ + Q_D(QDeclarativeTextInput); + if (d->inputMethodHints == hints) + return; + d->inputMethodHints = hints; + d->updateInputMethodHints(); +} + /*! \qmlproperty Component TextInput::cursorDelegate The delegate for the cursor in the TextInput. diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index 8c873b3..ec70e43 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -86,7 +86,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativeImplicitSizeP Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged) #endif Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged) - Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) + Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged) @@ -215,6 +215,9 @@ public: bool isInputMethodComposing() const; + Qt::InputMethodHints imHints() const; + void setIMHints(Qt::InputMethodHints hints); + Q_SIGNALS: void textChanged(); void cursorPositionChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h index fd4da2e..ed53e8f 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h @@ -73,7 +73,7 @@ public: QDeclarativeTextInputPrivate() : control(new QLineControl(QString())), color((QRgb)0), style(QDeclarativeText::Normal), styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft), - mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), + mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), inputMethodHints(Qt::ImhNone), hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true), showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false), autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true) @@ -108,6 +108,7 @@ public: void mirrorChange(); int calculateTextWidth(); bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType); + void updateInputMethodHints(); QLineControl* control; @@ -120,6 +121,7 @@ public: QColor styleColor; QDeclarativeTextInput::HAlignment hAlign; QDeclarativeTextInput::SelectionMode mouseSelectionMode; + Qt::InputMethodHints inputMethodHints; QPointer cursorComponent; QPointer cursorItem; QPointF pressPos; diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 943b1fa..79d95d3 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1364,8 +1364,10 @@ void tst_qdeclarativetextinput::inputMethods() QVERIFY(canvas->rootObject() != 0); QDeclarativeTextInput *input = qobject_cast(canvas->rootObject()); QVERIFY(input != 0); + QVERIFY(input->imHints() & Qt::ImhNoPredictiveText); QVERIFY(input->inputMethodHints() & Qt::ImhNoPredictiveText); - input->setInputMethodHints(Qt::ImhUppercaseOnly); + input->setIMHints(Qt::ImhUppercaseOnly); + QVERIFY(input->imHints() & Qt::ImhUppercaseOnly); QVERIFY(input->inputMethodHints() & Qt::ImhUppercaseOnly); QVERIFY(canvas->rootObject() != 0); @@ -1805,6 +1807,7 @@ void tst_qdeclarativetextinput::echoMode() ref &= ~Qt::ImhHiddenText; ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhNone); input->setEchoMode(QDeclarativeTextInput::NoEcho); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("")); @@ -1813,6 +1816,7 @@ void tst_qdeclarativetextinput::echoMode() ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhNone); input->setEchoMode(QDeclarativeTextInput::Password); //Password ref |= Qt::ImhHiddenText; @@ -1820,6 +1824,7 @@ void tst_qdeclarativetextinput::echoMode() QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("********")); QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhNone); input->setPasswordCharacter(QChar('Q')); QCOMPARE(input->passwordCharacter(), QLatin1String("Q")); QCOMPARE(input->text(), initial); @@ -1829,6 +1834,7 @@ void tst_qdeclarativetextinput::echoMode() ref &= ~Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhNone); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ")); QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("QQQQQQQQ")); @@ -1849,6 +1855,40 @@ void tst_qdeclarativetextinput::echoMode() QCOMPARE(input->displayText(), initial); QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), initial); + // Test echo mode doesn't override imHints. + input->setIMHints(Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly); + ref |= Qt::ImhDialableCharactersOnly; + //Normal + input->setEchoMode(QDeclarativeTextInput::Normal); + ref |= Qt::ImhHiddenText; + ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly); + //NoEcho + input->setEchoMode(QDeclarativeTextInput::NoEcho); + ref |= Qt::ImhHiddenText; + ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly); + //Password + input->setEchoMode(QDeclarativeTextInput::Password); + ref |= Qt::ImhHiddenText; + ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly); + //PasswordEchoOnEdit + input->setEchoMode(QDeclarativeTextInput::PasswordEchoOnEdit); + ref &= ~Qt::ImhHiddenText; + ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly); + //Normal + input->setEchoMode(QDeclarativeTextInput::Normal); + ref |= Qt::ImhHiddenText; + ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + QCOMPARE(input->inputMethodHints(), ref); + QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly); + delete canvas; } -- cgit v0.12 From 60198a071dd76e57ab799215f0fbddc8d550ba30 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 19 Apr 2011 15:11:36 +1000 Subject: Fix TextInput cursor position unchanged when selection length is 0. Move the cursor position to the start position when both the new and old selections are empty as would happen if either was non-empty. Change-Id: I493e52c551b47e009fd13b3e95856ff012ee5d95 Task-number: QTBUG-18768 Reviewed-by: Martin Jones --- src/gui/widgets/qlinecontrol.cpp | 10 +++++++++- .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 10 ++++++++++ .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 9 +++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index d03e5de..202ea7a 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -254,12 +254,20 @@ void QLineControl::setSelection(int start, int length) m_selstart = start; m_selend = qMin(start + length, (int)m_text.length()); m_cursor = m_selend; - } else { + } else if (length < 0){ if (start == m_selend && start + length == m_selstart) return; m_selstart = qMax(start + length, 0); m_selend = start; m_cursor = m_selstart; + } else if (m_selstart != m_selend) { + m_selstart = 0; + m_selend = 0; + m_cursor = start; + } else { + m_cursor = start; + emitCursorPositionChanged(); + return; } emit selectionChanged(); emitCursorPositionChanged(); diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 574d2d5..26a6fd8 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -788,6 +788,14 @@ void tst_qdeclarativetextedit::selection() QCOMPARE(textEditObject->selectionEnd(), i); QVERIFY(textEditObject->selectedText().isNull()); } + //Test cursor follows selection + for(int i=0; i<= testStr.size(); i++) { + textEditObject->select(i,i); + QCOMPARE(textEditObject->cursorPosition(), i); + QCOMPARE(textEditObject->selectionStart(), i); + QCOMPARE(textEditObject->selectionEnd(), i); + } + textEditObject->setCursorPosition(0); QVERIFY(textEditObject->cursorPosition() == 0); @@ -812,10 +820,12 @@ void tst_qdeclarativetextedit::selection() for(int i=0; i<= testStr.size(); i++) { textEditObject->select(0,i); QCOMPARE(testStr.mid(0,i), textEditObject->selectedText()); + QCOMPARE(textEditObject->cursorPosition(), i); } for(int i=0; i<= testStr.size(); i++) { textEditObject->select(i,testStr.size()); QCOMPARE(testStr.mid(i,testStr.size()-i), textEditObject->selectedText()); + QCOMPARE(textEditObject->cursorPosition(), testStr.size()); } textEditObject->setCursorPosition(0); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 79d95d3..baaf862 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -375,6 +375,13 @@ void tst_qdeclarativetextinput::selection() QCOMPARE(textinputObject->selectionEnd(), i); QVERIFY(textinputObject->selectedText().isNull()); } + //Test cursor follows selection + for(int i=0; i<= testStr.size(); i++) { + textinputObject->select(i,i); + QCOMPARE(textinputObject->cursorPosition(), i); + QCOMPARE(textinputObject->selectionStart(), i); + QCOMPARE(textinputObject->selectionEnd(), i); + } textinputObject->setCursorPosition(0); QVERIFY(textinputObject->cursorPosition() == 0); @@ -399,10 +406,12 @@ void tst_qdeclarativetextinput::selection() for(int i=0; i<= testStr.size(); i++) { textinputObject->select(0,i); QCOMPARE(testStr.mid(0,i), textinputObject->selectedText()); + QCOMPARE(textinputObject->cursorPosition(), i); } for(int i=0; i<= testStr.size(); i++) { textinputObject->select(i,testStr.size()); QCOMPARE(testStr.mid(i,testStr.size()-i), textinputObject->selectedText()); + QCOMPARE(textinputObject->cursorPosition(), testStr.size()); } textinputObject->setCursorPosition(0); -- cgit v0.12 From f14ac31c86eeb53d0b08c799ad0ad895d17475d6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 21 Apr 2011 16:17:46 +1000 Subject: Document section behavior when not ordered by section Change-Id: Id0345d477c253a5dd54306b06dae1df971ec76fc Task-number: QTBUG-17757 Reviewed-by: Bea Lam --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 7c01293..2e9822e 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2302,11 +2302,19 @@ void QDeclarativeListView::setCacheBuffer(int b) depending on the "size" property of the model item. The \c sectionHeading delegate component provides the light blue bar that marks the beginning of each section. + \snippet examples/declarative/modelviews/listview/sections.qml 0 \image qml-listview-sections-example.png + \note Adding sections to a ListView does not automatically re-order the + list items by the section criteria. + If the model is not ordered by section, then it is possible that + the sections created will not be unique; each boundary between + differing sections will result in a section header being created + even if that section exists elsewhere. + \sa {declarative/modelviews/listview}{ListView examples} */ QDeclarativeViewSection *QDeclarativeListView::sectionCriteria() -- cgit v0.12