8#include <QtGui/qstylehints.h>
9#include <QtGui/qguiapplication.h>
24#if QT_CONFIG(accessibility)
25#include <QtQuick/private/qquickaccessibleattached_p.h>
30Q_LOGGING_CATEGORY(lcItemManagement,
"qt.quick.controls.control.itemmanagement")
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
119const QQuickItemPrivate::ChangeTypes QQuickControlPrivate::ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed;
123 return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason || reason == Qt::ShortcutFocusReason;
126QQuickControlPrivate::QQuickControlPrivate()
128#if QT_CONFIG(accessibility)
129 QAccessible::installActivationObserver(
this);
133QQuickControlPrivate::~QQuickControlPrivate()
137void QQuickControlPrivate::init()
140 QObject::connect(q, &QQuickItem::baselineOffsetChanged, q, &QQuickControl::baselineOffsetChanged);
143#if QT_CONFIG(quicktemplates2_multitouch)
144bool QQuickControlPrivate::acceptTouch(
const QTouchEvent::TouchPoint &point)
146 if (point.id() == touchId)
149 if (touchId == -1 && point.state() == QEventPoint::Pressed) {
150 touchId = point.id();
158bool QQuickControlPrivate::handlePress(
const QPointF &, ulong)
163bool QQuickControlPrivate::handleMove(
const QPointF &point, ulong)
165#if QT_CONFIG(quicktemplates2_hover)
167 q->setHovered(hoverEnabled && q->contains(point));
174bool QQuickControlPrivate::handleRelease(
const QPointF &, ulong)
180void QQuickControlPrivate::handleUngrab()
185void QQuickControlPrivate::mirrorChange()
191void QQuickControlPrivate::setTopPadding(qreal value,
bool reset)
194 const QMarginsF oldPadding = getPadding();
195 extra.value().topPadding = value;
196 extra.value().hasTopPadding = !reset;
197 if ((!reset && !qFuzzyCompare(oldPadding.top(), value)) || (reset && !qFuzzyCompare(oldPadding.top(), getVerticalPadding()))) {
198 emit q->topPaddingChanged();
199 emit q->availableHeightChanged();
200 q->paddingChange(getPadding(), oldPadding);
204void QQuickControlPrivate::setLeftPadding(qreal value,
bool reset)
207 const QMarginsF oldPadding = getPadding();
208 extra.value().leftPadding = value;
209 extra.value().hasLeftPadding = !reset;
210 if ((!reset && !qFuzzyCompare(oldPadding.left(), value)) || (reset && !qFuzzyCompare(oldPadding.left(), getHorizontalPadding()))) {
211 emit q->leftPaddingChanged();
212 emit q->availableWidthChanged();
213 q->paddingChange(getPadding(), oldPadding);
217void QQuickControlPrivate::setRightPadding(qreal value,
bool reset)
220 const QMarginsF oldPadding = getPadding();
221 extra.value().rightPadding = value;
222 extra.value().hasRightPadding = !reset;
223 if ((!reset && !qFuzzyCompare(oldPadding.right(), value)) || (reset && !qFuzzyCompare(oldPadding.right(), getHorizontalPadding()))) {
224 emit q->rightPaddingChanged();
225 emit q->availableWidthChanged();
226 q->paddingChange(getPadding(), oldPadding);
230void QQuickControlPrivate::setBottomPadding(qreal value,
bool reset)
233 const QMarginsF oldPadding = getPadding();
234 extra.value().bottomPadding = value;
235 extra.value().hasBottomPadding = !reset;
236 if ((!reset && !qFuzzyCompare(oldPadding.bottom(), value)) || (reset && !qFuzzyCompare(oldPadding.bottom(), getVerticalPadding()))) {
237 emit q->bottomPaddingChanged();
238 emit q->availableHeightChanged();
239 q->paddingChange(getPadding(), oldPadding);
243void QQuickControlPrivate::setHorizontalPadding(qreal value,
bool reset)
246 const QMarginsF oldPadding = getPadding();
247 const qreal oldHorizontalPadding = getHorizontalPadding();
248 horizontalPadding = value;
249 hasHorizontalPadding = !reset;
250 if ((!reset && !qFuzzyCompare(oldHorizontalPadding, value)) || (reset && !qFuzzyCompare(oldHorizontalPadding, padding))) {
251 const QMarginsF newPadding = getPadding();
252 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
253 emit q->leftPaddingChanged();
254 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
255 emit q->rightPaddingChanged();
256 emit q->horizontalPaddingChanged();
257 emit q->availableWidthChanged();
258 q->paddingChange(newPadding, oldPadding);
262void QQuickControlPrivate::setVerticalPadding(qreal value,
bool reset)
265 const QMarginsF oldPadding = getPadding();
266 const qreal oldVerticalPadding = getVerticalPadding();
267 verticalPadding = value;
268 hasVerticalPadding = !reset;
269 if ((!reset && !qFuzzyCompare(oldVerticalPadding, value)) || (reset && !qFuzzyCompare(oldVerticalPadding, padding))) {
270 const QMarginsF newPadding = getPadding();
271 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
272 emit q->topPaddingChanged();
273 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
274 emit q->bottomPaddingChanged();
275 emit q->verticalPaddingChanged();
276 emit q->availableHeightChanged();
277 q->paddingChange(newPadding, oldPadding);
281void QQuickControlPrivate::setTopInset(qreal value,
bool reset)
284 const QMarginsF oldInset = getInset();
285 extra.value().topInset = value;
286 extra.value().hasTopInset = !reset;
287 if (!qFuzzyCompare(oldInset.top(), value)) {
288 emit q->topInsetChanged();
289 q->insetChange(getInset(), oldInset);
293void QQuickControlPrivate::setLeftInset(qreal value,
bool reset)
296 const QMarginsF oldInset = getInset();
297 extra.value().leftInset = value;
298 extra.value().hasLeftInset = !reset;
299 if (!qFuzzyCompare(oldInset.left(), value)) {
300 emit q->leftInsetChanged();
301 q->insetChange(getInset(), oldInset);
305void QQuickControlPrivate::setRightInset(qreal value,
bool reset)
308 const QMarginsF oldInset = getInset();
309 extra.value().rightInset = value;
310 extra.value().hasRightInset = !reset;
311 if (!qFuzzyCompare(oldInset.right(), value)) {
312 emit q->rightInsetChanged();
313 q->insetChange(getInset(), oldInset);
317void QQuickControlPrivate::setBottomInset(qreal value,
bool reset)
320 const QMarginsF oldInset = getInset();
321 extra.value().bottomInset = value;
322 extra.value().hasBottomInset = !reset;
323 if (!qFuzzyCompare(oldInset.bottom(), value)) {
324 emit q->bottomInsetChanged();
325 q->insetChange(getInset(), oldInset);
329void QQuickControlPrivate::resizeBackground()
334 resizingBackground =
true;
336 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
337 bool changeWidth =
false;
338 bool changeHeight =
false;
339 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
340 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
341 const auto leftInset = getLeftInset();
342 if (!qt_is_nan(leftInset) && p->x.valueBypassingBindings() != leftInset) {
344 p->x.setValueBypassingBindings(leftInset);
345 p->dirty(DirtyType::Position);
347 changeWidth = !p->width.hasBinding();
349 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
350 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
351 const auto topInset = getTopInset();
352 if (!qt_is_nan(topInset) && p->y.valueBypassingBindings() != topInset) {
354 p->y.setValueBypassingBindings(topInset);
355 p->dirty(DirtyType::Position);
357 changeHeight = !p->height.hasBinding();
359 if (changeHeight || changeWidth) {
360 auto newWidth = changeWidth ?
361 width.valueBypassingBindings() - getLeftInset() - getRightInset() :
362 p->width.valueBypassingBindings();
363 auto newHeight = changeHeight ?
364 height.valueBypassingBindings() - getTopInset() - getBottomInset() :
365 p->height.valueBypassingBindings();
366 background->setSize({newWidth, newHeight});
369 resizingBackground =
false;
372void QQuickControlPrivate::resizeContent()
376 contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding()));
377 contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight()));
381QQuickItem *QQuickControlPrivate::getContentItem()
384 executeContentItem();
388void QQuickControlPrivate::setContentItem_helper(QQuickItem *item,
bool notify)
391 if (contentItem == item)
395 warnIfCustomizationNotSupported(q, item, QStringLiteral(
"contentItem"));
397 if (!contentItem.isExecuting())
400 QQuickItem *oldContentItem = contentItem;
401 if (oldContentItem) {
402 disconnect(oldContentItem, &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
403 QQuickItemPrivate::get(oldContentItem)->removeItemChangeListener(
this, QQuickControlPrivate::Focus);
404 removeImplicitSizeListener(oldContentItem);
408 q->contentItemChange(item, oldContentItem);
409 QQuickControlPrivate::hideOldItem(oldContentItem);
412 connect(contentItem.data(), &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
416 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickControlPrivate::Focus);
417 if (!item->parentItem())
418 item->setParentItem(q);
419 if (componentComplete)
421 addImplicitSizeListener(contentItem);
424 updateImplicitContentSize();
425 updateBaselineOffset();
427 if (notify && !contentItem.isExecuting())
428 emit q->contentItemChanged();
431qreal QQuickControlPrivate::getContentWidth()
const
433 return contentItem ? contentItem->implicitWidth() : 0;
436qreal QQuickControlPrivate::getContentHeight()
const
438 return contentItem ? contentItem->implicitHeight() : 0;
441void QQuickControlPrivate::updateImplicitContentWidth()
444 const qreal oldWidth = implicitContentWidth;
445 implicitContentWidth = getContentWidth();
446 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
447 emit q->implicitContentWidthChanged();
450void QQuickControlPrivate::updateImplicitContentHeight()
453 const qreal oldHeight = implicitContentHeight;
454 implicitContentHeight = getContentHeight();
455 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
456 emit q->implicitContentHeightChanged();
459void QQuickControlPrivate::updateImplicitContentSize()
462 const qreal oldWidth = implicitContentWidth;
463 const qreal oldHeight = implicitContentHeight;
464 implicitContentWidth = getContentWidth();
465 implicitContentHeight = getContentHeight();
466 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
467 emit q->implicitContentWidthChanged();
468 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
469 emit q->implicitContentHeightChanged();
472QPalette QQuickControlPrivate::defaultPalette()
const
474 return QQuickTheme::palette(QQuickTheme::System);
477#if QT_CONFIG(accessibility)
478void QQuickControlPrivate::accessibilityActiveChanged(
bool active)
481 return q->accessibilityActiveChanged(active);
484QAccessible::Role QQuickControlPrivate::accessibleRole()
const
486 Q_Q(
const QQuickControl);
487 return q->accessibleRole();
490QQuickAccessibleAttached *QQuickControlPrivate::accessibleAttached(
const QObject *object)
492 if (!QAccessible::isActive())
494 return QQuickAccessibleAttached::attachedProperties(object);
499
500
501
502
503
504QFont QQuickControlPrivate::parentFont(
const QQuickItem *item)
506 QQuickItem *p = item->parentItem();
508 if (QQuickControl *control = qobject_cast<QQuickControl *>(p))
509 return QQuickControlPrivate::get(control)->resolvedFont;
510 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(p))
511 return label->QQuickText::font();
512 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(p))
513 return textField->QQuickTextInput::font();
514 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(p))
515 return textArea->QQuickTextEdit::font();
520 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
521 return window->font();
523 return QQuickTheme::font(QQuickTheme::System);
527
528
529
530
531
532
533
534void QQuickControlPrivate::resolveFont()
537 inheritFont(parentFont(q));
540void QQuickControlPrivate::inheritFont(
const QFont &font)
543 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
544 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
546 const QFont defaultFont = q->defaultFont();
547 QFont resolvedFont = parentFont.resolve(defaultFont);
549 setFont_helper(resolvedFont);
553
554
555
556
557void QQuickControlPrivate::updateFont(
const QFont &font)
560 QFont oldFont = resolvedFont;
564 q->fontChange(font, oldFont);
566 QQuickControlPrivate::updateFontRecur(q, font);
569 emit q->fontChanged();
572void QQuickControlPrivate::updateFontRecur(QQuickItem *item,
const QFont &font)
574 const auto childItems = item->childItems();
575 for (QQuickItem *child : childItems) {
576 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
577 QQuickControlPrivate::get(control)->inheritFont(font);
578 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(child))
579 QQuickLabelPrivate::get(label)->inheritFont(font);
580 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(child))
581 QQuickTextAreaPrivate::get(textArea)->inheritFont(font);
582 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(child))
583 QQuickTextFieldPrivate::get(textField)->inheritFont(font);
585 QQuickControlPrivate::updateFontRecur(child, font);
589QLocale QQuickControlPrivate::calcLocale(
const QQuickItem *item)
591 for (
const QQuickItem *p = item; p; p = p->parentItem())
592 if (
const QQuickControl *control = qobject_cast<
const QQuickControl *>(p))
593 return control->locale();
596 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
597 return window->locale();
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617void QQuickControlPrivate::warnIfCustomizationNotSupported(QObject *control, QQuickItem *item,
const QString &propertyName)
619 static const bool ignoreWarnings = [](){
620 return qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS");
625 if (!control->property(
"__notCustomizable").toBool()
626 || (item && item->property(
"__ignoreNotCustomizable").toBool()))
629 qmlWarning(item ? item : control).nospace() <<
"The current style does not support customization of this control "
630 <<
"(property: " << propertyName <<
" item: " << item <<
"). "
631 "Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: "
632 "https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference";
635void QQuickControlPrivate::updateLocale(
const QLocale &l,
bool e)
641 QLocale old = q->locale();
645 q->localeChange(l, old);
646 QQuickControlPrivate::updateLocaleRecur(q, l);
647 emit q->localeChanged();
651void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item,
const QLocale &l)
653 const auto childItems = item->childItems();
654 for (QQuickItem *child : childItems) {
655 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
656 QQuickControlPrivate::get(control)->updateLocale(l,
false);
658 updateLocaleRecur(child, l);
662#if QT_CONFIG(quicktemplates2_hover)
663void QQuickControlPrivate::updateHoverEnabled(
bool enabled,
bool xplicit)
666 if (!xplicit && explicitHoverEnabled)
669 bool wasEnabled = q->isHoverEnabled();
670 explicitHoverEnabled = xplicit;
671 if (wasEnabled != enabled) {
672 q->setAcceptHoverEvents(enabled);
673 QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
674 emit q->hoverEnabledChanged();
678void QQuickControlPrivate::updateHoverEnabledRecur(QQuickItem *item,
bool enabled)
680 const auto childItems = item->childItems();
681 for (QQuickItem *child : childItems) {
682 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
683 QQuickControlPrivate::get(control)->updateHoverEnabled(enabled,
false);
685 updateHoverEnabledRecur(child, enabled);
689bool QQuickControlPrivate::calcHoverEnabled(
const QQuickItem *item)
691 const QQuickItem *p = item;
696 if (qobject_cast<
const QQuickPopupItem *>(p))
699 auto *applicationWindow = qobject_cast<QQuickApplicationWindow *>(p->window());
700 if (applicationWindow) {
701 const auto *applicationWindowPrivate = QQuickApplicationWindowPrivate::get(applicationWindow);
702 if (p == applicationWindowPrivate->control) {
710 if (QQuickTemplatesUtils::isInteractiveControlType(p)) {
711 const QVariant hoverEnabledProperty = p->property(
"hoverEnabled");
712 Q_ASSERT(hoverEnabledProperty.isValid());
713 Q_ASSERT(hoverEnabledProperty.userType() == QMetaType::Bool);
714 return hoverEnabledProperty.toBool();
721 int env = qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_HOVER_ENABLED", &ok);
727 return QGuiApplication::styleHints()->useHoverEffects();
733void QQuickControlPrivate::cancelContentItem()
736 quickCancelDeferred(q, contentItemName());
739void QQuickControlPrivate::executeContentItem(
bool complete)
742 if (contentItem.wasExecuted())
745 if (!contentItem || complete)
746 quickBeginDeferred(q, contentItemName(), contentItem);
748 quickCompleteDeferred(q, contentItemName(), contentItem);
751void QQuickControlPrivate::cancelBackground()
754 quickCancelDeferred(q, backgroundName());
757void QQuickControlPrivate::executeBackground(
bool complete)
760 if (background.wasExecuted())
763 if (!background || complete)
764 quickBeginDeferred(q, backgroundName(), background);
766 quickCompleteDeferred(q, backgroundName(), background);
770
771
772
773
774
775
776void QQuickControlPrivate::hideOldItem(QQuickItem *item)
781 qCDebug(lcItemManagement) <<
"hiding old item" << item;
783 item->setVisible(
false);
784 item->setParentItem(
nullptr);
786#if QT_CONFIG(accessibility)
788 QQuickAccessibleAttached *accessible = accessibleAttached(item);
790 accessible->setIgnored(
true);
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813void QQuickControlPrivate::unhideOldItem(QQuickControl *control, QQuickItem *item, UnhideVisibility visibility)
816 qCDebug(lcItemManagement) <<
"unhiding old item" << item;
818 item->setVisible(visibility == UnhideVisibility::Show);
819 item->setParentItem(control);
821#if QT_CONFIG(accessibility)
823 QQuickAccessibleAttached *accessible = accessibleAttached(item);
825 accessible->setIgnored(
false);
829void QQuickControlPrivate::updateBaselineOffset()
832 if (extra.isAllocated() && extra.value().hasBaselineOffset)
836 q->QQuickItem::setBaselineOffset(0);
838 q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset());
841void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
843 addImplicitSizeListener(item,
this, changes);
846void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
848 removeImplicitSizeListener(item,
this, changes);
851void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
853 if (!item || !listener)
855 QQuickItemPrivate::get(item)->addItemChangeListener(listener, changes);
858void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
860 if (!item || !listener)
862 QQuickItemPrivate::get(item)->removeItemChangeListener(listener, changes);
865void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item)
868 if (item == background)
869 emit q->implicitBackgroundWidthChanged();
870 else if (item == contentItem)
871 updateImplicitContentWidth();
874void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item)
877 if (item == background)
878 emit q->implicitBackgroundHeightChanged();
879 else if (item == contentItem)
880 updateImplicitContentHeight();
883void QQuickControlPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
886 if (resizingBackground || item != background || !change.sizeChange())
889 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
892 if (change.widthChange())
893 extra.value().hasBackgroundWidth = p->widthValid();
894 if (change.heightChange())
895 extra.value().hasBackgroundHeight = p->heightValid();
899void QQuickControlPrivate::itemDestroyed(QQuickItem *item)
902 if (item == background) {
903 background =
nullptr;
904 emit q->implicitBackgroundWidthChanged();
905 emit q->implicitBackgroundHeightChanged();
906 }
else if (item == contentItem) {
907 contentItem =
nullptr;
908 updateImplicitContentSize();
912void QQuickControlPrivate::itemFocusChanged(QQuickItem *item, Qt::FocusReason reason)
915 if (item == contentItem || item == q)
916 setLastFocusChangeReason(reason);
919bool QQuickControlPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
922 Qt::FocusReason oldReason =
static_cast<Qt::FocusReason>(focusReason);
923 const auto focusReasonChanged = QQuickItemPrivate::setLastFocusChangeReason(reason);
924 if (focusReasonChanged)
925 emit q->focusReasonChanged();
926 if (isKeyFocusReason(oldReason) != isKeyFocusReason(reason))
927 emit q->visualFocusChanged();
929 return focusReasonChanged;
932QQuickControl::QQuickControl(QQuickItem *parent)
933 : QQuickItem(*(
new QQuickControlPrivate), parent)
939QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent)
940 : QQuickItem(dd, parent)
946QQuickControl::~QQuickControl()
949 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
950 d->removeImplicitSizeListener(d->contentItem);
952 QQuickItemPrivate::get(d->contentItem)->removeItemChangeListener(d, QQuickItemPrivate::Focus);
953#if QT_CONFIG(accessibility)
954 QAccessible::removeActivationObserver(d);
958void QQuickControl::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
961 QQuickItem::itemChange(change, value);
963 case ItemEnabledHasChanged:
966 case ItemVisibleHasChanged:
967#if QT_CONFIG(quicktemplates2_hover)
968 if (!value.boolValue)
972 case ItemSceneChange:
973 case ItemParentHasChanged:
974 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
977 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
978#if QT_CONFIG(quicktemplates2_hover)
979 if (!d->explicitHoverEnabled)
980 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
984 case ItemActiveFocusHasChanged:
985 if (isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason)))
986 emit visualFocusChanged();
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037QFont QQuickControl::font()
const
1039 Q_D(
const QQuickControl);
1040 QFont font = d->resolvedFont;
1042 font.setResolveMask(d->extra.value().requestedFont.resolveMask());
1046void QQuickControl::setFont(
const QFont &font)
1049 if (d->extra.value().requestedFont.resolveMask() == font.resolveMask() && d->extra.value().requestedFont == font)
1052 d->extra.value().requestedFont = font;
1056void QQuickControl::resetFont()
1062
1063
1064
1065
1066
1067
1068
1069
1070qreal QQuickControl::availableWidth()
const
1072 return qMax<qreal>(0.0, width() - leftPadding() - rightPadding());
1076
1077
1078
1079
1080
1081
1082
1083
1084qreal QQuickControl::availableHeight()
const
1086 return qMax<qreal>(0.0, height() - topPadding() - bottomPadding());
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128qreal QQuickControl::padding()
const
1130 Q_D(
const QQuickControl);
1134void QQuickControl::setPadding(qreal padding)
1137 if (qFuzzyCompare(d->padding, padding))
1140 const QMarginsF oldPadding = d->getPadding();
1141 const qreal oldVerticalPadding = d->getVerticalPadding();
1142 const qreal oldHorizontalPadding = d->getHorizontalPadding();
1144 d->padding = padding;
1145 emit paddingChanged();
1147 const QMarginsF newPadding = d->getPadding();
1148 const qreal newVerticalPadding = d->getVerticalPadding();
1149 const qreal newHorizontalPadding = d->getHorizontalPadding();
1151 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
1152 emit topPaddingChanged();
1153 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
1154 emit leftPaddingChanged();
1155 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
1156 emit rightPaddingChanged();
1157 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1158 emit bottomPaddingChanged();
1159 if (!qFuzzyCompare(newVerticalPadding, oldVerticalPadding))
1160 emit verticalPaddingChanged();
1161 if (!qFuzzyCompare(newHorizontalPadding, oldHorizontalPadding))
1162 emit horizontalPaddingChanged();
1163 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1164 emit availableHeightChanged();
1165 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right()))
1166 emit availableWidthChanged();
1168 paddingChange(newPadding, oldPadding);
1171void QQuickControl::resetPadding()
1177
1178
1179
1180
1181
1182
1183
1184qreal QQuickControl::topPadding()
const
1186 Q_D(
const QQuickControl);
1187 return d->getTopPadding();
1190void QQuickControl::setTopPadding(qreal padding)
1193 d->setTopPadding(padding);
1196void QQuickControl::resetTopPadding()
1199 d->setTopPadding(0,
true);
1203
1204
1205
1206
1207
1208
1209
1210qreal QQuickControl::leftPadding()
const
1212 Q_D(
const QQuickControl);
1213 return d->getLeftPadding();
1216void QQuickControl::setLeftPadding(qreal padding)
1219 d->setLeftPadding(padding);
1222void QQuickControl::resetLeftPadding()
1225 d->setLeftPadding(0,
true);
1229
1230
1231
1232
1233
1234
1235
1236qreal QQuickControl::rightPadding()
const
1238 Q_D(
const QQuickControl);
1239 return d->getRightPadding();
1242void QQuickControl::setRightPadding(qreal padding)
1245 d->setRightPadding(padding);
1248void QQuickControl::resetRightPadding()
1251 d->setRightPadding(0,
true);
1255
1256
1257
1258
1259
1260
1261
1262qreal QQuickControl::bottomPadding()
const
1264 Q_D(
const QQuickControl);
1265 return d->getBottomPadding();
1268void QQuickControl::setBottomPadding(qreal padding)
1271 d->setBottomPadding(padding);
1274void QQuickControl::resetBottomPadding()
1277 d->setBottomPadding(0,
true);
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291qreal QQuickControl::spacing()
const
1293 Q_D(
const QQuickControl);
1297void QQuickControl::setSpacing(qreal spacing)
1300 if (qFuzzyCompare(d->spacing, spacing))
1303 qreal oldSpacing = d->spacing;
1304 d->spacing = spacing;
1305 emit spacingChanged();
1306 spacingChange(spacing, oldSpacing);
1309void QQuickControl::resetSpacing()
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329QLocale QQuickControl::locale()
const
1331 Q_D(
const QQuickControl);
1335void QQuickControl::setLocale(
const QLocale &locale)
1338 if (d->hasLocale && d->locale == locale)
1341 d->updateLocale(locale,
true);
1344void QQuickControl::resetLocale()
1350 d->hasLocale =
false;
1351 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368bool QQuickControl::isMirrored()
const
1370 Q_D(
const QQuickControl);
1371 return d->isMirrored();
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399Qt::FocusReason QQuickControl::focusReason()
const
1401 Q_D(
const QQuickControl);
1402 return d->lastFocusChangeReason();
1405void QQuickControl::setFocusReason(Qt::FocusReason reason)
1408 d->setLastFocusChangeReason(reason);
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425bool QQuickControl::hasVisualFocus()
const
1427 Q_D(
const QQuickControl);
1428 return d->activeFocus && isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason));
1432
1433
1434
1435
1436
1437
1438
1439bool QQuickControl::isHovered()
const
1441#if QT_CONFIG(quicktemplates2_hover)
1442 Q_D(
const QQuickControl);
1449void QQuickControl::setHovered(
bool hovered)
1451#if QT_CONFIG(quicktemplates2_hover)
1453 if (hovered == d->hovered)
1456 d->hovered = hovered;
1457 emit hoveredChanged();
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479bool QQuickControl::isHoverEnabled()
const
1481#if QT_CONFIG(quicktemplates2_hover)
1482 Q_D(
const QQuickControl);
1483 return d->hoverEnabled;
1489void QQuickControl::setHoverEnabled(
bool enabled)
1491#if QT_CONFIG(quicktemplates2_hover)
1493 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
1496 d->updateHoverEnabled(enabled,
true);
1502void QQuickControl::resetHoverEnabled()
1504#if QT_CONFIG(quicktemplates2_hover)
1506 if (!d->explicitHoverEnabled)
1509 d->explicitHoverEnabled =
false;
1510 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
1515
1516
1517
1518
1519
1520
1521
1522
1523bool QQuickControl::isWheelEnabled()
const
1525 Q_D(
const QQuickControl);
1526 return d->wheelEnabled;
1529void QQuickControl::setWheelEnabled(
bool enabled)
1532 if (d->wheelEnabled == enabled)
1535 d->wheelEnabled = enabled;
1536 emit wheelEnabledChanged();
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561QQuickItem *QQuickControl::background()
const
1563 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1565 d->executeBackground();
1566 return d->background;
1569void QQuickControl::setBackground(QQuickItem *background)
1572 if (d->background == background)
1575 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, background, QStringLiteral(
"background"));
1577 if (!d->background.isExecuting())
1578 d->cancelBackground();
1580 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
1581 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
1583 if (d->extra.isAllocated()) {
1584 d->extra.value().hasBackgroundWidth =
false;
1585 d->extra.value().hasBackgroundHeight =
false;
1588 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1589 QQuickControlPrivate::hideOldItem(d->background);
1590 d->background = background;
1593 background->setParentItem(
this);
1594 if (qFuzzyIsNull(background->z()))
1595 background->setZ(-1);
1596 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
1597 if (p->widthValid() || p->heightValid()) {
1598 d->extra.value().hasBackgroundWidth = p->widthValid();
1599 d->extra.value().hasBackgroundHeight = p->heightValid();
1601 if (isComponentComplete())
1602 d->resizeBackground();
1603 d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1606 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
1607 emit implicitBackgroundWidthChanged();
1608 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
1609 emit implicitBackgroundHeightChanged();
1610 if (!d->background.isExecuting())
1611 emit backgroundChanged();
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644QQuickItem *QQuickControl::contentItem()
const
1646 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1647 if (!d->contentItem)
1648 d->setContentItem_helper(d->getContentItem(),
false);
1649 return d->contentItem;
1652void QQuickControl::setContentItem(QQuickItem *item)
1655 d->setContentItem_helper(item,
true);
1658qreal QQuickControl::baselineOffset()
const
1660 Q_D(
const QQuickControl);
1661 return d->baselineOffset;
1664void QQuickControl::setBaselineOffset(qreal offset)
1667 d->extra.value().hasBaselineOffset =
true;
1668 QQuickItem::setBaselineOffset(offset);
1671void QQuickControl::resetBaselineOffset()
1674 if (!d->extra.isAllocated() || !d->extra.value().hasBaselineOffset)
1677 if (d->extra.isAllocated())
1678 d->extra.value().hasBaselineOffset =
false;
1679 d->updateBaselineOffset();
1683
1684
1685
1686
1687
1688
1689
1690
1691qreal QQuickControl::horizontalPadding()
const
1693 Q_D(
const QQuickControl);
1694 return d->getHorizontalPadding();
1697void QQuickControl::setHorizontalPadding(qreal padding)
1700 d->setHorizontalPadding(padding);
1703void QQuickControl::resetHorizontalPadding()
1706 d->setHorizontalPadding(0,
true);
1710
1711
1712
1713
1714
1715
1716
1717
1718qreal QQuickControl::verticalPadding()
const
1720 Q_D(
const QQuickControl);
1721 return d->getVerticalPadding();
1724void QQuickControl::setVerticalPadding(qreal padding)
1727 d->setVerticalPadding(padding);
1730void QQuickControl::resetVerticalPadding()
1733 d->setVerticalPadding(0,
true);
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758qreal QQuickControl::implicitContentWidth()
const
1760 Q_D(
const QQuickControl);
1762 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1763 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1769 static constexpr auto kLastKnownGoodImplicitWidth =
"_q_lastKnownGoodImplicitWidth";
1770 if (safeArea->detectedPossibleBindingLoop) {
1771 const auto lastImplicitWidth = safeArea->property(kLastKnownGoodImplicitWidth).value<
int>();
1772 return lastImplicitWidth - leftPadding() - rightPadding();
1774 safeArea->setProperty(kLastKnownGoodImplicitWidth, implicitWidth());
1778 return d->implicitContentWidth;
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803qreal QQuickControl::implicitContentHeight()
const
1805 Q_D(
const QQuickControl);
1807 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1808 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1814 static constexpr auto kLastKnownGoodImplicitHeight =
"_q_lastKnownGoodImplicitHeight";
1815 if (safeArea->detectedPossibleBindingLoop) {
1816 const auto lastImplicitHeight = safeArea->property(kLastKnownGoodImplicitHeight).value<
int>();
1817 return lastImplicitHeight - topPadding() - bottomPadding();
1819 safeArea->setProperty(kLastKnownGoodImplicitHeight, implicitHeight());
1823 return d->implicitContentHeight;
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847qreal QQuickControl::implicitBackgroundWidth()
const
1849 Q_D(
const QQuickControl);
1852 return d->background->implicitWidth();
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876qreal QQuickControl::implicitBackgroundHeight()
const
1878 Q_D(
const QQuickControl);
1881 return d->background->implicitHeight();
1885
1886
1887
1888
1889
1890
1891
1892qreal QQuickControl::topInset()
const
1894 Q_D(
const QQuickControl);
1895 return d->getTopInset();
1898void QQuickControl::setTopInset(qreal inset)
1901 d->setTopInset(inset);
1904void QQuickControl::resetTopInset()
1907 d->setTopInset(0,
true);
1911
1912
1913
1914
1915
1916
1917
1918qreal QQuickControl::leftInset()
const
1920 Q_D(
const QQuickControl);
1921 return d->getLeftInset();
1924void QQuickControl::setLeftInset(qreal inset)
1927 d->setLeftInset(inset);
1930void QQuickControl::resetLeftInset()
1933 d->setLeftInset(0,
true);
1937
1938
1939
1940
1941
1942
1943
1944qreal QQuickControl::rightInset()
const
1946 Q_D(
const QQuickControl);
1947 return d->getRightInset();
1950void QQuickControl::setRightInset(qreal inset)
1953 d->setRightInset(inset);
1956void QQuickControl::resetRightInset()
1959 d->setRightInset(0,
true);
1963
1964
1965
1966
1967
1968
1969
1970qreal QQuickControl::bottomInset()
const
1972 Q_D(
const QQuickControl);
1973 return d->getBottomInset();
1976void QQuickControl::setBottomInset(qreal inset)
1979 d->setBottomInset(inset);
1982void QQuickControl::resetBottomInset()
1985 d->setBottomInset(0,
true);
1988void QQuickControl::classBegin()
1991 QQuickItem::classBegin();
1995void QQuickControl::componentComplete()
1998 d->executeBackground(
true);
1999 d->executeContentItem(
true);
2000 QQuickItem::componentComplete();
2001 d->resizeBackground();
2003 d->updateBaselineOffset();
2005 d->locale = QQuickControlPrivate::calcLocale(d->parentItem);
2006#if QT_CONFIG(quicktemplates2_hover)
2007 if (!d->explicitHoverEnabled)
2008 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
2010#if QT_CONFIG(accessibility)
2011 if (QAccessible::isActive())
2012 accessibilityActiveChanged(
true);
2016QFont QQuickControl::defaultFont()
const
2018 return QQuickTheme::font(QQuickTheme::System);
2021void QQuickControl::focusInEvent(QFocusEvent *event)
2023 QQuickItem::focusInEvent(event);
2026void QQuickControl::focusOutEvent(QFocusEvent *event)
2028 QQuickItem::focusOutEvent(event);
2031#if QT_CONFIG(quicktemplates2_hover)
2032void QQuickControl::hoverEnterEvent(QHoverEvent *event)
2035 setHovered(d->hoverEnabled);
2039void QQuickControl::hoverMoveEvent(QHoverEvent *event)
2042 setHovered(d->hoverEnabled && contains(event->position()));
2046void QQuickControl::hoverLeaveEvent(QHoverEvent *event)
2053void QQuickControl::mousePressEvent(QMouseEvent *event)
2056 event->setAccepted(d->handlePress(event->position(), event->timestamp()));
2059void QQuickControl::mouseMoveEvent(QMouseEvent *event)
2062 event->setAccepted(d->handleMove(event->position(), event->timestamp()));
2065void QQuickControl::mouseReleaseEvent(QMouseEvent *event)
2068 event->setAccepted(d->handleRelease(event->position(), event->timestamp()));
2071void QQuickControl::mouseUngrabEvent()
2077#if QT_CONFIG(quicktemplates2_multitouch)
2078void QQuickControl::touchEvent(QTouchEvent *event)
2081 switch (event->type()) {
2082 case QEvent::TouchBegin:
2083 case QEvent::TouchUpdate:
2084 case QEvent::TouchEnd:
2085 for (
const QTouchEvent::TouchPoint &point : event->points()) {
2086 if (!d->acceptTouch(point))
2089 switch (point.state()) {
2090 case QEventPoint::Pressed:
2091 d->handlePress(point.position(), event->timestamp());
2093 case QEventPoint::Updated:
2094 d->handleMove(point.position(), event->timestamp());
2096 case QEventPoint::Released:
2097 d->handleRelease(point.position(), event->timestamp());
2105 case QEvent::TouchCancel:
2110 QQuickItem::touchEvent(event);
2115void QQuickControl::touchUngrabEvent()
2122#if QT_CONFIG(wheelevent)
2123void QQuickControl::wheelEvent(QWheelEvent *event)
2126 event->setAccepted(d->wheelEnabled);
2130void QQuickControl::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
2133 QQuickItem::geometryChange(newGeometry, oldGeometry);
2134 d->resizeBackground();
2136 if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width()))
2137 emit availableWidthChanged();
2138 if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height()))
2139 emit availableHeightChanged();
2142void QQuickControl::enabledChange()
2146void QQuickControl::fontChange(
const QFont &newFont,
const QFont &oldFont)
2152#if QT_CONFIG(quicktemplates2_hover)
2153void QQuickControl::hoverChange()
2158void QQuickControl::mirrorChange()
2160 emit mirroredChanged();
2163void QQuickControl::spacingChange(qreal newSpacing, qreal oldSpacing)
2165 Q_UNUSED(newSpacing);
2166 Q_UNUSED(oldSpacing);
2169void QQuickControl::paddingChange(
const QMarginsF &newPadding,
const QMarginsF &oldPadding)
2172 Q_UNUSED(newPadding);
2173 Q_UNUSED(oldPadding);
2175 d->updateBaselineOffset();
2178void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
2184void QQuickControl::localeChange(
const QLocale &newLocale,
const QLocale &oldLocale)
2186 Q_UNUSED(newLocale);
2187 Q_UNUSED(oldLocale);
2190void QQuickControl::insetChange(
const QMarginsF &newInset,
const QMarginsF &oldInset)
2195 d->resizeBackground();
2198#if QT_CONFIG(accessibility)
2199QAccessible::Role QQuickControl::accessibleRole()
const
2201 return QAccessible::NoRole;
2204void QQuickControl::accessibilityActiveChanged(
bool active)
2210 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
2211 Q_ASSERT(accessibleAttached);
2212 accessibleAttached->setRole(d->effectiveAccessibleRole());
2216QString QQuickControl::accessibleName()
const
2218#if QT_CONFIG(accessibility)
2219 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this))
2220 return accessibleAttached->name();
2225void QQuickControl::maybeSetAccessibleName(
const QString &name)
2227#if QT_CONFIG(accessibility)
2228 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this)) {
2229 if (!accessibleAttached->wasNameExplicitlySet())
2230 accessibleAttached->setNameImplicitly(name);
2237QVariant QQuickControl::accessibleProperty(
const char *propertyName)
2239#if QT_CONFIG(accessibility)
2240 if (QAccessible::isActive())
2241 return QQuickAccessibleAttached::property(
this, propertyName);
2243 Q_UNUSED(propertyName);
2247bool QQuickControl::setAccessibleProperty(
const char *propertyName,
const QVariant &value)
2249#if QT_CONFIG(accessibility)
2250 if (QAccessible::isActive())
2251 return QQuickAccessibleAttached::setProperty(
this, propertyName, value);
2253 Q_UNUSED(propertyName);
2260#include "moc_qquickcontrol_p.cpp"
static bool isKeyFocusReason(Qt::FocusReason reason)
static QString contentItemName()