Skip to content

Commit

Permalink
Fix Text eliding with implicit height and maximumLineCount.
Browse files Browse the repository at this point in the history
Ignore the height of the text if the element height is invalid.

Task-number: QTBUG-24293
Change-Id: I1646c3f64583da40e6166aeea24c2c4af42cb279
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Feb 23, 2012
1 parent c5f65d8 commit 924a962
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/quick/items/qquicktext.cpp
Expand Up @@ -666,6 +666,7 @@ QRect QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
}

const int lineWidth = q->widthValid() ? q->width() : INT_MAX;
const qreal maxHeight = q->heightValid() ? q->height() : FLT_MAX;
const bool customLayout = isLineLaidOutConnected();
const bool wasTruncated = truncated;

Expand Down Expand Up @@ -715,6 +716,7 @@ QRect QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
}
layout.beginLayout();


bool wrapped = false;
bool truncateHeight = false;
truncated = false;
Expand All @@ -735,7 +737,7 @@ QRect QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)

// Elide the previous line if the accumulated height of the text exceeds the height
// of the element.
if (multilineElide && height > q->height() && visibleCount > 1) {
if (multilineElide && height > maxHeight && visibleCount > 1) {
elide = true;
if (eos != -1) // There's an abbreviated string available, skip the rest as it's
break; // all going to be discarded.
Expand Down Expand Up @@ -873,7 +875,7 @@ QRect QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
}

if (verticalFit) {
if (truncateHeight || (q->heightValid() && unelidedRect.height() > q->height())) {
if (truncateHeight || unelidedRect.height() > maxHeight) {
largeFont = scaledFontSize - 1;
scaledFontSize = (smallFont + largeFont + 1) / 2;
if (smallFont > largeFont)
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/qtquick2/qquicktext/data/multilineelide.qml
@@ -1,7 +1,7 @@
import QtQuick 2.0

Text {
width: 200; height: 200
width: 200
wrapMode: Text.WordWrap
elide: Text.ElideRight
maximumLineCount: 3
Expand Down
6 changes: 6 additions & 0 deletions tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
Expand Up @@ -471,6 +471,12 @@ void tst_qquicktext::multilineElide()

qreal lineHeight = myText->contentHeight() / 3.;

// Set a valid height greater than the truncated content height and ensure the line count is
// unchanged.
myText->setHeight(200);
QCOMPARE(myText->lineCount(), 3);
QCOMPARE(myText->truncated(), true);

// reduce size and ensure fewer lines are drawn
myText->setHeight(lineHeight * 2);
QCOMPARE(myText->lineCount(), 2);
Expand Down

0 comments on commit 924a962

Please sign in to comment.