aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktext.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den.exter@qinetic.com.au>2015-04-23 21:29:47 +1000
committerAndrew den Exter <andrew.den.exter@qinetic.com.au>2015-05-04 12:21:26 +0000
commit705c2bf4e5c71e4d31a387ed85e205962a344580 (patch)
tree0b4c692d00bed13b75e302ac84eed468a47c17fb /src/quick/items/qquicktext.cpp
parent682d57c9f6da7940dc68a73d3e23fe4bcf5ac2f0 (diff)
Fix implicitHeight for Text items bindings dependent on implicitWidth.
Recalculate the implicitHeight on the second layout if the width changes after setting the implicitWidth, and potentially do another layout if the updating the implicitHeight changes the height. Change-Id: Ib6a637452013b56dba7ae8a6862cd92156386578 Task-number: QTBUG-45546 Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: Albert Astals Cid <albert.astals@canonical.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/quick/items/qquicktext.cpp')
-rw-r--r--src/quick/items/qquicktext.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index c1794697a5..456ec25edd 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -749,6 +749,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
: largeFont;
int scaledFontSize = largeFont;
+ bool widthChanged = false;
widthExceeded = q->width() <= 0 && (singlelineElide || canWrap || horizontalFit);
heightExceeded = q->height() <= 0 && (multilineElide || verticalFit);
@@ -945,6 +946,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
if ((lineWidth < qMin(oldWidth, naturalWidth) || (widthExceeded && lineWidth > oldWidth))
&& (singlelineElide || multilineElide || canWrap || horizontalFit
|| q->effectiveHAlign() != QQuickText::AlignLeft)) {
+ widthChanged = true;
widthExceeded = false;
heightExceeded = false;
continue;
@@ -966,6 +968,39 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
heightExceeded = false;
continue;
}
+ } else if (widthChanged) {
+ widthChanged = false;
+ if (line.isValid()) {
+ for (int lineCount = layout.lineCount(); lineCount < maxLineCount; ++lineCount) {
+ line = layout.createLine();
+ if (!line.isValid())
+ break;
+ setLineGeometry(line, lineWidth, naturalHeight);
+ }
+ }
+ layout.endLayout();
+
+ bool wasInLayout = internalWidthUpdate;
+ internalWidthUpdate = true;
+ q->setImplicitHeight(naturalHeight);
+ internalWidthUpdate = wasInLayout;
+
+ multilineElide = elideMode == QQuickText::ElideRight
+ && q->widthValid()
+ && (q->heightValid() || maximumLineCountValid);
+ verticalFit = fontSizeMode() & QQuickText::VerticalFit
+ && (q->heightValid() || (maximumLineCountValid && canWrap));
+
+ const qreal oldHeight = maxHeight;
+ maxHeight = q->heightValid() ? q->height() : FLT_MAX;
+ // If the height of the item has changed and it's possible the result of eliding,
+ // line count truncation or scaling has changed, do another layout.
+ if ((maxHeight < qMin(oldHeight, naturalHeight) || (heightExceeded && maxHeight > oldHeight))
+ && (multilineElide || (canWrap && maximumLineCountValid))) {
+ widthExceeded = false;
+ heightExceeded = false;
+ continue;
+ }
} else {
layout.endLayout();
}