63void QQuickLabelPrivate::setTopInset(qreal value,
bool reset)
66 const QMarginsF oldInset = getInset();
67 extra.value().topInset = value;
68 extra.value().hasTopInset = !reset;
69 if (!qFuzzyCompare(oldInset.top(), value)) {
70 emit q->topInsetChanged();
71 q->insetChange(getInset(), oldInset);
75void QQuickLabelPrivate::setLeftInset(qreal value,
bool reset)
78 const QMarginsF oldInset = getInset();
79 extra.value().leftInset = value;
80 extra.value().hasLeftInset = !reset;
81 if (!qFuzzyCompare(oldInset.left(), value)) {
82 emit q->leftInsetChanged();
83 q->insetChange(getInset(), oldInset);
87void QQuickLabelPrivate::setRightInset(qreal value,
bool reset)
90 const QMarginsF oldInset = getInset();
91 extra.value().rightInset = value;
92 extra.value().hasRightInset = !reset;
93 if (!qFuzzyCompare(oldInset.right(), value)) {
94 emit q->rightInsetChanged();
95 q->insetChange(getInset(), oldInset);
99void QQuickLabelPrivate::setBottomInset(qreal value,
bool reset)
102 const QMarginsF oldInset = getInset();
103 extra.value().bottomInset = value;
104 extra.value().hasBottomInset = !reset;
105 if (!qFuzzyCompare(oldInset.bottom(), value)) {
106 emit q->bottomInsetChanged();
107 q->insetChange(getInset(), oldInset);
111void QQuickLabelPrivate::resizeBackground()
116 resizingBackground =
true;
118 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
119 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
120 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
121 background->setX(getLeftInset());
122 background->setWidth(width - getLeftInset() - getRightInset());
124 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
125 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
126 background->setY(getTopInset());
127 background->setHeight(height - getTopInset() - getBottomInset());
130 resizingBackground =
false;
147void QQuickLabelPrivate::inheritFont(
const QFont &font)
149 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
150 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
152 const QFont defaultFont = QQuickTheme::font(QQuickTheme::Label);
153 QFont resolvedFont = parentFont.resolve(defaultFont);
155 setFont_helper(resolvedFont);
163void QQuickLabelPrivate::updateFont(
const QFont &font)
166 QFont oldFont = sourceFont;
167 q->QQuickText::setFont(font);
169 QQuickControlPrivate::updateFontRecur(q, font);
172 emit q->fontChanged();
220void QQuickLabelPrivate::executeBackground(
bool complete)
223 if (background.wasExecuted())
226 if (!background || complete)
227 quickBeginDeferred(q, backgroundName(), background);
229 quickCompleteDeferred(q, backgroundName(), background);
232void QQuickLabelPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
235 if (resizingBackground || item != background || !change.sizeChange())
238 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
239 extra.value().hasBackgroundWidth = p->widthValid();
240 extra.value().hasBackgroundHeight = p->heightValid();
273QQuickLabel::QQuickLabel(QQuickItem *parent)
274 : QQuickText(*(
new QQuickLabelPrivate), parent)
277 QObjectPrivate::connect(
this, &QQuickText::textChanged, d, &QQuickLabelPrivate::textChanged);
324void QQuickLabel::setBackground(QQuickItem *background)
327 if (d->background == background)
330 if (!d->background.isExecuting())
331 d->cancelBackground();
333 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
334 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
336 if (d->extra.isAllocated()) {
337 d->extra.value().hasBackgroundWidth =
false;
338 d->extra.value().hasBackgroundHeight =
false;
341 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
342 QQuickControlPrivate::hideOldItem(d->background);
343 d->background = background;
346 background->setParentItem(
this);
347 if (qFuzzyIsNull(background->z()))
348 background->setZ(-1);
349 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
350 if (p->widthValid() || p->heightValid()) {
351 d->extra.value().hasBackgroundWidth = p->widthValid();
352 d->extra.value().hasBackgroundHeight = p->heightValid();
354 if (isComponentComplete())
355 d->resizeBackground();
356 QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
359 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
360 emit implicitBackgroundWidthChanged();
361 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
362 emit implicitBackgroundHeightChanged();
363 if (!d->background.isExecuting())
364 emit backgroundChanged();
528void QQuickLabel::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
531 QQuickText::itemChange(change, value);
533 case ItemEnabledHasChanged:
535 case ItemSceneChange:
536 case ItemParentHasChanged:
537 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {