QQuickText: Signal content height/width changes also when resetting
If we change the content height or content width to the initial one, we still need to signal the change. Fixes: QTBUG-71684 Change-Id: Idf6e3f89423eab3d8f5310c164c5acc5108e0d8b Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
parent
9a7c5a925c
commit
63ada5fa00
|
@ -343,6 +343,19 @@ void QQuickTextPrivate::updateBaseline(qreal baseline, qreal dy)
|
|||
q->setBaselineOffset(baseline + yoff + q->topPadding());
|
||||
}
|
||||
|
||||
void QQuickTextPrivate::signalSizeChange(const QSizeF &previousSize)
|
||||
{
|
||||
Q_Q(QQuickText);
|
||||
|
||||
if (layedOutTextRect.size() != previousSize) {
|
||||
emit q->contentSizeChanged();
|
||||
if (layedOutTextRect.width() != previousSize.width())
|
||||
emit q->contentWidthChanged(layedOutTextRect.width());
|
||||
if (layedOutTextRect.height() != previousSize.height())
|
||||
emit q->contentHeightChanged(layedOutTextRect.height());
|
||||
}
|
||||
}
|
||||
|
||||
void QQuickTextPrivate::updateSize()
|
||||
{
|
||||
Q_Q(QQuickText);
|
||||
|
@ -363,6 +376,8 @@ void QQuickTextPrivate::updateSize()
|
|||
qreal hPadding = q->leftPadding() + q->rightPadding();
|
||||
qreal vPadding = q->topPadding() + q->bottomPadding();
|
||||
|
||||
const QSizeF previousSize = layedOutTextRect.size();
|
||||
|
||||
if (text.isEmpty() && !isLineLaidOutConnected() && fontSizeMode() == QQuickText::FixedSize) {
|
||||
// How much more expensive is it to just do a full layout on an empty string here?
|
||||
// There may be subtle differences in the height and baseline calculations between
|
||||
|
@ -379,14 +394,13 @@ void QQuickTextPrivate::updateSize()
|
|||
q->setImplicitSize(hPadding, fontHeight + vPadding);
|
||||
layedOutTextRect = QRectF(0, 0, 0, fontHeight);
|
||||
advance = QSizeF();
|
||||
emit q->contentSizeChanged();
|
||||
signalSizeChange(previousSize);
|
||||
updateType = UpdatePaintNode;
|
||||
q->update();
|
||||
return;
|
||||
}
|
||||
|
||||
QSizeF size(0, 0);
|
||||
QSizeF previousSize = layedOutTextRect.size();
|
||||
|
||||
//setup instance of QTextLayout for all cases other than richtext
|
||||
if (!richText) {
|
||||
|
@ -483,13 +497,7 @@ void QQuickTextPrivate::updateSize()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (layedOutTextRect.size() != previousSize)
|
||||
emit q->contentSizeChanged();
|
||||
if (layedOutTextRect.width() != previousSize.width())
|
||||
emit q->contentWidthChanged(layedOutTextRect.width());
|
||||
if (layedOutTextRect.height() != previousSize.height())
|
||||
emit q->contentHeightChanged(layedOutTextRect.height());
|
||||
signalSizeChange(previousSize);
|
||||
updateType = UpdatePaintNode;
|
||||
q->update();
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
|
||||
void updateBaseline(qreal baseline, qreal dy);
|
||||
void updateSize();
|
||||
void signalSizeChange(const QSizeF &previousSize);
|
||||
void updateLayout();
|
||||
bool determineHorizontalAlignment();
|
||||
bool setHAlign(QQuickText::HAlignment, bool forceAlign = false);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import QtQuick 2.9
|
||||
|
||||
Text{
|
||||
width: 200
|
||||
height: contentHeight
|
||||
text: ''
|
||||
}
|
|
@ -159,6 +159,8 @@ private slots:
|
|||
|
||||
void fontInfo();
|
||||
|
||||
void initialContentHeight();
|
||||
|
||||
private:
|
||||
QStringList standard;
|
||||
QStringList richText;
|
||||
|
@ -4383,6 +4385,18 @@ void tst_qquicktext::fontInfo()
|
|||
QVERIFY(copy->font().pixelSize() < 1000);
|
||||
}
|
||||
|
||||
void tst_qquicktext::initialContentHeight()
|
||||
{
|
||||
QQmlComponent component(&engine, testFile("contentHeight.qml"));
|
||||
QVERIFY(component.isReady());
|
||||
QScopedPointer<QObject> object(component.create());
|
||||
QObject *root = object.data();
|
||||
QVERIFY(root);
|
||||
QQuickText *text = qobject_cast<QQuickText *>(root);
|
||||
QVERIFY(text);
|
||||
QCOMPARE(text->height(), text->contentHeight());
|
||||
}
|
||||
|
||||
void tst_qquicktext::implicitSizeChangeRewrap()
|
||||
{
|
||||
QScopedPointer<QQuickView> window(new QQuickView);
|
||||
|
|
Loading…
Reference in New Issue