66void QQuickLabelPrivate::setTopInset(qreal value,
bool reset)
69 const QMarginsF oldInset = getInset();
70 extra.value().topInset = value;
71 extra.value().hasTopInset = !reset;
72 if (!qFuzzyCompare(oldInset.top(), value)) {
73 emit q->topInsetChanged();
74 q->insetChange(getInset(), oldInset);
78void QQuickLabelPrivate::setLeftInset(qreal value,
bool reset)
81 const QMarginsF oldInset = getInset();
82 extra.value().leftInset = value;
83 extra.value().hasLeftInset = !reset;
84 if (!qFuzzyCompare(oldInset.left(), value)) {
85 emit q->leftInsetChanged();
86 q->insetChange(getInset(), oldInset);
90void QQuickLabelPrivate::setRightInset(qreal value,
bool reset)
93 const QMarginsF oldInset = getInset();
94 extra.value().rightInset = value;
95 extra.value().hasRightInset = !reset;
96 if (!qFuzzyCompare(oldInset.right(), value)) {
97 emit q->rightInsetChanged();
98 q->insetChange(getInset(), oldInset);
102void QQuickLabelPrivate::setBottomInset(qreal value,
bool reset)
105 const QMarginsF oldInset = getInset();
106 extra.value().bottomInset = value;
107 extra.value().hasBottomInset = !reset;
108 if (!qFuzzyCompare(oldInset.bottom(), value)) {
109 emit q->bottomInsetChanged();
110 q->insetChange(getInset(), oldInset);
114void QQuickLabelPrivate::resizeBackground()
119 resizingBackground =
true;
121 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
122 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
123 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
124 background->setX(getLeftInset());
125 background->setWidth(width - getLeftInset() - getRightInset());
127 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
128 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
129 background->setY(getTopInset());
130 background->setHeight(height - getTopInset() - getBottomInset());
133 resizingBackground =
false;
150void QQuickLabelPrivate::inheritFont(
const QFont &font)
152 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
153 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
155 const QFont defaultFont = QQuickTheme::font(QQuickTheme::Label);
156 QFont resolvedFont = parentFont.resolve(defaultFont);
158 setFont_helper(resolvedFont);
166void QQuickLabelPrivate::updateFont(
const QFont &font)
169 QFont oldFont = sourceFont;
170 q->QQuickText::setFont(font);
172 QQuickControlPrivate::updateFontRecur(q, font);
175 emit q->fontChanged();
223void QQuickLabelPrivate::executeBackground(
bool complete)
226 if (background.wasExecuted())
229 if (!background || complete)
230 quickBeginDeferred(q, backgroundName(), background);
232 quickCompleteDeferred(q, backgroundName(), background);
235void QQuickLabelPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
238 if (resizingBackground || item != background || !change.sizeChange())
241 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
242 extra.value().hasBackgroundWidth = p->widthValid();
243 extra.value().hasBackgroundHeight = p->heightValid();
276QQuickLabel::QQuickLabel(QQuickItem *parent)
277 : QQuickText(*(
new QQuickLabelPrivate), parent)
280 QObjectPrivate::connect(
this, &QQuickText::textChanged, d, &QQuickLabelPrivate::textChanged);
327void QQuickLabel::setBackground(QQuickItem *background)
330 if (d->background == background)
333 if (!d->background.isExecuting())
334 d->cancelBackground();
336 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
337 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
339 if (d->extra.isAllocated()) {
340 d->extra.value().hasBackgroundWidth =
false;
341 d->extra.value().hasBackgroundHeight =
false;
344 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
345 QQuickControlPrivate::hideOldItem(d->background);
346 d->background = background;
349 background->setParentItem(
this);
350 if (qFuzzyIsNull(background->z()))
351 background->setZ(-1);
352 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
353 if (p->widthValid() || p->heightValid()) {
354 d->extra.value().hasBackgroundWidth = p->widthValid();
355 d->extra.value().hasBackgroundHeight = p->heightValid();
357 if (isComponentComplete())
358 d->resizeBackground();
359 QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
362 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
363 emit implicitBackgroundWidthChanged();
364 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
365 emit implicitBackgroundHeightChanged();
366 if (!d->background.isExecuting())
367 emit backgroundChanged();
531void QQuickLabel::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
534 QQuickText::itemChange(change, value);
536 case ItemEnabledHasChanged:
538 case ItemSceneChange:
539 case ItemParentHasChanged:
540 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {