diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquicklabel.cpp | 31 | ||||
-rw-r--r-- | src/quicktemplates2/qquicklabel_p_p.h | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextarea.cpp | 6 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextfield.cpp | 1 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_label.qml | 24 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_textarea.qml | 3 |
7 files changed, 56 insertions, 13 deletions
diff --git a/.qmake.conf b/.qmake.conf index 4518dc99..95b95e56 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -4,4 +4,4 @@ DEFINES += QT_NO_FOREACH QQC2_SOURCE_TREE = $$PWD -MODULE_VERSION = 5.9.5 +MODULE_VERSION = 5.9.6 diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index c8b125ca..a31f7de0 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -95,6 +95,22 @@ QQuickLabelPrivate::~QQuickLabelPrivate() #endif } +void QQuickLabelPrivate::resizeBackground() +{ + Q_Q(QQuickLabel); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + /*! \internal @@ -232,6 +248,8 @@ void QQuickLabel::setBackground(QQuickItem *background) background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } if (!d->background.isExecuting()) emit backgroundChanged(); @@ -249,6 +267,7 @@ void QQuickLabel::componentComplete() Q_D(QQuickLabel); d->executeBackground(true); QQuickText::componentComplete(); + d->resizeBackground(); #if QT_CONFIG(accessibility) if (!d->accessibleAttached && QAccessible::isActive()) d->accessibilityActiveChanged(true); @@ -267,17 +286,7 @@ void QQuickLabel::geometryChanged(const QRectF &newGeometry, const QRectF &oldGe { Q_D(QQuickLabel); QQuickText::geometryChanged(newGeometry, oldGeometry); - if (d->background) { - QQuickItemPrivate *p = QQuickItemPrivate::get(d->background); - if (!p->widthValid) { - d->background->setWidth(newGeometry.width()); - p->widthValid = false; - } - if (!p->heightValid) { - d->background->setHeight(newGeometry.height()); - p->heightValid = false; - } - } + d->resizeBackground(); } QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquicklabel_p_p.h b/src/quicktemplates2/qquicklabel_p_p.h index f612434b..2e60a96d 100644 --- a/src/quicktemplates2/qquicklabel_p_p.h +++ b/src/quicktemplates2/qquicklabel_p_p.h @@ -75,6 +75,8 @@ public: return static_cast<QQuickLabelPrivate *>(QObjectPrivate::get(item)); } + void resizeBackground(); + void resolveFont(); void inheritFont(const QFont &f); diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 500e7bba..d40ca560 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -483,7 +483,10 @@ void QQuickTextArea::setBackground(QQuickItem *background) delete d->background; d->background = background; if (background) { - background->setParentItem(this); + if (d->flickable) + background->setParentItem(d->flickable); + else + background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); if (isComponentComplete()) @@ -636,6 +639,7 @@ void QQuickTextArea::componentComplete() Q_D(QQuickTextArea); d->executeBackground(true); QQuickTextEdit::componentComplete(); + d->resizeBackground(); #if QT_CONFIG(quicktemplates2_hover) if (!d->explicitHoverEnabled) setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem)); diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index 8ca51ddb..275856f1 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -490,6 +490,7 @@ void QQuickTextField::componentComplete() Q_D(QQuickTextField); d->executeBackground(true); QQuickTextInput::componentComplete(); + d->resizeBackground(); #if QT_CONFIG(quicktemplates2_hover) if (!d->explicitHoverEnabled) setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem)); diff --git a/tests/auto/controls/data/tst_label.qml b/tests/auto/controls/data/tst_label.qml index 5618fe07..69d273a7 100644 --- a/tests/auto/controls/data/tst_label.qml +++ b/tests/auto/controls/data/tst_label.qml @@ -66,6 +66,18 @@ TestCase { } Component { + id: backgroundLabel + Label { + background: Rectangle { } + } + } + + Component { + id: rectangle + Rectangle { } + } + + Component { id: signalSpy SignalSpy { } } @@ -115,4 +127,16 @@ TestCase { compare(child.font[data.tag], defaultValue) compare(childSpy.count, 0) } + + function test_background() { + var control = createTemporaryObject(backgroundLabel, testCase, {text: "Label"}) + verify(control) + + compare(control.background.width, control.width) + compare(control.background.height, control.height) + + control.background = rectangle.createObject(control) + compare(control.background.width, control.width) + compare(control.background.height, control.height) + } } diff --git a/tests/auto/controls/data/tst_textarea.qml b/tests/auto/controls/data/tst_textarea.qml index 7c47aa25..2de82d85 100644 --- a/tests/auto/controls/data/tst_textarea.qml +++ b/tests/auto/controls/data/tst_textarea.qml @@ -212,6 +212,9 @@ TestCase { var textArea = control.TextArea.flickable verify(textArea) + if (textArea.background) + compare(textArea.background.parent, control) + for (var i = 1; i <= 100; ++i) textArea.text += "line\n" + i |