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.value().requestedFont.resolveMask());
1052void QQuickControl::setFont(
const QFont &font)
1055 if (d->extra.value().requestedFont.resolveMask() == font.resolveMask() && d->extra.value().requestedFont == font)
1058 d->extra.value().requestedFont = font;
1062void QQuickControl::resetFont()
1068
1069
1070
1071
1072
1073
1074
1075
1076qreal QQuickControl::availableWidth()
const
1078 return qMax<qreal>(0.0, width() - leftPadding() - rightPadding());
1082
1083
1084
1085
1086
1087
1088
1089
1090qreal QQuickControl::availableHeight()
const
1092 return qMax<qreal>(0.0, height() - topPadding() - bottomPadding());
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
1128
1129
1130
1131
1132
1133
1134qreal QQuickControl::padding()
const
1136 Q_D(
const QQuickControl);
1140void QQuickControl::setPadding(qreal padding)
1143 if (qFuzzyCompare(d->padding, padding))
1146 const QMarginsF oldPadding = d->getPadding();
1147 const qreal oldVerticalPadding = d->getVerticalPadding();
1148 const qreal oldHorizontalPadding = d->getHorizontalPadding();
1150 d->padding = padding;
1151 emit paddingChanged();
1153 const QMarginsF newPadding = d->getPadding();
1154 const qreal newVerticalPadding = d->getVerticalPadding();
1155 const qreal newHorizontalPadding = d->getHorizontalPadding();
1157 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
1158 emit topPaddingChanged();
1159 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
1160 emit leftPaddingChanged();
1161 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
1162 emit rightPaddingChanged();
1163 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1164 emit bottomPaddingChanged();
1165 if (!qFuzzyCompare(newVerticalPadding, oldVerticalPadding))
1166 emit verticalPaddingChanged();
1167 if (!qFuzzyCompare(newHorizontalPadding, oldHorizontalPadding))
1168 emit horizontalPaddingChanged();
1169 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1170 emit availableHeightChanged();
1171 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right()))
1172 emit availableWidthChanged();
1174 paddingChange(newPadding, oldPadding);
1177void QQuickControl::resetPadding()
1183
1184
1185
1186
1187
1188
1189
1190qreal QQuickControl::topPadding()
const
1192 Q_D(
const QQuickControl);
1193 return d->getTopPadding();
1196void QQuickControl::setTopPadding(qreal padding)
1199 d->setTopPadding(padding);
1202void QQuickControl::resetTopPadding()
1205 d->setTopPadding(0,
true);
1209
1210
1211
1212
1213
1214
1215
1216qreal QQuickControl::leftPadding()
const
1218 Q_D(
const QQuickControl);
1219 return d->getLeftPadding();
1222void QQuickControl::setLeftPadding(qreal padding)
1225 d->setLeftPadding(padding);
1228void QQuickControl::resetLeftPadding()
1231 d->setLeftPadding(0,
true);
1235
1236
1237
1238
1239
1240
1241
1242qreal QQuickControl::rightPadding()
const
1244 Q_D(
const QQuickControl);
1245 return d->getRightPadding();
1248void QQuickControl::setRightPadding(qreal padding)
1251 d->setRightPadding(padding);
1254void QQuickControl::resetRightPadding()
1257 d->setRightPadding(0,
true);
1261
1262
1263
1264
1265
1266
1267
1268qreal QQuickControl::bottomPadding()
const
1270 Q_D(
const QQuickControl);
1271 return d->getBottomPadding();
1274void QQuickControl::setBottomPadding(qreal padding)
1277 d->setBottomPadding(padding);
1280void QQuickControl::resetBottomPadding()
1283 d->setBottomPadding(0,
true);
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297qreal QQuickControl::spacing()
const
1299 Q_D(
const QQuickControl);
1303void QQuickControl::setSpacing(qreal spacing)
1306 if (qFuzzyCompare(d->spacing, spacing))
1309 qreal oldSpacing = d->spacing;
1310 d->spacing = spacing;
1311 emit spacingChanged();
1312 spacingChange(spacing, oldSpacing);
1315void QQuickControl::resetSpacing()
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335QLocale QQuickControl::locale()
const
1337 Q_D(
const QQuickControl);
1341void QQuickControl::setLocale(
const QLocale &locale)
1344 if (d->hasLocale && d->locale == locale)
1347 d->updateLocale(locale,
true);
1350void QQuickControl::resetLocale()
1356 d->hasLocale =
false;
1357 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374bool QQuickControl::isMirrored()
const
1376 Q_D(
const QQuickControl);
1377 return d->isMirrored();
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405Qt::FocusReason QQuickControl::focusReason()
const
1407 Q_D(
const QQuickControl);
1408 return d->lastFocusChangeReason();
1411void QQuickControl::setFocusReason(Qt::FocusReason reason)
1414 d->setLastFocusChangeReason(reason);
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431bool QQuickControl::hasVisualFocus()
const
1433 Q_D(
const QQuickControl);
1434 return d->activeFocus && isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason));
1438
1439
1440
1441
1442
1443
1444
1445bool QQuickControl::isHovered()
const
1447#if QT_CONFIG(quicktemplates2_hover)
1448 Q_D(
const QQuickControl);
1455void QQuickControl::setHovered(
bool hovered)
1457#if QT_CONFIG(quicktemplates2_hover)
1459 if (hovered == d->hovered)
1462 d->hovered = hovered;
1463 emit hoveredChanged();
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485bool QQuickControl::isHoverEnabled()
const
1487#if QT_CONFIG(quicktemplates2_hover)
1488 Q_D(
const QQuickControl);
1489 return d->hoverEnabled;
1495void QQuickControl::setHoverEnabled(
bool enabled)
1497#if QT_CONFIG(quicktemplates2_hover)
1499 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
1502 d->updateHoverEnabled(enabled,
true);
1508void QQuickControl::resetHoverEnabled()
1510#if QT_CONFIG(quicktemplates2_hover)
1512 if (!d->explicitHoverEnabled)
1515 d->explicitHoverEnabled =
false;
1516 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
1521
1522
1523
1524
1525
1526
1527
1528
1529bool QQuickControl::isWheelEnabled()
const
1531 Q_D(
const QQuickControl);
1532 return d->wheelEnabled;
1535void QQuickControl::setWheelEnabled(
bool enabled)
1538 if (d->wheelEnabled == enabled)
1541 d->wheelEnabled = enabled;
1542 emit wheelEnabledChanged();
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567QQuickItem *QQuickControl::background()
const
1569 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1571 d->executeBackground();
1572 return d->background;
1575void QQuickControl::setBackground(QQuickItem *background)
1578 if (d->background == background)
1581 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, background, QStringLiteral(
"background"));
1583 if (!d->background.isExecuting())
1584 d->cancelBackground();
1586 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
1587 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
1589 if (d->extra.isAllocated()) {
1590 d->extra.value().hasBackgroundWidth =
false;
1591 d->extra.value().hasBackgroundHeight =
false;
1594 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1595 QQuickControlPrivate::hideOldItem(d->background);
1596 d->background = background;
1599 background->setParentItem(
this);
1600 if (qFuzzyIsNull(background->z()))
1601 background->setZ(-1);
1602 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
1603 if (p->widthValid() || p->heightValid()) {
1604 d->extra.value().hasBackgroundWidth = p->widthValid();
1605 d->extra.value().hasBackgroundHeight = p->heightValid();
1607 if (isComponentComplete())
1608 d->resizeBackground();
1609 d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1612 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
1613 emit implicitBackgroundWidthChanged();
1614 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
1615 emit implicitBackgroundHeightChanged();
1616 if (!d->background.isExecuting())
1617 emit backgroundChanged();
1621
1622
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
1650QQuickItem *QQuickControl::contentItem()
const
1652 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1653 if (!d->contentItem)
1654 d->setContentItem_helper(d->getContentItem(),
false);
1655 return d->contentItem;
1658void QQuickControl::setContentItem(QQuickItem *item)
1661 d->setContentItem_helper(item,
true);
1664qreal QQuickControl::baselineOffset()
const
1666 Q_D(
const QQuickControl);
1667 return d->baselineOffset;
1670void QQuickControl::setBaselineOffset(qreal offset)
1673 d->extra.value().hasBaselineOffset =
true;
1674 QQuickItem::setBaselineOffset(offset);
1677void QQuickControl::resetBaselineOffset()
1680 if (!d->extra.isAllocated() || !d->extra.value().hasBaselineOffset)
1683 if (d->extra.isAllocated())
1684 d->extra.value().hasBaselineOffset =
false;
1685 d->updateBaselineOffset();
1689
1690
1691
1692
1693
1694
1695
1696
1697qreal QQuickControl::horizontalPadding()
const
1699 Q_D(
const QQuickControl);
1700 return d->getHorizontalPadding();
1703void QQuickControl::setHorizontalPadding(qreal padding)
1706 d->setHorizontalPadding(padding);
1709void QQuickControl::resetHorizontalPadding()
1712 d->setHorizontalPadding(0,
true);
1716
1717
1718
1719
1720
1721
1722
1723
1724qreal QQuickControl::verticalPadding()
const
1726 Q_D(
const QQuickControl);
1727 return d->getVerticalPadding();
1730void QQuickControl::setVerticalPadding(qreal padding)
1733 d->setVerticalPadding(padding);
1736void QQuickControl::resetVerticalPadding()
1739 d->setVerticalPadding(0,
true);
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764qreal QQuickControl::implicitContentWidth()
const
1766 Q_D(
const QQuickControl);
1768 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1769 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1775 static constexpr auto kLastKnownGoodImplicitWidth =
"_q_lastKnownGoodImplicitWidth";
1776 if (safeArea->detectedPossibleBindingLoop) {
1777 const auto lastImplicitWidth = safeArea->property(kLastKnownGoodImplicitWidth).value<
int>();
1778 return lastImplicitWidth - leftPadding() - rightPadding();
1780 safeArea->setProperty(kLastKnownGoodImplicitWidth, implicitWidth());
1784 return d->implicitContentWidth;
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809qreal QQuickControl::implicitContentHeight()
const
1811 Q_D(
const QQuickControl);
1813 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1814 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1820 static constexpr auto kLastKnownGoodImplicitHeight =
"_q_lastKnownGoodImplicitHeight";
1821 if (safeArea->detectedPossibleBindingLoop) {
1822 const auto lastImplicitHeight = safeArea->property(kLastKnownGoodImplicitHeight).value<
int>();
1823 return lastImplicitHeight - topPadding() - bottomPadding();
1825 safeArea->setProperty(kLastKnownGoodImplicitHeight, implicitHeight());
1829 return d->implicitContentHeight;
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853qreal QQuickControl::implicitBackgroundWidth()
const
1855 Q_D(
const QQuickControl);
1858 return d->background->implicitWidth();
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882qreal QQuickControl::implicitBackgroundHeight()
const
1884 Q_D(
const QQuickControl);
1887 return d->background->implicitHeight();
1891
1892
1893
1894
1895
1896
1897
1898qreal QQuickControl::topInset()
const
1900 Q_D(
const QQuickControl);
1901 return d->getTopInset();
1904void QQuickControl::setTopInset(qreal inset)
1907 d->setTopInset(inset);
1910void QQuickControl::resetTopInset()
1913 d->setTopInset(0,
true);
1917
1918
1919
1920
1921
1922
1923
1924qreal QQuickControl::leftInset()
const
1926 Q_D(
const QQuickControl);
1927 return d->getLeftInset();
1930void QQuickControl::setLeftInset(qreal inset)
1933 d->setLeftInset(inset);
1936void QQuickControl::resetLeftInset()
1939 d->setLeftInset(0,
true);
1943
1944
1945
1946
1947
1948
1949
1950qreal QQuickControl::rightInset()
const
1952 Q_D(
const QQuickControl);
1953 return d->getRightInset();
1956void QQuickControl::setRightInset(qreal inset)
1959 d->setRightInset(inset);
1962void QQuickControl::resetRightInset()
1965 d->setRightInset(0,
true);
1969
1970
1971
1972
1973
1974
1975
1976qreal QQuickControl::bottomInset()
const
1978 Q_D(
const QQuickControl);
1979 return d->getBottomInset();
1982void QQuickControl::setBottomInset(qreal inset)
1985 d->setBottomInset(inset);
1988void QQuickControl::resetBottomInset()
1991 d->setBottomInset(0,
true);
1994void QQuickControl::classBegin()
1997 QQuickItem::classBegin();
2001void QQuickControl::componentComplete()
2004 d->executeBackground(
true);
2005 d->executeContentItem(
true);
2006 QQuickItem::componentComplete();
2007 d->resizeBackground();
2009 d->updateBaselineOffset();
2011 d->locale = QQuickControlPrivate::calcLocale(d->parentItem);
2012#if QT_CONFIG(quicktemplates2_hover)
2013 if (!d->explicitHoverEnabled)
2014 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
2016#if QT_CONFIG(accessibility)
2017 if (QAccessible::isActive())
2018 accessibilityActiveChanged(
true);
2022QFont QQuickControl::defaultFont()
const
2024 return QQuickTheme::font(QQuickTheme::System);
2027void QQuickControl::focusInEvent(QFocusEvent *event)
2029 QQuickItem::focusInEvent(event);
2032void QQuickControl::focusOutEvent(QFocusEvent *event)
2034 QQuickItem::focusOutEvent(event);
2037#if QT_CONFIG(quicktemplates2_hover)
2038void QQuickControl::hoverEnterEvent(QHoverEvent *event)
2041 setHovered(d->hoverEnabled);
2045void QQuickControl::hoverMoveEvent(QHoverEvent *event)
2048 setHovered(d->hoverEnabled && contains(event->position()));
2052void QQuickControl::hoverLeaveEvent(QHoverEvent *event)
2059void QQuickControl::mousePressEvent(QMouseEvent *event)
2062 event->setAccepted(d->handlePress(event->position(), event->timestamp()));
2065void QQuickControl::mouseMoveEvent(QMouseEvent *event)
2068 event->setAccepted(d->handleMove(event->position(), event->timestamp()));
2071void QQuickControl::mouseReleaseEvent(QMouseEvent *event)
2074 event->setAccepted(d->handleRelease(event->position(), event->timestamp()));
2077void QQuickControl::mouseUngrabEvent()
2083#if QT_CONFIG(quicktemplates2_multitouch)
2084void QQuickControl::touchEvent(QTouchEvent *event)
2087 switch (event->type()) {
2088 case QEvent::TouchBegin:
2089 case QEvent::TouchUpdate:
2090 case QEvent::TouchEnd:
2091 for (
const QTouchEvent::TouchPoint &point : event->points()) {
2092 if (!d->acceptTouch(point))
2095 switch (point.state()) {
2096 case QEventPoint::Pressed:
2097 d->handlePress(point.position(), event->timestamp());
2099 case QEventPoint::Updated:
2100 d->handleMove(point.position(), event->timestamp());
2102 case QEventPoint::Released:
2103 d->handleRelease(point.position(), event->timestamp());
2111 case QEvent::TouchCancel:
2116 QQuickItem::touchEvent(event);
2121void QQuickControl::touchUngrabEvent()
2128#if QT_CONFIG(wheelevent)
2129void QQuickControl::wheelEvent(QWheelEvent *event)
2132 event->setAccepted(d->wheelEnabled);
2136void QQuickControl::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
2139 QQuickItem::geometryChange(newGeometry, oldGeometry);
2140 d->resizeBackground();
2142 if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width()))
2143 emit availableWidthChanged();
2144 if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height()))
2145 emit availableHeightChanged();
2148void QQuickControl::enabledChange()
2152void QQuickControl::fontChange(
const QFont &newFont,
const QFont &oldFont)
2158#if QT_CONFIG(quicktemplates2_hover)
2159void QQuickControl::hoverChange()
2161 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this, isHovered());
2165void QQuickControl::mirrorChange()
2167 emit mirroredChanged();
2170void QQuickControl::spacingChange(qreal newSpacing, qreal oldSpacing)
2172 Q_UNUSED(newSpacing);
2173 Q_UNUSED(oldSpacing);
2176void QQuickControl::paddingChange(
const QMarginsF &newPadding,
const QMarginsF &oldPadding)
2179 Q_UNUSED(newPadding);
2180 Q_UNUSED(oldPadding);
2182 d->updateBaselineOffset();
2185void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
2191void QQuickControl::localeChange(
const QLocale &newLocale,
const QLocale &oldLocale)
2193 Q_UNUSED(newLocale);
2194 Q_UNUSED(oldLocale);
2197void QQuickControl::insetChange(
const QMarginsF &newInset,
const QMarginsF &oldInset)
2202 d->resizeBackground();
2205#if QT_CONFIG(accessibility)
2206QAccessible::Role QQuickControl::accessibleRole()
const
2208 return QAccessible::NoRole;
2211void QQuickControl::accessibilityActiveChanged(
bool active)
2217 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
2218 Q_ASSERT(accessibleAttached);
2219 accessibleAttached->setRole(d->effectiveAccessibleRole());
2223QString QQuickControl::accessibleName()
const
2225#if QT_CONFIG(accessibility)
2226 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this))
2227 return accessibleAttached->name();
2232void QQuickControl::maybeSetAccessibleName(
const QString &name)
2234#if QT_CONFIG(accessibility)
2235 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this)) {
2236 if (!accessibleAttached->wasNameExplicitlySet())
2237 accessibleAttached->setNameImplicitly(name);
2244QVariant QQuickControl::accessibleProperty(
const char *propertyName)
2246#if QT_CONFIG(accessibility)
2247 if (QAccessible::isActive())
2248 return QQuickAccessibleAttached::property(
this, propertyName);
2250 Q_UNUSED(propertyName);
2254bool QQuickControl::setAccessibleProperty(
const char *propertyName,
const QVariant &value)
2256#if QT_CONFIG(accessibility)
2257 if (QAccessible::isActive())
2258 return QQuickAccessibleAttached::setProperty(
this, propertyName, value);
2260 Q_UNUSED(propertyName);
2267#include "moc_qquickcontrol_p.cpp"
Combined button and popup list for selecting options.
static bool isKeyFocusReason(Qt::FocusReason reason)
static QString contentItemName()