diff options
author | Egor Nemtsev <enemtsev@luxoft.com> | 2020-01-31 20:02:13 +0300 |
---|---|---|
committer | Egor Nemtsev <enemtsev@luxoft.com> | 2020-02-19 10:39:40 +0000 |
commit | 5a5d1c12a2f123c0c6c5782d42a1d079fe1adb75 (patch) | |
tree | 7b286ce9d53fc1edddbec0851074a16e3afafa3c /plugins | |
parent | 4ea370f96765562e8eba888be081270c1c8941dd (diff) |
[sysui] Fix NeptuneIconLabel to scale correctly on Desktop
- IconLabel doesn't report pixel size of image. On Mac dpi switching is not
handled well. To handle issue with wrong icon scaling we:
1. Connect to status change signal to call layout() and update composite item
2. Apply scaling via inner image item scale for non-Pad fill mode
Above applies to situation when we just render scaled image, then size of
rendered image is equal to
image_pixel_width * scale X image_pixel_height * scale. For situation
when we want to have icon of particular size, iconRectWidth, iconRectHeight
and iconFillMode properties are introduced.
Some images are expanded by 1 pixel to handle scaling more nicely
Task-number: AUTOSUITE-1304
Change-Id: Ia08c073944eb8ec55309c4aabaf54e7d3961a56f
Reviewed-by: Grigorii Zimin <gzimin@luxoft.com>
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/controls/ListItemBasic.qml | 5 | ||||
-rw-r--r-- | plugins/controls/ToolsColumn.qml | 34 | ||||
-rw-r--r-- | plugins/controls/neptuneiconlabel.cpp | 283 | ||||
-rw-r--r-- | plugins/controls/neptuneiconlabel.h | 23 | ||||
-rw-r--r-- | plugins/controls/neptuneiconlabel_p.h | 10 |
5 files changed, 297 insertions, 58 deletions
diff --git a/plugins/controls/ListItemBasic.qml b/plugins/controls/ListItemBasic.qml index 6f2287e1..3ea7538b 100644 --- a/plugins/controls/ListItemBasic.qml +++ b/plugins/controls/ListItemBasic.qml @@ -40,6 +40,7 @@ import QtGraphicalEffects 1.0 import shared.utils 1.0 import shared.Style 1.0 import shared.Sizes 1.0 +import shared.controls 1.0 /*! \qmltype ListItemBasic @@ -172,9 +173,9 @@ ItemDelegate { Layout.fillHeight: true implicitWidth: root.implicitHeight visible: root.icon.source.toString() !== "" || root.icon.name !== "" - IconLabel { + NeptuneIconLabel { opacity: Style.opacityHigh - scale: Sizes.scale + iconScale: Sizes.scale spacing: root.spacing mirrored: root.mirrored display: root.display diff --git a/plugins/controls/ToolsColumn.qml b/plugins/controls/ToolsColumn.qml index 478b267a..b06bc15b 100644 --- a/plugins/controls/ToolsColumn.qml +++ b/plugins/controls/ToolsColumn.qml @@ -108,6 +108,32 @@ ColumnLayout { spacing: Sizes.dp(24) /*! + \qmlproperty enumeration ToolsColumn::iconFillMode + + Set this property to define what happens when the item's icon image has a different size + than the item. Please refer to \l{Image::fillMode} for possible values. + For values other than Image.Pad \l{ToolsColumn::iconRectWidth} and + \l {ToolsColumn::iconRectHeight} should be defined. + */ + property int iconFillMode: Image.Pad + + /*! + \qmlpropery real ToolsColumn::iconRectWidth + + Set this property to define width of rectangle area for icon when + \l{ToolsColumn::iconfillMode} has other value than Image.Pad. + */ + property real iconRectWidth: 0 + + /*! + \qmlpropery real ToolsColumn::iconRectHeight + + Set this property to define height of rectangle area for icon when + \l{ToolsColumn::iconfillMode} has other value than Image.Pad. + */ + property real iconRectHeight: 0 + + /*! \qmlproperty int ToolsColumn::currentIndex This property holds the current selected index of the tools column. @@ -122,8 +148,9 @@ ColumnLayout { This property holds the current selected text of the tools column. */ - readonly property string currentText: model ? model.get(currentIndex).text : "" - + readonly property string currentText: model && model.count > currentIndex + ? model.get(currentIndex).text + : "" /*! \qmlproperty string ToolsColumn::currentItem @@ -166,6 +193,9 @@ ColumnLayout { Layout.alignment: Qt.AlignHCenter objectName: model.objectName ? model.objectName : "" baselineOffset: 0 + iconFillMode: root.iconFillMode + iconRectWidth: root.iconRectWidth + iconRectHeight: root.iconRectHeight checkable: true checked: root.currentIndex === index icon.name: model.icon ? (checked ? model.icon + "_ON" : model.icon + "_OFF") : "" diff --git a/plugins/controls/neptuneiconlabel.cpp b/plugins/controls/neptuneiconlabel.cpp index 26d3f002..bf6c6d1a 100644 --- a/plugins/controls/neptuneiconlabel.cpp +++ b/plugins/controls/neptuneiconlabel.cpp @@ -31,12 +31,13 @@ #include "neptuneiconlabel.h" #include "neptuneiconlabel_p.h" -#include <QtQuickControls2/private/qquickiconimage_p.h> // #include "qquickiconimage_p.h" -#include <QtQuickControls2/private/qquickmnemoniclabel_p.h> // #include "qquickmnemoniclabel_p.h" +#include <QtQuickControls2/private/qquickiconimage_p.h> +#include <QtQuickControls2/private/qquickmnemoniclabel_p.h> #include <QtGui/private/qguiapplication_p.h> #include <QtQuick/private/qquickitem_p.h> #include <QtQuick/private/qquicktext_p.h> +#include <QtQml> #include <QFileSelector> @@ -85,13 +86,14 @@ bool NeptuneIconLabelPrivate::createImage() return false; image = new QQuickIconImage(q); + QObject::connect(image, &QQuickIconImage::statusChanged, + q, &NeptuneIconLabel::onImageStatusChanged); watchChanges(image); beginClass(image); image->setObjectName(QStringLiteral("image")); image->setName(icon.name()); QFileSelector selector; image->setSource(selector.select(icon.source())); - image->setSourceSize(QSize(icon.width(), icon.height())); image->setColor(icon.color()); QQmlEngine::setContextForObject(image, qmlContext(q)); if (componentComplete) @@ -125,7 +127,6 @@ void NeptuneIconLabelPrivate::syncImage() image->setName(icon.name()); QFileSelector selector; image->setSource(selector.select(icon.source())); - image->setSourceSize(QSize(icon.width(), icon.height())); image->setColor(icon.color()); const int valign = alignment & Qt::AlignVertical_Mask; image->setVerticalAlignment(static_cast<QQuickImage::VAlignment>(valign)); @@ -218,17 +219,21 @@ void NeptuneIconLabelPrivate::updateImplicitSize() const qreal textImplicitWidth = showText ? label->implicitWidth() : 0; const qreal textImplicitHeight = showText ? label->implicitHeight() : 0; const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0; - const qreal implicitWidth = display == NeptuneIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing - : qMax(iconImplicitWidth, textImplicitWidth); - const qreal implicitHeight = display == NeptuneIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing - : qMax(iconImplicitHeight, textImplicitHeight); + 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); } // adapted from QStyle::alignedRect() -static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle) +static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, + const QRectF &rectangle) { - alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft : Qt::LeftToRight, alignment); + alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft + : Qt::LeftToRight, alignment); qreal x = rectangle.x(); qreal y = rectangle.y(); const qreal w = size.width(); @@ -244,31 +249,74 @@ static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF & return QRectF(x, y, w, h); } +void NeptuneIconLabelPrivate::applyIconSizeAndPosition(const QRectF &iconRect) { + Q_ASSERT(image); + + // if we are using scaled image we have first to upscale and shift image item + // according to iconScale (image.scale()), so when item is actually scaled, it will + // be the iconRect size at iconRect.topLeft position + // Do nothing in case of zero scale or 1.0 scale, just apply calculated iconRect + if (image->scale() > 0 && !qFuzzyCompare(image->scale(), 1.0)) { + image->setSize(iconRect.size() / image->scale()); + const QPointF shift{(image->size().width() - iconRect.size().width()) * 0.5, + (image->size().height() - iconRect.size().height()) * 0.5}; + image->setPosition(iconRect.topLeft() - shift); + } else { + // To avoid aliasing, apply only integer values for position + // and size. Only valid for non-Pad mode + image->setSize(iconRect.size().toSize()); + image->setPosition(iconRect.topLeft().toPoint()); + } +} + void NeptuneIconLabelPrivate::layout() { + // layout() is called to arrange image and text elements inside NeptuneIconLabel item + // + // We have: + // 1. available area to fit + // 2. pre-defined icon rect size for image of iconRectWidth x iconRectHeight + // 3. fillMode + // If fill mode is not Pad, then we are trying to fit image inside pre-defined icon rect + // If pre-defined icon rect doesn't fit available size, min size is selected for resulting image + // rect + // If Pad mode is set, image is displayed according to defined iconScale multiplied by + // (source image pixel size). With Pad set image will be sliced by NeptuneIconLabel item borders + if (!componentComplete) return; const qreal availableWidth = width - leftPadding - rightPadding; const qreal availableHeight = height - topPadding - bottomPadding; + // these sizes later compared to available item size, minimum is selected + qreal iconWidth{iconRectWidth}; + 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(); + } + switch (display) { case NeptuneIconLabel::IconOnly: - if (image) { + if (image && image->status() == QQuickImageBase::Ready) { + // Align rect for image according to available space const QRectF iconRect = alignedRect(mirrored, alignment, - QSizeF(qMin(image->implicitWidth() * iconScale, availableWidth), - qMin(image->implicitHeight() * iconScale, availableHeight)), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); + QSizeF(qMin(iconWidth, availableWidth), + qMin(iconHeight, availableHeight)), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + applyIconSizeAndPosition(iconRect); } break; case NeptuneIconLabel::TextOnly: if (label) { const QRectF textRect = alignedRect(mirrored, alignment, - QSizeF(qMin(label->implicitWidth(), availableWidth), - qMin(label->implicitHeight(), availableHeight)), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + QSizeF(qMin(label->implicitWidth(), availableWidth), + qMin(label->implicitHeight(), availableHeight)), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); label->setSize(textRect.size()); label->setPosition(textRect.topLeft()); } @@ -276,67 +324,72 @@ void NeptuneIconLabelPrivate::layout() case NeptuneIconLabel::TextUnderIcon: { // Work out the sizes first, as the positions depend on them. - QSizeF iconSize; - QSizeF textSize; - if (image) { - iconSize.setWidth(qMin(image->implicitWidth() * iconScale, availableWidth)); - iconSize.setHeight(qMin(image->implicitHeight() * iconScale, availableHeight)); + QSizeF iconSize{0.0, 0.0}; + QSizeF textSize{0.0, 0.0}; + if (image && image->status() == QQuickImageBase::Ready) { + iconSize.setWidth(qMin(iconWidth, availableWidth)); + iconSize.setHeight(qMin(iconHeight, availableHeight)); } qreal effectiveSpacing = 0; if (label) { if (!iconSize.isEmpty()) effectiveSpacing = spacing; textSize.setWidth(qMin(label->implicitWidth(), availableWidth)); - textSize.setHeight(qMin(label->implicitHeight(), availableHeight - iconSize.height() - effectiveSpacing)); + textSize.setHeight(qMin(label->implicitHeight(), + availableHeight - iconSize.height() - effectiveSpacing)); } QRectF combinedRect = alignedRect(mirrored, alignment, - QSizeF(qMax(iconSize.width(), textSize.width()), - iconSize.height() + effectiveSpacing + textSize.height()), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - if (image) { - QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, combinedRect); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); + QSizeF(qMax(iconSize.width(), textSize.width()), + iconSize.height() + effectiveSpacing + textSize.height()), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + if (image && image->status() == QQuickImageBase::Ready) { + // Align rect for image according to available space + QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, + combinedRect); + applyIconSizeAndPosition(iconRect); } if (label) { - QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, combinedRect); + QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, + combinedRect); label->setSize(textRect.size()); label->setPosition(textRect.topLeft()); } break; } - - case NeptuneIconLabel::TextBesideIcon: default: + // includes case NeptuneIconLabel::TextBesideIcon: // Work out the sizes first, as the positions depend on them. - QSizeF iconSize(0, 0); - QSizeF textSize(0, 0); - if (image) { - iconSize.setWidth(qMin(image->implicitWidth() * iconScale, availableWidth)); - iconSize.setHeight(qMin(image->implicitHeight() * iconScale, availableHeight)); + QSizeF iconSize{0.0, 0.0}; + QSizeF textSize{0.0, 0.0}; + if (image && image->status() == QQuickImageBase::Ready) { + iconSize.setWidth(qMin(iconWidth, availableWidth)); + iconSize.setHeight(qMin(iconHeight, availableHeight)); } qreal effectiveSpacing = 0; if (label) { if (!iconSize.isEmpty()) effectiveSpacing = spacing; - textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width() - effectiveSpacing)); + textSize.setWidth(qMin(label->implicitWidth(), + availableWidth - iconSize.width() - effectiveSpacing)); textSize.setHeight(qMin(label->implicitHeight(), availableHeight)); } const QRectF combinedRect = alignedRect(mirrored, alignment, - QSizeF(iconSize.width() + effectiveSpacing + textSize.width(), - qMax(iconSize.height(), textSize.height())), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - if (image) { - const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedRect); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); + QSizeF(iconSize.width() + effectiveSpacing + textSize.width(), + qMax(iconSize.height(), textSize.height())), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + if (image && image->status() == QQuickImageBase::Ready) { + // Align rect for image according to available space + const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, + iconSize, combinedRect); + applyIconSizeAndPosition(iconRect); } if (label) { - const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedRect); + const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, + textSize, combinedRect); label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); + label->setPosition(textRect.topLeft().toPoint()); } break; } @@ -380,6 +433,33 @@ void NeptuneIconLabelPrivate::itemDestroyed(QQuickItem *item) label = nullptr; } +void NeptuneIconLabelPrivate::applyIconScaleForPadMode() { + // works only for Pad fill mode (default) + if (iconFillMode != QQuickImage::Pad) + return; + + if (qFuzzyCompare(iconScale, image->scale())) + return; + + image->setScale(iconScale); + layout(); +} + +void NeptuneIconLabelPrivate::applyIconRect() { + // works only for non-Pad fill mode + if (iconFillMode == QQuickImage::Pad) + return; + + // in non-pad mode scale is not used for image inner object, reset it + // it is fitted inside desired rect + if (!qFuzzyCompare(image->scale(), 1.0)) { + image->setScale(1.0); + } + + image->setFillMode(iconFillMode); + layout(); +} + NeptuneIconLabel::NeptuneIconLabel(QQuickItem *parent) : QQuickItem(*(new NeptuneIconLabelPrivate), parent) { @@ -403,6 +483,7 @@ QQuickIcon NeptuneIconLabel::icon() const void NeptuneIconLabel::setIcon(const QQuickIcon &icon) { Q_D(NeptuneIconLabel); + if (d->icon == icon) return; @@ -419,10 +500,19 @@ qreal NeptuneIconLabel::iconScale() const void NeptuneIconLabel::setIconScale(qreal scale) { Q_D(NeptuneIconLabel); - if (d->iconScale == scale) + if (qFuzzyCompare(d->iconScale, scale)) return; + if (qFuzzyCompare(scale, 0.0) || scale < 0.0) { + qmlWarning(this) << "Invalid scale value: " << scale << "must be greater than zero"; + return; + } + d->iconScale = scale; + if (d->image && d->image->status() == QQuickImageBase::Ready + && d->iconFillMode == QQuickImage::Pad) { + d->applyIconScaleForPadMode(); + } } QString NeptuneIconLabel::text() const @@ -540,8 +630,8 @@ void NeptuneIconLabel::setAlignment(Qt::Alignment alignment) Q_D(NeptuneIconLabel); const int valign = alignment & Qt::AlignVertical_Mask; const int halign = alignment & Qt::AlignHorizontal_Mask; - const uint align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter); - if (d->alignment == align) + const int align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter); + if (d->alignment & align) return; d->alignment = static_cast<Qt::Alignment>(align); @@ -647,6 +737,7 @@ void NeptuneIconLabel::resetBottomPadding() void NeptuneIconLabel::componentComplete() { Q_D(NeptuneIconLabel); + if (d->image) completeComponent(d->image); if (d->label) @@ -659,7 +750,91 @@ void NeptuneIconLabel::geometryChanged(const QRectF &newGeometry, const QRectF & { Q_D(NeptuneIconLabel); QQuickItem::geometryChanged(newGeometry, oldGeometry); - d->layout(); + + //layout operates only by width and height, skip layout updates on rect x,y change + if (newGeometry.size() != oldGeometry.size()) { + d->layout(); + } +} + +void NeptuneIconLabel::onImageStatusChanged(QQuickImageBase::Status status) +{ + Q_D(NeptuneIconLabel); + + if (status == QQuickImageBase::Ready) { + // When we create image object we don't know about it's pixel size until it is loaded + // We need image source pixel size to correctly display scaled image + + // In Pad mode we scale sourceSize according to iconScale size = pixel size x iconScale + // In other modes we scale sourceSize to fit in desired iconRectWidth x iconRectHeight + if (d->iconFillMode == QQuickImage::Pad) { + d->applyIconScaleForPadMode(); + } else if (d->iconRectWidth > 0.0 && d->iconRectHeight > 0.0) { + d->applyIconRect(); + } + } +} + +QQuickImage::FillMode NeptuneIconLabel::iconFillMode() const { + Q_D(const NeptuneIconLabel); + + return d->iconFillMode; +} + +void NeptuneIconLabel::setIconFillMode(QQuickImage::FillMode mode) { + Q_D(NeptuneIconLabel); + + if (d->iconFillMode == mode) + return; + + d->iconFillMode = mode; + + if (d->image && d->image->status() == QQuickImageBase::Ready) { + if (d->iconFillMode == QQuickImage::Pad) { + d->applyIconScaleForPadMode(); + } else if (d->iconRectWidth > 0 && d->iconRectHeight > 0) { + d->applyIconRect(); + } + } +} + +void NeptuneIconLabel::setIconRectWidth(qreal width) { + Q_D(NeptuneIconLabel); + + if (qFuzzyCompare(d->iconRectWidth, width)) + return; + + d->iconRectWidth = width; + if (d->image && d->image->status() == QQuickImageBase::Ready && d->iconRectHeight > 0.0 + && d->iconFillMode != QQuickImage::Pad) { + d->applyIconRect(); + } + Q_EMIT iconRectWidthChanged(); } +void NeptuneIconLabel::setIconRectHeight(qreal height) { + Q_D(NeptuneIconLabel); + + if (qFuzzyCompare(d->iconRectHeight, height)) + return; + + d->iconRectHeight = height; + if (d->image && d->image->status() == QQuickImageBase::Ready && d->iconRectWidth > 0 + && d->iconFillMode != QQuickImage::Pad) { + d->applyIconRect(); + } + Q_EMIT iconRectHeightChanged(); +} + +qreal NeptuneIconLabel::iconRectWidth() const { + Q_D(const NeptuneIconLabel); + + return d->iconRectWidth; +} + +qreal NeptuneIconLabel::iconRectHeight() const { + Q_D(const NeptuneIconLabel); + + return d->iconRectHeight; +} QT_END_NAMESPACE diff --git a/plugins/controls/neptuneiconlabel.h b/plugins/controls/neptuneiconlabel.h index b6c3af2d..18484bfe 100644 --- a/plugins/controls/neptuneiconlabel.h +++ b/plugins/controls/neptuneiconlabel.h @@ -35,6 +35,8 @@ #include <QtQuick/qquickitem.h> #include <QtQuickControls2/private/qtquickcontrols2global_p.h> #include <QtQuickTemplates2/private/qquickicon_p.h> +#include <QtQuick/private/qquickimagebase_p.h> +#include <QtQuick/private/qquickimage_p.h> QT_BEGIN_NAMESPACE @@ -56,6 +58,11 @@ class NeptuneIconLabel : public QQuickItem Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding FINAL) Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding FINAL) Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding FINAL) + Q_PROPERTY(QQuickImage::FillMode iconFillMode READ iconFillMode WRITE setIconFillMode FINAL) + Q_PROPERTY(qreal iconRectWidth READ iconRectWidth WRITE setIconRectWidth + NOTIFY iconRectWidthChanged) + Q_PROPERTY(qreal iconRectHeight READ iconRectHeight WRITE setIconRectHeight + NOTIFY iconRectHeightChanged) public: enum Display { @@ -69,6 +76,9 @@ public: explicit NeptuneIconLabel(QQuickItem *parent = nullptr); ~NeptuneIconLabel(); + QQuickImage::FillMode iconFillMode() const; + void setIconFillMode(QQuickImage::FillMode mode); + QQuickIcon icon() const; void setIcon(const QQuickIcon &icon); @@ -112,10 +122,23 @@ public: void setBottomPadding(qreal padding); void resetBottomPadding(); + qreal iconRectWidth() const; + void setIconRectWidth(qreal width); + + qreal iconRectHeight() const; + void setIconRectHeight(qreal height); + +Q_SIGNALS: + void iconRectWidthChanged(); + void iconRectHeightChanged(); + protected: void componentComplete() override; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; +private Q_SLOTS: + void onImageStatusChanged(QQuickImageBase::Status); + private: Q_DISABLE_COPY(NeptuneIconLabel) Q_DECLARE_PRIVATE(NeptuneIconLabel) diff --git a/plugins/controls/neptuneiconlabel_p.h b/plugins/controls/neptuneiconlabel_p.h index d3ee90dd..ddd5ef53 100644 --- a/plugins/controls/neptuneiconlabel_p.h +++ b/plugins/controls/neptuneiconlabel_p.h @@ -35,6 +35,8 @@ #include <QtQuick/private/qquickitem_p.h> #include <QtQuickControls2/private/qtquickcontrols2global_p.h> #include <QtQuickTemplates2/private/qquickicon_p.h> +#include <QtQuick/private/qquickimage_p.h> +#include <QtQuick/private/qquickrectangle_p.h> QT_BEGIN_NAMESPACE @@ -91,6 +93,14 @@ public: QQuickIcon icon; QQuickIconImage *image; QQuickMnemonicLabel *label; + QQuickImage::FillMode iconFillMode{QQuickImage::FillMode::Pad}; + qreal iconRectWidth{0.0}; + qreal iconRectHeight{0.0}; + +private: + void applyIconScaleForPadMode(); + void applyIconRect(); + void applyIconSizeAndPosition(const QRectF &iconRect); }; QT_END_NAMESPACE |