65void QQuickLabelPrivate::setTopInset(qreal value,
bool reset)
68 const QMarginsF oldInset = getInset();
69 extra.value().topInset = value;
70 extra.value().hasTopInset = !reset;
71 if (!qFuzzyCompare(oldInset.top(), value)) {
72 emit q->topInsetChanged();
73 q->insetChange(getInset(), oldInset);
77void QQuickLabelPrivate::setLeftInset(qreal value,
bool reset)
80 const QMarginsF oldInset = getInset();
81 extra.value().leftInset = value;
82 extra.value().hasLeftInset = !reset;
83 if (!qFuzzyCompare(oldInset.left(), value)) {
84 emit q->leftInsetChanged();
85 q->insetChange(getInset(), oldInset);
89void QQuickLabelPrivate::setRightInset(qreal value,
bool reset)
92 const QMarginsF oldInset = getInset();
93 extra.value().rightInset = value;
94 extra.value().hasRightInset = !reset;
95 if (!qFuzzyCompare(oldInset.right(), value)) {
96 emit q->rightInsetChanged();
97 q->insetChange(getInset(), oldInset);
101void QQuickLabelPrivate::setBottomInset(qreal value,
bool reset)
104 const QMarginsF oldInset = getInset();
105 extra.value().bottomInset = value;
106 extra.value().hasBottomInset = !reset;
107 if (!qFuzzyCompare(oldInset.bottom(), value)) {
108 emit q->bottomInsetChanged();
109 q->insetChange(getInset(), oldInset);
113void QQuickLabelPrivate::resizeBackground()
118 resizingBackground =
true;
120 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
121 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
122 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
123 background->setX(getLeftInset());
124 background->setWidth(width - getLeftInset() - getRightInset());
126 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
127 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
128 background->setY(getTopInset());
129 background->setHeight(height - getTopInset() - getBottomInset());
132 resizingBackground =
false;
149void QQuickLabelPrivate::inheritFont(
const QFont &font)
151 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
152 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
154 const QFont defaultFont = QQuickTheme::font(QQuickTheme::Label);
155 QFont resolvedFont = parentFont.resolve(defaultFont);
157 setFont_helper(resolvedFont);
165void QQuickLabelPrivate::updateFont(
const QFont &font)
168 QFont oldFont = sourceFont;
169 q->QQuickText::setFont(font);
171 QQuickControlPrivate::updateFontRecur(q, font);
174 emit q->fontChanged();
222void QQuickLabelPrivate::executeBackground(
bool complete)
225 if (background.wasExecuted())
228 if (!background || complete)
229 quickBeginDeferred(q, backgroundName(), background);
231 quickCompleteDeferred(q, backgroundName(), background);
234void QQuickLabelPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
237 if (resizingBackground || item != background || !change.sizeChange())
240 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
241 extra.value().hasBackgroundWidth = p->widthValid();
242 extra.value().hasBackgroundHeight = p->heightValid();
275QQuickLabel::QQuickLabel(QQuickItem *parent)
276 : QQuickText(*(
new QQuickLabelPrivate), parent)
279 QObjectPrivate::connect(
this, &QQuickText::textChanged, d, &QQuickLabelPrivate::textChanged);
326void QQuickLabel::setBackground(QQuickItem *background)
329 if (d->background == background)
332 if (!d->background.isExecuting())
333 d->cancelBackground();
335 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
336 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
338 if (d->extra.isAllocated()) {
339 d->extra.value().hasBackgroundWidth =
false;
340 d->extra.value().hasBackgroundHeight =
false;
343 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
344 QQuickControlPrivate::hideOldItem(d->background);
345 d->background = background;
348 background->setParentItem(
this);
349 if (qFuzzyIsNull(background->z()))
350 background->setZ(-1);
351 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
352 if (p->widthValid() || p->heightValid()) {
353 d->extra.value().hasBackgroundWidth = p->widthValid();
354 d->extra.value().hasBackgroundHeight = p->heightValid();
356 if (isComponentComplete())
357 d->resizeBackground();
358 QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
361 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
362 emit implicitBackgroundWidthChanged();
363 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
364 emit implicitBackgroundHeightChanged();
365 if (!d->background.isExecuting())
366 emit backgroundChanged();
530void QQuickLabel::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
533 QQuickText::itemChange(change, value);
535 case ItemEnabledHasChanged:
537 case ItemSceneChange:
538 case ItemParentHasChanged:
539 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {