From cdec6d9db487399d960e8f0ae0b8b64bc70ae477 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 16 Jun 2015 14:27:06 +0200 Subject: TextField: sync background resizing with Control Change-Id: Iabf6e88fc929215af6e82fdd1493678b73a65dcd Reviewed-by: J-P Nurmi --- src/controls/qquicktextfield.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/controls/qquicktextfield.cpp b/src/controls/qquicktextfield.cpp index 0d85fa05..8c7cb310 100644 --- a/src/controls/qquicktextfield.cpp +++ b/src/controls/qquicktextfield.cpp @@ -49,11 +49,29 @@ class QQuickTextFieldPrivate public: QQuickTextFieldPrivate() : background(Q_NULLPTR), placeholder(Q_NULLPTR) { } + void resizeBackground(); + QQuickItem *background; QQuickText *placeholder; QQuickTextField *q_ptr; }; +void QQuickTextFieldPrivate::resizeBackground() +{ + Q_Q(QQuickTextField); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid && qFuzzyIsNull(background->x())) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid && qFuzzyIsNull(background->y())) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + QQuickTextField::QQuickTextField(QQuickItem *parent) : QQuickTextInput(parent), d_ptr(new QQuickTextFieldPrivate) { @@ -81,6 +99,8 @@ void QQuickTextField::setBackground(QQuickItem *background) background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } emit backgroundChanged(); } @@ -108,17 +128,7 @@ void QQuickTextField::geometryChanged(const QRectF &newGeometry, const QRectF &o { Q_D(QQuickTextField); QQuickTextInput::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(); } QSGNode *QQuickTextField::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) -- cgit v1.2.3