Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquicklabel.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquicklabel_p.h"
5#include "qquicklabel_p_p.h"
6#include "qquickcontrol_p.h"
7#include "qquickcontrol_p_p.h"
9
10#include <QtQuick/private/qquickitem_p.h>
11#include <QtQuick/private/qquicktext_p.h>
12
13#if QT_CONFIG(accessibility)
14#include <QtQuick/private/qquickaccessibleattached_p.h>
15#endif
16
18
23
50{
51#if QT_CONFIG(accessibility)
52 QAccessible::installActivationObserver(this);
53#endif
54}
55
57{
58#if QT_CONFIG(accessibility)
59 QAccessible::removeActivationObserver(this);
60#endif
61}
62
64{
65 Q_Q(QQuickLabel);
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);
72 }
73}
74
76{
77 Q_Q(QQuickLabel);
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);
84 }
85}
86
88{
89 Q_Q(QQuickLabel);
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);
96 }
97}
98
100{
101 Q_Q(QQuickLabel);
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);
108 }
109}
110
112{
113 if (!background)
114 return;
115
116 resizingBackground = true;
117
119 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
120 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
123 }
124 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
125 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
128 }
129
130 resizingBackground = false;
131}
132
146
148{
149 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
150 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
151
152 const QFont defaultFont = QQuickTheme::font(QQuickTheme::Label);
153 QFont resolvedFont = parentFont.resolve(defaultFont);
154
155 setFont_helper(resolvedFont);
156}
157
164{
165 Q_Q(QQuickLabel);
166 QFont oldFont = sourceFont;
167 q->QQuickText::setFont(font);
168
170
171 if (oldFont != font)
172 emit q->fontChanged();
173}
174
176{
177#if QT_CONFIG(accessibility)
178 maybeSetAccessibleName(text);
179#else
180 Q_UNUSED(text);
181#endif
182}
183
184#if QT_CONFIG(accessibility)
185void QQuickLabelPrivate::accessibilityActiveChanged(bool active)
186{
187 if (!active)
188 return;
189
190 Q_Q(QQuickLabel);
191 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q, true));
192 Q_ASSERT(accessibleAttached);
193 accessibleAttached->setRole(effectiveAccessibleRole());
194 maybeSetAccessibleName(text);
195}
196
197QAccessible::Role QQuickLabelPrivate::accessibleRole() const
198{
199 return QAccessible::StaticText;
200}
201
202void QQuickLabelPrivate::maybeSetAccessibleName(const QString &name)
203{
204 Q_Q(QQuickLabel);
205 auto accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(
206 qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q, true));
207 if (accessibleAttached) {
208 if (!accessibleAttached->wasNameExplicitlySet())
209 accessibleAttached->setNameImplicitly(name);
210 }
211}
212#endif
213
219
221{
222 Q_Q(QQuickLabel);
224 return;
225
226 if (!background || complete)
228 if (complete)
230}
231
233{
234 Q_UNUSED(diff);
235 if (resizingBackground || item != background || !change.sizeChange())
236 return;
237
239 extra.value().hasBackgroundWidth = p->widthValid();
240 extra.value().hasBackgroundHeight = p->heightValid();
242}
243
245{
246 Q_Q(QQuickLabel);
247 if (item == background)
248 emit q->implicitBackgroundWidthChanged();
249}
250
252{
253 Q_Q(QQuickLabel);
254 if (item == background)
255 emit q->implicitBackgroundHeightChanged();
256}
257
259{
260 Q_Q(QQuickLabel);
261 if (item == background) {
262 background = nullptr;
263 emit q->implicitBackgroundWidthChanged();
264 emit q->implicitBackgroundHeightChanged();
265 }
266}
267
272
279
285
287{
288 Q_D(const QQuickLabel);
290 // The resolve mask should inherit from the requestedFont
291 font.setResolveMask(d->extra.value().requestedFont.resolveMask());
292 return font;
293}
294
296{
297 Q_D(QQuickLabel);
298 if (d->extra.value().requestedFont.resolveMask() == font.resolveMask() && d->extra.value().requestedFont == font)
299 return;
300
301 d->extra.value().requestedFont = font;
302 d->resolveFont();
303}
304
317{
318 QQuickLabelPrivate *d = const_cast<QQuickLabelPrivate *>(d_func());
319 if (!d->background)
321 return d->background;
322}
323
325{
326 Q_D(QQuickLabel);
327 if (d->background == background)
328 return;
329
330 if (!d->background.isExecuting())
331 d->cancelBackground();
332
333 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
334 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
335
336 if (d->extra.isAllocated()) {
337 d->extra.value().hasBackgroundWidth = false;
338 d->extra.value().hasBackgroundHeight = false;
339 }
340
343 d->background = background;
344
345 if (background) {
347 if (qFuzzyIsNull(background->z()))
348 background->setZ(-1);
350 if (p->widthValid() || p->heightValid()) {
351 d->extra.value().hasBackgroundWidth = p->widthValid();
352 d->extra.value().hasBackgroundHeight = p->heightValid();
353 }
355 d->resizeBackground();
357 }
358
359 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
360 emit implicitBackgroundWidthChanged();
361 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
362 emit implicitBackgroundHeightChanged();
363 if (!d->background.isExecuting())
365}
366
379{
380 Q_D(const QQuickLabel);
381 if (!d->background)
382 return 0;
383 return d->background->implicitWidth();
384}
385
398{
399 Q_D(const QQuickLabel);
400 if (!d->background)
401 return 0;
402 return d->background->implicitHeight();
403}
404
414{
415 Q_D(const QQuickLabel);
416 return d->getTopInset();
417}
418
420{
421 Q_D(QQuickLabel);
422 d->setTopInset(inset);
423}
424
426{
427 Q_D(QQuickLabel);
428 d->setTopInset(0, true);
429}
430
440{
441 Q_D(const QQuickLabel);
442 return d->getLeftInset();
443}
444
446{
447 Q_D(QQuickLabel);
448 d->setLeftInset(inset);
449}
450
452{
453 Q_D(QQuickLabel);
454 d->setLeftInset(0, true);
455}
456
466{
467 Q_D(const QQuickLabel);
468 return d->getRightInset();
469}
470
472{
473 Q_D(QQuickLabel);
474 d->setRightInset(inset);
475}
476
478{
479 Q_D(QQuickLabel);
480 d->setRightInset(0, true);
481}
482
492{
493 Q_D(const QQuickLabel);
494 return d->getBottomInset();
495}
496
498{
499 Q_D(QQuickLabel);
500 d->setBottomInset(inset);
501}
502
504{
505 Q_D(QQuickLabel);
506 d->setBottomInset(0, true);
507}
508
510{
511 Q_D(QQuickLabel);
513 d->resolveFont();
514}
515
517{
518 Q_D(QQuickLabel);
519 d->executeBackground(true);
521 d->resizeBackground();
522#if QT_CONFIG(accessibility)
523 if (QAccessible::isActive())
524 d->accessibilityActiveChanged(true);
525#endif
526}
527
529{
530 Q_D(QQuickLabel);
532 switch (change) {
534 break;
535 case ItemSceneChange:
537 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
538 d->resolveFont();
539 }
540 break;
541 default:
542 break;
543 }
544}
545
546void QQuickLabel::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
547{
548 Q_D(QQuickLabel);
549 QQuickText::geometryChange(newGeometry, oldGeometry);
550 d->resizeBackground();
551}
552
553void QQuickLabel::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
554{
555 Q_D(QQuickLabel);
556 Q_UNUSED(newInset);
557 Q_UNUSED(oldInset);
558 d->resizeBackground();
559}
560
562
563#include "moc_qquicklabel_p.cpp"
\reentrant
Definition qfont.h:22
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition qfont.cpp:1893
void setResolveMask(uint mask)
Definition qfont.h:313
uint resolveMask() const
Definition qfont.h:312
\inmodule QtCore
Definition qmargins.h:270
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
virtual void classBegin()=0
Invoked after class creation, but before any properties have been set.
void removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes=ImplicitSizeChanges)
static const ChangeTypes ImplicitSizeChanges
Abstract base type providing functionality common to all controls.
void addImplicitSizeListener(QQuickItem *item, ChangeTypes changes=ImplicitSizeChanges)
static void hideOldItem(QQuickItem *item)
static QFont parentFont(const QQuickItem *item)
static void updateFontRecur(QQuickItem *item, const QFont &font)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
qreal x
\qmlproperty real QtQuick::Item::x \qmlproperty real QtQuick::Item::y \qmlproperty real QtQuick::Item...
Definition qquickitem.h:72
void setParentItem(QQuickItem *parent)
qreal z
\qmlproperty real QtQuick::Item::z
Definition qquickitem.h:74
qreal y
Defines the item's y position relative to its parent.
Definition qquickitem.h:73
void setHeight(qreal)
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void setZ(qreal)
void setWidth(qreal)
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:144
@ ItemEnabledHasChanged
Definition qquickitem.h:155
@ ItemParentHasChanged
Definition qquickitem.h:149
void setX(qreal)
void setY(qreal)
void itemDestroyed(QQuickItem *item) override
QQuickLabelPrivate()
Styled text label with inherited font.
void setBottomInset(qreal value, bool reset=false)
void textChanged(const QString &text)
void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override
void inheritFont(const QFont &font)
void itemImplicitWidthChanged(QQuickItem *item) override
QMarginsF getInset() const
qreal getLeftInset() const
void updateFont(const QFont &font)
qreal getBottomInset() const
void setFont_helper(const QFont &font)
qreal getTopInset() const
void setLeftInset(qreal value, bool reset=false)
void itemImplicitHeightChanged(QQuickItem *item) override
qreal getRightInset() const
void executeBackground(bool complete=false)
QLazilyAllocated< ExtraData > extra
QQuickDeferredPointer< QQuickItem > background
QPalette defaultPalette() const override
void setTopInset(qreal value, bool reset=false)
void setRightInset(qreal value, bool reset=false)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setFont(const QFont &font)
void setTopInset(qreal inset)
void resetRightInset()
void backgroundChanged()
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void resetBottomInset()
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
qreal implicitBackgroundWidth
qreal implicitBackgroundHeight
void resetLeftInset()
void setLeftInset(qreal inset)
virtual void insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
void setRightInset(qreal inset)
void setBottomInset(qreal inset)
void resetTopInset()
void classBegin() override
\reimp Derived classes should call the base class method before adding their own action to perform at...
QQuickLabel(QQuickItem *parent=nullptr)
QQuickItem * background
qreal bottomInset
void setBackground(QQuickItem *background)
void textChanged(const QString &text)
void componentComplete() override
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
static QPalette palette(Scope scope)
static QFont font(Scope scope)
\inmodule QtCore\reentrant
Definition qrect.h:484
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString text
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
GLint GLsizei GLsizei height
GLint GLsizei width
GLuint name
GLboolean reset
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
void quickCancelDeferred(QObject *object, const QString &property)
void quickCompleteDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
void quickBeginDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
#define Q_UNUSED(x)
static QString backgroundName()
double qreal
Definition qtypes.h:187
QGraphicsItem * item
\inmodule QtQuick
Definition qquickitem.h:159