diff options
author | Egor Nemtsev <enemtsev@luxoft.com> | 2020-02-19 19:21:52 +0300 |
---|---|---|
committer | Egor Nemtsev <enemtsev@luxoft.com> | 2020-02-25 08:10:40 +0000 |
commit | 3ea701e475c22a13be804ea2a3da4220a39ba188 (patch) | |
tree | d01d137f7853b1f038d1e02dfe817d855ab08517 | |
parent | 0fad0a464f541f9499fe84d887a7b905df20663f (diff) |
[sysui] fix implicitSize for NeptuneIconLabel
- implicitSize should be updated according to scaled size of image
and updated iconRectWidth and iconRectHeight
Task-number: AUTOSUITE-1304
Change-Id: I8d08b0df4f1598f99b192e9cd85408fec722d854
Reviewed-by: Grigorii Zimin <gzimin@luxoft.com>
-rw-r--r-- | plugins/controls/neptuneiconlabel.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/plugins/controls/neptuneiconlabel.cpp b/plugins/controls/neptuneiconlabel.cpp index bf6c6d1a..26c817d3 100644 --- a/plugins/controls/neptuneiconlabel.cpp +++ b/plugins/controls/neptuneiconlabel.cpp @@ -210,21 +210,34 @@ void NeptuneIconLabelPrivate::updateOrSyncLabel() void NeptuneIconLabelPrivate::updateImplicitSize() { Q_Q(NeptuneIconLabel); + const bool showIcon = image && hasIcon(); const bool showText = label && hasText(); const qreal horizontalPadding = leftPadding + rightPadding; const qreal verticalPadding = topPadding + bottomPadding; - const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0; - const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0; + qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0; + qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0; const qreal textImplicitWidth = showText ? label->implicitWidth() : 0; const qreal textImplicitHeight = showText ? label->implicitHeight() : 0; const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0; + + // for Pad we apply scaling to image object, so it will be *iconScale size in result + // implicitWidth of image is equal to 1.0 scaled image + if (iconFillMode == QQuickImage::Pad) { + iconImplicitWidth *= iconScale; + iconImplicitHeight *= iconScale; + } else { + iconImplicitWidth = iconRectWidth; + iconImplicitHeight = iconRectHeight; + } + const qreal implicitWidth = display == NeptuneIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing : qMax(iconImplicitWidth, textImplicitWidth); const qreal implicitHeight = display == NeptuneIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing : qMax(iconImplicitHeight, textImplicitHeight); + q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding); } @@ -294,10 +307,10 @@ void NeptuneIconLabelPrivate::layout() qreal iconHeight{iconRectHeight}; if (image && image->status() == QQuickImageBase::Ready && iconFillMode == QQuickImage::Pad) { - // if Pad mode, use implicit size, which is: iconScale x image pixel size - // implicit size is set after image is loaded or setSourceSize is called - iconWidth = image->implicitWidth(); - iconHeight = image->implicitHeight(); + // if Pad mode, use implicit size * iconScale + // implicit size is set after image is loaded + iconWidth = image->implicitWidth() * iconScale; + iconHeight = image->implicitHeight() * iconScale; } switch (display) { @@ -438,10 +451,8 @@ void NeptuneIconLabelPrivate::applyIconScaleForPadMode() { if (iconFillMode != QQuickImage::Pad) return; - if (qFuzzyCompare(iconScale, image->scale())) - return; - image->setScale(iconScale); + updateImplicitSize(); layout(); } @@ -457,6 +468,7 @@ void NeptuneIconLabelPrivate::applyIconRect() { } image->setFillMode(iconFillMode); + updateImplicitSize(); layout(); } |