8#include <QtGui/qstylehints.h>
9#include <QtGui/qguiapplication.h>
26#if QT_CONFIG(accessibility)
27#include <QtQuick/private/qquickaccessibleattached_p.h>
32Q_LOGGING_CATEGORY(lcItemManagement,
"qt.quick.controls.control.itemmanagement")
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
118
119
120
122const QQuickItemPrivate::ChangeTypes QQuickControlPrivate::ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed;
126 return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason || reason == Qt::ShortcutFocusReason;
129QQuickControlPrivate::QQuickControlPrivate()
131#if QT_CONFIG(accessibility)
132 QAccessible::installActivationObserver(
this);
136QQuickControlPrivate::~QQuickControlPrivate()
140void QQuickControlPrivate::init()
143 QObject::connect(q, &QQuickItem::baselineOffsetChanged, q, &QQuickControl::baselineOffsetChanged);
144#if QT_CONFIG(accessibility)
149#if QT_CONFIG(quicktemplates2_multitouch)
150bool QQuickControlPrivate::acceptTouch(
const QTouchEvent::TouchPoint &point)
152 if (point.id() == touchId)
155 if (touchId == -1 && point.state() == QEventPoint::Pressed) {
156 touchId = point.id();
164bool QQuickControlPrivate::handlePress(
const QPointF &, ulong)
169bool QQuickControlPrivate::handleMove(
const QPointF &point, ulong)
171#if QT_CONFIG(quicktemplates2_hover)
173 q->setHovered(hoverEnabled && q->contains(point));
180bool QQuickControlPrivate::handleRelease(
const QPointF &, ulong)
186void QQuickControlPrivate::handleUngrab()
191void QQuickControlPrivate::mirrorChange()
197void QQuickControlPrivate::setTopPadding(qreal value,
bool reset)
200 const QMarginsF oldPadding = getPadding();
201 extra.value().topPadding = value;
202 extra.value().hasTopPadding = !reset;
203 if ((!reset && !qFuzzyCompare(oldPadding.top(), value)) || (reset && !qFuzzyCompare(oldPadding.top(), getVerticalPadding()))) {
204 emit q->topPaddingChanged();
205 emit q->availableHeightChanged();
206 q->paddingChange(getPadding(), oldPadding);
210void QQuickControlPrivate::setLeftPadding(qreal value,
bool reset)
213 const QMarginsF oldPadding = getPadding();
214 extra.value().leftPadding = value;
215 extra.value().hasLeftPadding = !reset;
216 if ((!reset && !qFuzzyCompare(oldPadding.left(), value)) || (reset && !qFuzzyCompare(oldPadding.left(), getHorizontalPadding()))) {
217 emit q->leftPaddingChanged();
218 emit q->availableWidthChanged();
219 q->paddingChange(getPadding(), oldPadding);
223void QQuickControlPrivate::setRightPadding(qreal value,
bool reset)
226 const QMarginsF oldPadding = getPadding();
227 extra.value().rightPadding = value;
228 extra.value().hasRightPadding = !reset;
229 if ((!reset && !qFuzzyCompare(oldPadding.right(), value)) || (reset && !qFuzzyCompare(oldPadding.right(), getHorizontalPadding()))) {
230 emit q->rightPaddingChanged();
231 emit q->availableWidthChanged();
232 q->paddingChange(getPadding(), oldPadding);
236void QQuickControlPrivate::setBottomPadding(qreal value,
bool reset)
239 const QMarginsF oldPadding = getPadding();
240 extra.value().bottomPadding = value;
241 extra.value().hasBottomPadding = !reset;
242 if ((!reset && !qFuzzyCompare(oldPadding.bottom(), value)) || (reset && !qFuzzyCompare(oldPadding.bottom(), getVerticalPadding()))) {
243 emit q->bottomPaddingChanged();
244 emit q->availableHeightChanged();
245 q->paddingChange(getPadding(), oldPadding);
249void QQuickControlPrivate::setHorizontalPadding(qreal value,
bool reset)
252 const QMarginsF oldPadding = getPadding();
253 const qreal oldHorizontalPadding = getHorizontalPadding();
254 horizontalPadding = value;
255 hasHorizontalPadding = !reset;
256 if ((!reset && !qFuzzyCompare(oldHorizontalPadding, value)) || (reset && !qFuzzyCompare(oldHorizontalPadding, padding))) {
257 const QMarginsF newPadding = getPadding();
258 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
259 emit q->leftPaddingChanged();
260 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
261 emit q->rightPaddingChanged();
262 emit q->horizontalPaddingChanged();
263 emit q->availableWidthChanged();
264 q->paddingChange(newPadding, oldPadding);
268void QQuickControlPrivate::setVerticalPadding(qreal value,
bool reset)
271 const QMarginsF oldPadding = getPadding();
272 const qreal oldVerticalPadding = getVerticalPadding();
273 verticalPadding = value;
274 hasVerticalPadding = !reset;
275 if ((!reset && !qFuzzyCompare(oldVerticalPadding, value)) || (reset && !qFuzzyCompare(oldVerticalPadding, padding))) {
276 const QMarginsF newPadding = getPadding();
277 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
278 emit q->topPaddingChanged();
279 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
280 emit q->bottomPaddingChanged();
281 emit q->verticalPaddingChanged();
282 emit q->availableHeightChanged();
283 q->paddingChange(newPadding, oldPadding);
287void QQuickControlPrivate::setTopInset(qreal value,
bool reset)
290 const QMarginsF oldInset = getInset();
291 extra.value().topInset = value;
292 extra.value().hasTopInset = !reset;
293 if (!qFuzzyCompare(oldInset.top(), value)) {
294 emit q->topInsetChanged();
295 q->insetChange(getInset(), oldInset);
299void QQuickControlPrivate::setLeftInset(qreal value,
bool reset)
302 const QMarginsF oldInset = getInset();
303 extra.value().leftInset = value;
304 extra.value().hasLeftInset = !reset;
305 if (!qFuzzyCompare(oldInset.left(), value)) {
306 emit q->leftInsetChanged();
307 q->insetChange(getInset(), oldInset);
311void QQuickControlPrivate::setRightInset(qreal value,
bool reset)
314 const QMarginsF oldInset = getInset();
315 extra.value().rightInset = value;
316 extra.value().hasRightInset = !reset;
317 if (!qFuzzyCompare(oldInset.right(), value)) {
318 emit q->rightInsetChanged();
319 q->insetChange(getInset(), oldInset);
323void QQuickControlPrivate::setBottomInset(qreal value,
bool reset)
326 const QMarginsF oldInset = getInset();
327 extra.value().bottomInset = value;
328 extra.value().hasBottomInset = !reset;
329 if (!qFuzzyCompare(oldInset.bottom(), value)) {
330 emit q->bottomInsetChanged();
331 q->insetChange(getInset(), oldInset);
335void QQuickControlPrivate::resizeBackground()
340 resizingBackground =
true;
342 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
343 bool changeWidth =
false;
344 bool changeHeight =
false;
345 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
346 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
347 const auto leftInset = getLeftInset();
348 if (!qt_is_nan(leftInset) && p->x.valueBypassingBindings() != leftInset) {
350 p->x.setValueBypassingBindings(leftInset);
351 p->dirty(DirtyType::Position);
353 changeWidth = !p->width.hasBinding();
355 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
356 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
357 const auto topInset = getTopInset();
358 if (!qt_is_nan(topInset) && p->y.valueBypassingBindings() != topInset) {
360 p->y.setValueBypassingBindings(topInset);
361 p->dirty(DirtyType::Position);
363 changeHeight = !p->height.hasBinding();
365 if (changeHeight || changeWidth) {
366 auto newWidth = changeWidth ?
367 width.valueBypassingBindings() - getLeftInset() - getRightInset() :
368 p->width.valueBypassingBindings();
369 auto newHeight = changeHeight ?
370 height.valueBypassingBindings() - getTopInset() - getBottomInset() :
371 p->height.valueBypassingBindings();
372 background->setSize({newWidth, newHeight});
375 resizingBackground =
false;
378void QQuickControlPrivate::resizeContent()
382 contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding()));
383 contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight()));
387QQuickItem *QQuickControlPrivate::getContentItem()
390 executeContentItem();
394void QQuickControlPrivate::setContentItem_helper(QQuickItem *item,
bool notify)
397 if (contentItem == item)
401 warnIfCustomizationNotSupported(q, item, QStringLiteral(
"contentItem"));
403 if (!contentItem.isExecuting())
406 QQuickItem *oldContentItem = contentItem;
407 if (oldContentItem) {
408 disconnect(oldContentItem, &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
409 QQuickItemPrivate::get(oldContentItem)->removeItemChangeListener(
this, QQuickControlPrivate::Focus);
410 removeImplicitSizeListener(oldContentItem);
414 q->contentItemChange(item, oldContentItem);
415 QQuickControlPrivate::hideOldItem(oldContentItem);
418 connect(contentItem.data(), &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
422 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickControlPrivate::Focus);
423 if (!item->parentItem())
424 item->setParentItem(q);
425 if (componentComplete)
427 addImplicitSizeListener(contentItem);
430 updateImplicitContentSize();
431 updateBaselineOffset();
433 if (notify && !contentItem.isExecuting())
434 emit q->contentItemChanged();
437qreal QQuickControlPrivate::getContentWidth()
const
439 return contentItem ? contentItem->implicitWidth() : 0;
442qreal QQuickControlPrivate::getContentHeight()
const
444 return contentItem ? contentItem->implicitHeight() : 0;
447void QQuickControlPrivate::updateImplicitContentWidth()
450 const qreal oldWidth = implicitContentWidth;
451 implicitContentWidth = getContentWidth();
452 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
453 emit q->implicitContentWidthChanged();
456void QQuickControlPrivate::updateImplicitContentHeight()
459 const qreal oldHeight = implicitContentHeight;
460 implicitContentHeight = getContentHeight();
461 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
462 emit q->implicitContentHeightChanged();
465void QQuickControlPrivate::updateImplicitContentSize()
468 const qreal oldWidth = implicitContentWidth;
469 const qreal oldHeight = implicitContentHeight;
470 implicitContentWidth = getContentWidth();
471 implicitContentHeight = getContentHeight();
472 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
473 emit q->implicitContentWidthChanged();
474 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
475 emit q->implicitContentHeightChanged();
478QPalette QQuickControlPrivate::defaultPalette()
const
480 return QQuickTheme::palette(QQuickTheme::System);
483#if QT_CONFIG(accessibility)
484void QQuickControlPrivate::accessibilityActiveChanged(
bool active)
487 return q->accessibilityActiveChanged(active);
490QAccessible::Role QQuickControlPrivate::accessibleRole()
const
492 Q_Q(
const QQuickControl);
493 return q->accessibleRole();
496QQuickAccessibleAttached *QQuickControlPrivate::accessibleAttached(
const QObject *object)
498 if (!QAccessible::isActive())
500 return QQuickAccessibleAttached::attachedProperties(object);
505
506
507
508
509
510QFont QQuickControlPrivate::parentFont(
const QQuickItem *item)
512 QQuickItem *p = item->parentItem();
514 if (QQuickControl *control = qobject_cast<QQuickControl *>(p))
515 return QQuickControlPrivate::get(control)->resolvedFont;
516 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(p))
517 return label->QQuickText::font();
518 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(p))
519 return textField->QQuickTextInput::font();
520 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(p))
521 return textArea->QQuickTextEdit::font();
526 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
527 return window->font();
529 return QQuickTheme::font(QQuickTheme::System);
533
534
535
536
537
538
539
540void QQuickControlPrivate::resolveFont()
543 inheritFont(parentFont(q));
546void QQuickControlPrivate::inheritFont(
const QFont &font)
549 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
550 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
552 const QFont defaultFont = q->defaultFont();
553 QFont resolvedFont = parentFont.resolve(defaultFont);
555 setFont_helper(resolvedFont);
559
560
561
562
563void QQuickControlPrivate::updateFont(
const QFont &font)
566 QFont oldFont = resolvedFont;
570 q->fontChange(font, oldFont);
572 QQuickControlPrivate::updateFontRecur(q, font);
575 emit q->fontChanged();
578void QQuickControlPrivate::updateFontRecur(QQuickItem *item,
const QFont &font)
580 const auto childItems = item->childItems();
581 for (QQuickItem *child : childItems) {
582 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
583 QQuickControlPrivate::get(control)->inheritFont(font);
584 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(child))
585 QQuickLabelPrivate::get(label)->inheritFont(font);
586 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(child))
587 QQuickTextAreaPrivate::get(textArea)->inheritFont(font);
588 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(child))
589 QQuickTextFieldPrivate::get(textField)->inheritFont(font);
591 QQuickControlPrivate::updateFontRecur(child, font);
595QLocale QQuickControlPrivate::calcLocale(
const QQuickItem *item)
597 for (
const QQuickItem *p = item; p; p = p->parentItem())
598 if (
const QQuickControl *control = qobject_cast<
const QQuickControl *>(p))
599 return control->locale();
602 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
603 return window->locale();
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623void QQuickControlPrivate::warnIfCustomizationNotSupported(QObject *control, QQuickItem *item,
const QString &propertyName)
625 static const bool ignoreWarnings = [](){
626 return qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS");
631 if (!control->property(
"__notCustomizable").toBool()
632 || (item && item->property(
"__ignoreNotCustomizable").toBool()))
635 qmlWarning(item ? item : control).nospace() <<
"The current style does not support customization of this control "
636 <<
"(property: " << propertyName <<
" item: " << item <<
"). "
637 "Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: "
638 "https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference";
641void QQuickControlPrivate::updateLocale(
const QLocale &l,
bool e)
647 QLocale old = q->locale();
651 q->localeChange(l, old);
652 QQuickControlPrivate::updateLocaleRecur(q, l);
653 emit q->localeChanged();
657void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item,
const QLocale &l)
659 const auto childItems = item->childItems();
660 for (QQuickItem *child : childItems) {
661 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
662 QQuickControlPrivate::get(control)->updateLocale(l,
false);
664 updateLocaleRecur(child, l);
668#if QT_CONFIG(quicktemplates2_hover)
669void QQuickControlPrivate::updateHoverEnabled(
bool enabled,
bool xplicit)
672 if (!xplicit && explicitHoverEnabled)
675 bool wasEnabled = q->isHoverEnabled();
676 explicitHoverEnabled = xplicit;
677 if (wasEnabled != enabled) {
678 q->setAcceptHoverEvents(enabled);
679 QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
680 emit q->hoverEnabledChanged();
684void QQuickControlPrivate::updateHoverEnabledRecur(QQuickItem *item,
bool enabled)
686 const auto childItems = item->childItems();
687 for (QQuickItem *child : childItems) {
688 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
689 QQuickControlPrivate::get(control)->updateHoverEnabled(enabled,
false);
691 updateHoverEnabledRecur(child, enabled);
695bool QQuickControlPrivate::calcHoverEnabled(
const QQuickItem *item)
697 const QQuickItem *p = item;
702 if (qobject_cast<
const QQuickPopupItem *>(p))
705 auto *applicationWindow = qobject_cast<QQuickApplicationWindow *>(p->window());
706 if (applicationWindow) {
707 const auto *applicationWindowPrivate = QQuickApplicationWindowPrivate::get(applicationWindow);
708 if (p == applicationWindowPrivate->control) {
716 if (QQuickTemplatesUtils::isInteractiveControlType(p)) {
717 const QVariant hoverEnabledProperty = p->property(
"hoverEnabled");
718 Q_ASSERT(hoverEnabledProperty.isValid());
719 Q_ASSERT(hoverEnabledProperty.userType() == QMetaType::Bool);
720 return hoverEnabledProperty.toBool();
727 int env = qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_HOVER_ENABLED", &ok);
733 return QGuiApplication::styleHints()->useHoverEffects();
739void QQuickControlPrivate::cancelContentItem()
742 quickCancelDeferred(q, contentItemName());
745void QQuickControlPrivate::executeContentItem(
bool complete)
748 if (contentItem.wasExecuted())
751 if (!contentItem || complete)
752 quickBeginDeferred(q, contentItemName(), contentItem);
754 quickCompleteDeferred(q, contentItemName(), contentItem);
757void QQuickControlPrivate::cancelBackground()
760 quickCancelDeferred(q, backgroundName());
763void QQuickControlPrivate::executeBackground(
bool complete)
766 if (background.wasExecuted())
769 if (!background || complete)
770 quickBeginDeferred(q, backgroundName(), background);
772 quickCompleteDeferred(q, backgroundName(), background);
776
777
778
779
780
781
782void QQuickControlPrivate::hideOldItem(QQuickItem *item)
787 qCDebug(lcItemManagement) <<
"hiding old item" << item;
789 item->setVisible(
false);
790 item->setParentItem(
nullptr);
792#if QT_CONFIG(accessibility)
794 QQuickAccessibleAttached *accessible = accessibleAttached(item);
796 accessible->setIgnored(
true);
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819void QQuickControlPrivate::unhideOldItem(QQuickControl *control, QQuickItem *item, UnhideVisibility visibility)
822 qCDebug(lcItemManagement) <<
"unhiding old item" << item;
824 item->setVisible(visibility == UnhideVisibility::Show);
825 item->setParentItem(control);
827#if QT_CONFIG(accessibility)
829 QQuickAccessibleAttached *accessible = accessibleAttached(item);
831 accessible->setIgnored(
false);
835void QQuickControlPrivate::updateBaselineOffset()
838 if (extra.isAllocated() && extra.value().hasBaselineOffset)
842 q->QQuickItem::setBaselineOffset(0);
844 q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset());
847void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
849 addImplicitSizeListener(item,
this, changes);
852void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
854 removeImplicitSizeListener(item,
this, changes);
857void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
859 if (!item || !listener)
861 QQuickItemPrivate::get(item)->addItemChangeListener(listener, changes);
864void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
866 if (!item || !listener)
868 QQuickItemPrivate::get(item)->removeItemChangeListener(listener, changes);
871void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item)
874 if (item == background)
875 emit q->implicitBackgroundWidthChanged();
876 else if (item == contentItem)
877 updateImplicitContentWidth();
880void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item)
883 if (item == background)
884 emit q->implicitBackgroundHeightChanged();
885 else if (item == contentItem)
886 updateImplicitContentHeight();
889void QQuickControlPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
892 if (resizingBackground || item != background || !change.sizeChange())
895 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
898 if (change.widthChange())
899 extra.value().hasBackgroundWidth = p->widthValid();
900 if (change.heightChange())
901 extra.value().hasBackgroundHeight = p->heightValid();
905void QQuickControlPrivate::itemDestroyed(QQuickItem *item)
908 if (item == background) {
909 background =
nullptr;
910 emit q->implicitBackgroundWidthChanged();
911 emit q->implicitBackgroundHeightChanged();
912 }
else if (item == contentItem) {
913 contentItem =
nullptr;
914 updateImplicitContentSize();
918void QQuickControlPrivate::itemFocusChanged(QQuickItem *item, Qt::FocusReason reason)
921 if (item == contentItem || item == q)
922 setLastFocusChangeReason(reason);
925bool QQuickControlPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
928 Qt::FocusReason oldReason =
static_cast<Qt::FocusReason>(focusReason);
929 const auto focusReasonChanged = QQuickItemPrivate::setLastFocusChangeReason(reason);
930 if (focusReasonChanged)
931 emit q->focusReasonChanged();
932 if (isKeyFocusReason(oldReason) != isKeyFocusReason(reason))
933 emit q->visualFocusChanged();
935 return focusReasonChanged;
938QQuickControl::QQuickControl(QQuickItem *parent)
939 : QQuickItem(*(
new QQuickControlPrivate), parent)
945QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent)
946 : QQuickItem(dd, parent)
952QQuickControl::~QQuickControl()
955 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
956 d->removeImplicitSizeListener(d->contentItem);
958 QQuickItemPrivate::get(d->contentItem)->removeItemChangeListener(d, QQuickItemPrivate::Focus);
959#if QT_CONFIG(accessibility)
960 QAccessible::removeActivationObserver(d);
964void QQuickControl::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
967 QQuickItem::itemChange(change, value);
969 case ItemEnabledHasChanged:
972 case ItemVisibleHasChanged:
973#if QT_CONFIG(quicktemplates2_hover)
974 if (!value.boolValue)
978 case ItemSceneChange:
979 case ItemParentHasChanged:
980 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
983 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
984#if QT_CONFIG(quicktemplates2_hover)
985 if (!d->explicitHoverEnabled)
986 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
990 case ItemActiveFocusHasChanged:
991 if (isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason)))
992 emit visualFocusChanged();
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
1037
1038
1039
1040
1041
1042
1043QFont QQuickControl::font()
const
1045 Q_D(
const QQuickControl);
1046 QFont font = d->resolvedFont;
1048 font.setResolveMask(d->extra.isAllocated() ? d->extra->requestedFont.resolveMask() : 0);
1052void QQuickControl::setFont(
const QFont &font)
1055 if (d->extra.isAllocated()
1056 && d->extra.value().requestedFont.resolveMask() == font.resolveMask()
1057 && d->extra.value().requestedFont == font)
1060 d->extra.value().requestedFont = font;
1064void QQuickControl::resetFont()
1070
1071
1072
1073
1074
1075
1076
1077
1078qreal QQuickControl::availableWidth()
const
1080 return qMax<qreal>(0.0, width() - leftPadding() - rightPadding());
1084
1085
1086
1087
1088
1089
1090
1091
1092qreal QQuickControl::availableHeight()
const
1094 return qMax<qreal>(0.0, height() - topPadding() - bottomPadding());
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
1128
1129
1130
1131
1132
1133
1134
1135
1136qreal QQuickControl::padding()
const
1138 Q_D(
const QQuickControl);
1142void QQuickControl::setPadding(qreal padding)
1145 if (qFuzzyCompare(d->padding, padding))
1148 const QMarginsF oldPadding = d->getPadding();
1149 const qreal oldVerticalPadding = d->getVerticalPadding();
1150 const qreal oldHorizontalPadding = d->getHorizontalPadding();
1152 d->padding = padding;
1153 emit paddingChanged();
1155 const QMarginsF newPadding = d->getPadding();
1156 const qreal newVerticalPadding = d->getVerticalPadding();
1157 const qreal newHorizontalPadding = d->getHorizontalPadding();
1159 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
1160 emit topPaddingChanged();
1161 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
1162 emit leftPaddingChanged();
1163 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
1164 emit rightPaddingChanged();
1165 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1166 emit bottomPaddingChanged();
1167 if (!qFuzzyCompare(newVerticalPadding, oldVerticalPadding))
1168 emit verticalPaddingChanged();
1169 if (!qFuzzyCompare(newHorizontalPadding, oldHorizontalPadding))
1170 emit horizontalPaddingChanged();
1171 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1172 emit availableHeightChanged();
1173 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right()))
1174 emit availableWidthChanged();
1176 paddingChange(newPadding, oldPadding);
1179void QQuickControl::resetPadding()
1185
1186
1187
1188
1189
1190
1191
1192qreal QQuickControl::topPadding()
const
1194 Q_D(
const QQuickControl);
1195 return d->getTopPadding();
1198void QQuickControl::setTopPadding(qreal padding)
1201 d->setTopPadding(padding);
1204void QQuickControl::resetTopPadding()
1207 d->setTopPadding(0,
true);
1211
1212
1213
1214
1215
1216
1217
1218qreal QQuickControl::leftPadding()
const
1220 Q_D(
const QQuickControl);
1221 return d->getLeftPadding();
1224void QQuickControl::setLeftPadding(qreal padding)
1227 d->setLeftPadding(padding);
1230void QQuickControl::resetLeftPadding()
1233 d->setLeftPadding(0,
true);
1237
1238
1239
1240
1241
1242
1243
1244qreal QQuickControl::rightPadding()
const
1246 Q_D(
const QQuickControl);
1247 return d->getRightPadding();
1250void QQuickControl::setRightPadding(qreal padding)
1253 d->setRightPadding(padding);
1256void QQuickControl::resetRightPadding()
1259 d->setRightPadding(0,
true);
1263
1264
1265
1266
1267
1268
1269
1270qreal QQuickControl::bottomPadding()
const
1272 Q_D(
const QQuickControl);
1273 return d->getBottomPadding();
1276void QQuickControl::setBottomPadding(qreal padding)
1279 d->setBottomPadding(padding);
1282void QQuickControl::resetBottomPadding()
1285 d->setBottomPadding(0,
true);
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299qreal QQuickControl::spacing()
const
1301 Q_D(
const QQuickControl);
1305void QQuickControl::setSpacing(qreal spacing)
1308 if (qFuzzyCompare(d->spacing, spacing))
1311 qreal oldSpacing = d->spacing;
1312 d->spacing = spacing;
1313 emit spacingChanged();
1314 spacingChange(spacing, oldSpacing);
1317void QQuickControl::resetSpacing()
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337QLocale QQuickControl::locale()
const
1339 Q_D(
const QQuickControl);
1343void QQuickControl::setLocale(
const QLocale &locale)
1346 if (d->hasLocale && d->locale == locale)
1349 d->updateLocale(locale,
true);
1352void QQuickControl::resetLocale()
1358 d->hasLocale =
false;
1359 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376bool QQuickControl::isMirrored()
const
1378 Q_D(
const QQuickControl);
1379 return d->isMirrored();
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407Qt::FocusReason QQuickControl::focusReason()
const
1409 Q_D(
const QQuickControl);
1410 return d->lastFocusChangeReason();
1413void QQuickControl::setFocusReason(Qt::FocusReason reason)
1416 d->setLastFocusChangeReason(reason);
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433bool QQuickControl::hasVisualFocus()
const
1435 Q_D(
const QQuickControl);
1436 return d->activeFocus && isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason));
1440
1441
1442
1443
1444
1445
1446
1447bool QQuickControl::isHovered()
const
1449#if QT_CONFIG(quicktemplates2_hover)
1450 Q_D(
const QQuickControl);
1457void QQuickControl::setHovered(
bool hovered)
1459#if QT_CONFIG(quicktemplates2_hover)
1461 if (hovered == d->hovered)
1464 d->hovered = hovered;
1465 emit hoveredChanged();
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487bool QQuickControl::isHoverEnabled()
const
1489#if QT_CONFIG(quicktemplates2_hover)
1490 Q_D(
const QQuickControl);
1491 return d->hoverEnabled;
1497void QQuickControl::setHoverEnabled(
bool enabled)
1499#if QT_CONFIG(quicktemplates2_hover)
1501 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
1504 d->updateHoverEnabled(enabled,
true);
1510void QQuickControl::resetHoverEnabled()
1512#if QT_CONFIG(quicktemplates2_hover)
1514 if (!d->explicitHoverEnabled)
1517 d->explicitHoverEnabled =
false;
1518 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
1523
1524
1525
1526
1527
1528
1529
1530
1531bool QQuickControl::isWheelEnabled()
const
1533 Q_D(
const QQuickControl);
1534 return d->wheelEnabled;
1537void QQuickControl::setWheelEnabled(
bool enabled)
1540 if (d->wheelEnabled == enabled)
1543 d->wheelEnabled = enabled;
1544 emit wheelEnabledChanged();
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569QQuickItem *QQuickControl::background()
const
1571 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1573 d->executeBackground();
1574 return d->background;
1577void QQuickControl::setBackground(QQuickItem *background)
1580 if (d->background == background)
1583 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, background, QStringLiteral(
"background"));
1585 if (!d->background.isExecuting())
1586 d->cancelBackground();
1588 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
1589 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
1591 if (d->extra.isAllocated()) {
1592 d->extra.value().hasBackgroundWidth =
false;
1593 d->extra.value().hasBackgroundHeight =
false;
1596 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1597 QQuickControlPrivate::hideOldItem(d->background);
1598 d->background = background;
1601 background->setParentItem(
this);
1602 if (qFuzzyIsNull(background->z()))
1603 background->setZ(-1);
1604 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
1605 if (p->widthValid() || p->heightValid()) {
1606 d->extra.value().hasBackgroundWidth = p->widthValid();
1607 d->extra.value().hasBackgroundHeight = p->heightValid();
1609 if (isComponentComplete())
1610 d->resizeBackground();
1611 d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1614 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
1615 emit implicitBackgroundWidthChanged();
1616 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
1617 emit implicitBackgroundHeightChanged();
1618 if (!d->background.isExecuting())
1619 emit backgroundChanged();
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652QQuickItem *QQuickControl::contentItem()
const
1654 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1655 if (!d->contentItem)
1656 d->setContentItem_helper(d->getContentItem(),
false);
1657 return d->contentItem;
1660void QQuickControl::setContentItem(QQuickItem *item)
1663 d->setContentItem_helper(item,
true);
1666qreal QQuickControl::baselineOffset()
const
1668 Q_D(
const QQuickControl);
1669 return d->baselineOffset;
1672void QQuickControl::setBaselineOffset(qreal offset)
1675 d->extra.value().hasBaselineOffset =
true;
1676 QQuickItem::setBaselineOffset(offset);
1679void QQuickControl::resetBaselineOffset()
1682 if (!d->extra.isAllocated() || !d->extra.value().hasBaselineOffset)
1685 if (d->extra.isAllocated())
1686 d->extra.value().hasBaselineOffset =
false;
1687 d->updateBaselineOffset();
1691
1692
1693
1694
1695
1696
1697
1698
1699qreal QQuickControl::horizontalPadding()
const
1701 Q_D(
const QQuickControl);
1702 return d->getHorizontalPadding();
1705void QQuickControl::setHorizontalPadding(qreal padding)
1708 d->setHorizontalPadding(padding);
1711void QQuickControl::resetHorizontalPadding()
1714 d->setHorizontalPadding(0,
true);
1718
1719
1720
1721
1722
1723
1724
1725
1726qreal QQuickControl::verticalPadding()
const
1728 Q_D(
const QQuickControl);
1729 return d->getVerticalPadding();
1732void QQuickControl::setVerticalPadding(qreal padding)
1735 d->setVerticalPadding(padding);
1738void QQuickControl::resetVerticalPadding()
1741 d->setVerticalPadding(0,
true);
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766qreal QQuickControl::implicitContentWidth()
const
1768 Q_D(
const QQuickControl);
1770 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1771 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1777 static constexpr auto kLastKnownGoodImplicitWidth =
"_q_lastKnownGoodImplicitWidth";
1778 if (safeArea->detectedPossibleBindingLoop) {
1779 const auto lastImplicitWidth = safeArea->property(kLastKnownGoodImplicitWidth).value<
int>();
1780 return lastImplicitWidth - leftPadding() - rightPadding();
1782 safeArea->setProperty(kLastKnownGoodImplicitWidth, implicitWidth());
1786 return d->implicitContentWidth;
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811qreal QQuickControl::implicitContentHeight()
const
1813 Q_D(
const QQuickControl);
1815 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1816 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1822 static constexpr auto kLastKnownGoodImplicitHeight =
"_q_lastKnownGoodImplicitHeight";
1823 if (safeArea->detectedPossibleBindingLoop) {
1824 const auto lastImplicitHeight = safeArea->property(kLastKnownGoodImplicitHeight).value<
int>();
1825 return lastImplicitHeight - topPadding() - bottomPadding();
1827 safeArea->setProperty(kLastKnownGoodImplicitHeight, implicitHeight());
1831 return d->implicitContentHeight;
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855qreal QQuickControl::implicitBackgroundWidth()
const
1857 Q_D(
const QQuickControl);
1860 return d->background->implicitWidth();
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884qreal QQuickControl::implicitBackgroundHeight()
const
1886 Q_D(
const QQuickControl);
1889 return d->background->implicitHeight();
1893
1894
1895
1896
1897
1898
1899
1900qreal QQuickControl::topInset()
const
1902 Q_D(
const QQuickControl);
1903 return d->getTopInset();
1906void QQuickControl::setTopInset(qreal inset)
1909 d->setTopInset(inset);
1912void QQuickControl::resetTopInset()
1915 d->setTopInset(0,
true);
1919
1920
1921
1922
1923
1924
1925
1926qreal QQuickControl::leftInset()
const
1928 Q_D(
const QQuickControl);
1929 return d->getLeftInset();
1932void QQuickControl::setLeftInset(qreal inset)
1935 d->setLeftInset(inset);
1938void QQuickControl::resetLeftInset()
1941 d->setLeftInset(0,
true);
1945
1946
1947
1948
1949
1950
1951
1952qreal QQuickControl::rightInset()
const
1954 Q_D(
const QQuickControl);
1955 return d->getRightInset();
1958void QQuickControl::setRightInset(qreal inset)
1961 d->setRightInset(inset);
1964void QQuickControl::resetRightInset()
1967 d->setRightInset(0,
true);
1971
1972
1973
1974
1975
1976
1977
1978qreal QQuickControl::bottomInset()
const
1980 Q_D(
const QQuickControl);
1981 return d->getBottomInset();
1984void QQuickControl::setBottomInset(qreal inset)
1987 d->setBottomInset(inset);
1990void QQuickControl::resetBottomInset()
1993 d->setBottomInset(0,
true);
1996void QQuickControl::classBegin()
1999 QQuickItem::classBegin();
2003void QQuickControl::componentComplete()
2006 d->executeBackground(
true);
2007 d->executeContentItem(
true);
2008 QQuickItem::componentComplete();
2009 d->resizeBackground();
2011 d->updateBaselineOffset();
2013 d->locale = QQuickControlPrivate::calcLocale(d->parentItem);
2014#if QT_CONFIG(quicktemplates2_hover)
2015 if (!d->explicitHoverEnabled)
2016 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
2018#if QT_CONFIG(accessibility)
2019 if (QAccessible::isActive())
2020 accessibilityActiveChanged(
true);
2024QFont QQuickControl::defaultFont()
const
2026 return QQuickTheme::font(QQuickTheme::System);
2029void QQuickControl::focusInEvent(QFocusEvent *event)
2031 QQuickItem::focusInEvent(event);
2034void QQuickControl::focusOutEvent(QFocusEvent *event)
2036 QQuickItem::focusOutEvent(event);
2039#if QT_CONFIG(quicktemplates2_hover)
2040void QQuickControl::hoverEnterEvent(QHoverEvent *event)
2043 setHovered(d->hoverEnabled);
2047void QQuickControl::hoverMoveEvent(QHoverEvent *event)
2050 setHovered(d->hoverEnabled && contains(event->position()));
2054void QQuickControl::hoverLeaveEvent(QHoverEvent *event)
2061void QQuickControl::mousePressEvent(QMouseEvent *event)
2064 event->setAccepted(d->handlePress(event->position(), event->timestamp()));
2067void QQuickControl::mouseMoveEvent(QMouseEvent *event)
2070 event->setAccepted(d->handleMove(event->position(), event->timestamp()));
2073void QQuickControl::mouseReleaseEvent(QMouseEvent *event)
2076 event->setAccepted(d->handleRelease(event->position(), event->timestamp()));
2079void QQuickControl::mouseUngrabEvent()
2085#if QT_CONFIG(quicktemplates2_multitouch)
2086void QQuickControl::touchEvent(QTouchEvent *event)
2089 switch (event->type()) {
2090 case QEvent::TouchBegin:
2091 case QEvent::TouchUpdate:
2092 case QEvent::TouchEnd:
2093 for (
const QTouchEvent::TouchPoint &point : event->points()) {
2094 if (!d->acceptTouch(point))
2097 switch (point.state()) {
2098 case QEventPoint::Pressed:
2099 d->handlePress(point.position(), event->timestamp());
2101 case QEventPoint::Updated:
2102 d->handleMove(point.position(), event->timestamp());
2104 case QEventPoint::Released:
2105 d->handleRelease(point.position(), event->timestamp());
2113 case QEvent::TouchCancel:
2118 QQuickItem::touchEvent(event);
2123void QQuickControl::touchUngrabEvent()
2130#if QT_CONFIG(wheelevent)
2131void QQuickControl::wheelEvent(QWheelEvent *event)
2134 event->setAccepted(d->wheelEnabled);
2138void QQuickControl::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
2141 QQuickItem::geometryChange(newGeometry, oldGeometry);
2142 d->resizeBackground();
2144 if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width()))
2145 emit availableWidthChanged();
2146 if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height()))
2147 emit availableHeightChanged();
2150void QQuickControl::enabledChange()
2154void QQuickControl::fontChange(
const QFont &newFont,
const QFont &oldFont)
2160#if QT_CONFIG(quicktemplates2_hover)
2161void QQuickControl::hoverChange()
2163 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this, isHovered());
2167void QQuickControl::mirrorChange()
2169 emit mirroredChanged();
2172void QQuickControl::spacingChange(qreal newSpacing, qreal oldSpacing)
2174 Q_UNUSED(newSpacing);
2175 Q_UNUSED(oldSpacing);
2178void QQuickControl::paddingChange(
const QMarginsF &newPadding,
const QMarginsF &oldPadding)
2181 Q_UNUSED(newPadding);
2182 Q_UNUSED(oldPadding);
2184 d->updateBaselineOffset();
2187void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
2193void QQuickControl::localeChange(
const QLocale &newLocale,
const QLocale &oldLocale)
2195 Q_UNUSED(newLocale);
2196 Q_UNUSED(oldLocale);
2199void QQuickControl::insetChange(
const QMarginsF &newInset,
const QMarginsF &oldInset)
2204 d->resizeBackground();
2207#if QT_CONFIG(accessibility)
2208QAccessible::Role QQuickControl::accessibleRole()
const
2210 return QAccessible::NoRole;
2213void QQuickControl::accessibilityActiveChanged(
bool active)
2219 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
2220 Q_ASSERT(accessibleAttached);
2221 accessibleAttached->setRole(d->effectiveAccessibleRole());
2225QString QQuickControl::accessibleName()
const
2227#if QT_CONFIG(accessibility)
2228 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this))
2229 return accessibleAttached->name();
2234void QQuickControl::maybeSetAccessibleName(
const QString &name)
2236#if QT_CONFIG(accessibility)
2237 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this)) {
2238 if (!accessibleAttached->wasNameExplicitlySet())
2239 accessibleAttached->setNameImplicitly(name);
2246QVariant QQuickControl::accessibleProperty(
const char *propertyName)
2248#if QT_CONFIG(accessibility)
2249 if (QAccessible::isActive())
2250 return QQuickAccessibleAttached::property(
this, propertyName);
2252 Q_UNUSED(propertyName);
2256bool QQuickControl::setAccessibleProperty(
const char *propertyName,
const QVariant &value)
2258#if QT_CONFIG(accessibility)
2259 if (QAccessible::isActive())
2260 return QQuickAccessibleAttached::setProperty(
this, propertyName, value);
2262 Q_UNUSED(propertyName);
2269#include "moc_qquickcontrol_p.cpp"
Combined button and popup list for selecting options.
static bool isKeyFocusReason(Qt::FocusReason reason)
static QString contentItemName()