64void QQuickLabelPrivate::setTopInset(qreal value,
bool reset)
67 const QMarginsF oldInset = getInset();
68 extra.value().topInset = value;
69 extra.value().hasTopInset = !reset;
70 if (!qFuzzyCompare(oldInset.top(), value)) {
71 emit q->topInsetChanged();
72 q->insetChange(getInset(), oldInset);
76void QQuickLabelPrivate::setLeftInset(qreal value,
bool reset)
79 const QMarginsF oldInset = getInset();
80 extra.value().leftInset = value;
81 extra.value().hasLeftInset = !reset;
82 if (!qFuzzyCompare(oldInset.left(), value)) {
83 emit q->leftInsetChanged();
84 q->insetChange(getInset(), oldInset);
88void QQuickLabelPrivate::setRightInset(qreal value,
bool reset)
91 const QMarginsF oldInset = getInset();
92 extra.value().rightInset = value;
93 extra.value().hasRightInset = !reset;
94 if (!qFuzzyCompare(oldInset.right(), value)) {
95 emit q->rightInsetChanged();
96 q->insetChange(getInset(), oldInset);
100void QQuickLabelPrivate::setBottomInset(qreal value,
bool reset)
103 const QMarginsF oldInset = getInset();
104 extra.value().bottomInset = value;
105 extra.value().hasBottomInset = !reset;
106 if (!qFuzzyCompare(oldInset.bottom(), value)) {
107 emit q->bottomInsetChanged();
108 q->insetChange(getInset(), oldInset);
112void QQuickLabelPrivate::resizeBackground()
117 resizingBackground =
true;
119 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
120 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
121 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
122 background->setX(getLeftInset());
123 background->setWidth(width - getLeftInset() - getRightInset());
125 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
126 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
127 background->setY(getTopInset());
128 background->setHeight(height - getTopInset() - getBottomInset());
131 resizingBackground =
false;
148void QQuickLabelPrivate::inheritFont(
const QFont &font)
150 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
151 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
153 const QFont defaultFont = QQuickTheme::font(QQuickTheme::Label);
154 QFont resolvedFont = parentFont.resolve(defaultFont);
156 setFont_helper(resolvedFont);
164void QQuickLabelPrivate::updateFont(
const QFont &font)
167 QFont oldFont = sourceFont;
168 q->QQuickText::setFont(font);
170 QQuickControlPrivate::updateFontRecur(q, font);
173 emit q->fontChanged();
221void QQuickLabelPrivate::executeBackground(
bool complete)
224 if (background.wasExecuted())
227 if (!background || complete)
228 quickBeginDeferred(q, backgroundName(), background);
230 quickCompleteDeferred(q, backgroundName(), background);
233void QQuickLabelPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
236 if (resizingBackground || item != background || !change.sizeChange())
239 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
240 extra.value().hasBackgroundWidth = p->widthValid();
241 extra.value().hasBackgroundHeight = p->heightValid();
274QQuickLabel::QQuickLabel(QQuickItem *parent)
275 : QQuickText(*(
new QQuickLabelPrivate), parent)
278 QObjectPrivate::connect(
this, &QQuickText::textChanged, d, &QQuickLabelPrivate::textChanged);
325void QQuickLabel::setBackground(QQuickItem *background)
328 if (d->background == background)
331 if (!d->background.isExecuting())
332 d->cancelBackground();
334 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
335 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
337 if (d->extra.isAllocated()) {
338 d->extra.value().hasBackgroundWidth =
false;
339 d->extra.value().hasBackgroundHeight =
false;
342 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
343 QQuickControlPrivate::hideOldItem(d->background);
344 d->background = background;
347 background->setParentItem(
this);
348 if (qFuzzyIsNull(background->z()))
349 background->setZ(-1);
350 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
351 if (p->widthValid() || p->heightValid()) {
352 d->extra.value().hasBackgroundWidth = p->widthValid();
353 d->extra.value().hasBackgroundHeight = p->heightValid();
355 if (isComponentComplete())
356 d->resizeBackground();
357 QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
360 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
361 emit implicitBackgroundWidthChanged();
362 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
363 emit implicitBackgroundHeightChanged();
364 if (!d->background.isExecuting())
365 emit backgroundChanged();
529void QQuickLabel::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
532 QQuickText::itemChange(change, value);
534 case ItemEnabledHasChanged:
536 case ItemSceneChange:
537 case ItemParentHasChanged:
538 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {